[lxc-devel] [PATCH v2] lxc-checkconfig: use POSIX shell instead of bash

Stéphane Graber stgraber at ubuntu.com
Tue Nov 27 15:05:25 UTC 2012


On 11/27/2012 02:27 AM, Natanael Copa wrote:
> - replace 'echo -e' with printf
> - replace 'if [[ ... ]]' with 'if [ ... ]'
> - add \ at after && and || when those are at end of line
> 
> Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>

Looks good, acked and added to the staging branch. Thanks

> ---
> Changes v1 -> v2:
>  - rebase against current staging
> 
>  src/lxc/lxc-checkconfig.in | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/src/lxc/lxc-checkconfig.in b/src/lxc/lxc-checkconfig.in
> index 7dd6476..d17bb95 100644
> --- a/src/lxc/lxc-checkconfig.in
> +++ b/src/lxc/lxc-checkconfig.in
> @@ -1,13 +1,13 @@
> -#!/bin/bash
> +#!/bin/sh
>  
>  # Allow environment variables to override grep and config
>  : ${CONFIG:=/proc/config.gz}
>  : ${GREP:=zgrep}
>  
> -SETCOLOR_SUCCESS="echo -en \\033[1;32m"
> -SETCOLOR_FAILURE="echo -en \\033[1;31m"
> -SETCOLOR_WARNING="echo -en \\033[1;33m"
> -SETCOLOR_NORMAL="echo -en \\033[0;39m"
> +SETCOLOR_SUCCESS="printf \\e[1;32m"
> +SETCOLOR_FAILURE="printf \\e[1;31m"
> +SETCOLOR_WARNING="printf \\e[1;33m"
> +SETCOLOR_NORMAL="printf \\e[0;39m"
>  
>  is_set() {
>      $GREP -q "$1=[y|m]" $CONFIG
> @@ -21,12 +21,12 @@ is_enabled() {
>      RES=$?
>  
>      if [ $RES -eq 0 ]; then
> -	$SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
> +	$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
>      else
>  	if [ ! -z "$mandatory" -a "$mandatory" = yes ]; then
> -	    $SETCOLOR_FAILURE && echo -e "required" && $SETCOLOR_NORMAL
> +	    $SETCOLOR_FAILURE && echo "required" && $SETCOLOR_NORMAL
>  	else
> -	    $SETCOLOR_WARNING && echo -e "missing" && $SETCOLOR_NORMAL
> +	    $SETCOLOR_WARNING && echo "missing" && $SETCOLOR_NORMAL
>  	fi
>      fi
>  }
> @@ -70,7 +70,7 @@ print_cgroups() {
>  CGROUP_MNT_PATH=`print_cgroups cgroup /proc/self/mounts | head -1`
>  KVER_MAJOR=$($GREP '^# Linux' $CONFIG | \
>      sed -r 's/.* ([0-9])\.[0-9]{1,2}\.[0-9]{1,3}.*/\1/')
> -if [[ $KVER_MAJOR == 2 ]]; then
> +if [ "$KVER_MAJOR" = "2" ]; then
>  KVER_MINOR=$($GREP '^# Linux' $CONFIG | \
>      sed -r 's/.* 2.6.([0-9]{2}).*/\1/')
>  else
> @@ -82,7 +82,7 @@ echo -n "Cgroup: " && is_enabled CONFIG_CGROUPS yes
>  
>  if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then
>      echo -n "Cgroup clone_children flag: " &&
> -    $SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
> +    $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
>  else
>      echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes
>  fi
> @@ -101,12 +101,12 @@ echo "--- Misc ---"
>  echo -n "Veth pair device: " && is_enabled CONFIG_VETH
>  echo -n "Macvlan: " && is_enabled CONFIG_MACVLAN
>  echo -n "Vlan: " && is_enabled CONFIG_VLAN_8021Q
> -echo -n "File capabilities: " &&
> -    ( [[ ${KVER_MAJOR} == 2 && ${KVER_MINOR} < 33 ]] &&
> -       is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) ||
> -    ( [[ ( ${KVER_MAJOR} == 2 && ${KVER_MINOR} > 32 ) ||
> -         ${KVER_MAJOR} > 2 ]] && $SETCOLOR_SUCCESS &&
> -         echo -e "enabled" && $SETCOLOR_NORMAL )
> +echo -n "File capabilities: " && \
> +    ( [ "${KVER_MAJOR}" = 2 ] && [ ${KVER_MINOR} -lt 33 ] && \
> +       is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) || \
> +    ( ( [ "${KVER_MAJOR}" = "2" ] && [ ${KVER_MINOR} -gt 32 ] ) || \
> +         [ ${KVER_MAJOR} -gt 2 ] && $SETCOLOR_SUCCESS && \
> +         echo "enabled" && $SETCOLOR_NORMAL )
>  
>  echo
>  echo "Note : Before booting a new kernel, you can check its configuration"
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121127/c5853362/attachment.pgp>


More information about the lxc-devel mailing list