@@ -272,9 +272,7 @@ load_configuration()
272272 # check if we need to upgrade configuration:
273273 if [ -z " $OPT_DONT_UPGRADE_CONFIGURATION " ]; then
274274 if [ ! -f ~ /.scratchbox2/$SBOX_TARGET /sb2.config.d/config-stamp.20 ]; then
275- $SBOX_DIR /share/scratchbox2/scripts/sb2-upgrade-config \
276- $SBOX_TARGET
277- if [ $? != 0 ]; then
275+ if ! $SBOX_DIR /share/scratchbox2/scripts/sb2-upgrade-config $SBOX_TARGET ; then
278276 echo " Failed to upgrade configuration files" >&2
279277 exit 1
280278 fi
@@ -356,17 +354,17 @@ clone_target_root_dir_from()
356354
357355 echo " Copying target root from $source_directory ..."
358356 # cp -Rp does not preserve hard links, but cpio does
359- (cd $source_directory ; find . -depth -print |
360- cpio -pamd $SBOX_SESSION_DIR /target_root)
361- if [ $? != 0 ] ; then
357+
358+ if ! (cd $source_directory ; find . -depth -print |
359+ cpio -pamd $SBOX_SESSION_DIR /target_root) ; then
362360 exit_error " Failed to clone target_root"
363361 fi
364362 # There is a bug in gnu cpio: timestamps of directories
365363 # will not be set correctly on the first run,
366364 # but they will be corrected by another round:
367- (cd $source_directory ; find . -depth -type d -print |
368- cpio -pamd $SBOX_SESSION_DIR /target_root)
369- if [ $? != 0 ] ; then
365+
366+ if ! (cd $source_directory ; find . -depth -type d -print |
367+ cpio -pamd $SBOX_SESSION_DIR /target_root) ; then
370368 exit_error " Failed to fix directory permissions in target_root clone"
371369 fi
372370 #
@@ -661,7 +659,7 @@ write_ld_library_path_replacement_to_exec_config()
661659 fi
662660 # Include directories listed in ld.so.conf.d/*
663661 if [ -d $rootdir /etc/ld.so.conf.d ]; then
664- for ld_so_conf in " $root " /etc/ld.so.conf.d/* ; do
662+ for ld_so_conf in " $rootdir " /etc/ld.so.conf.d/* ; do
665663 if [ -e " $ld_so_conf " ] ; then
666664 lloc2=$( grep --extended-regexp --only-matching ' ^/' " $rootdir " /etc/ld.so.conf.d/* )
667665 break
@@ -723,13 +721,13 @@ check_qemu_features()
723721 # Use "sb2-show" to find out how qemu should be executed
724722 # (qemu might be under tools_root => it might need to
725723 # use ld.so and libraries from tools)
726- __SB2_BINARYNAME=" sb2:CheckingQemuExec" \
727- sb2-monitor \
724+ if ! __SB2_BINARYNAME=" sb2:CheckingQemuExec" \
725+ sb2-monitor \
728726 -L $SBOX_LIBSB2 -- $SBOX_DIR /bin/sb2-show \
729727 -- exec-cmdline \
730728 $qemu_path $qemu_options \
731729 > $SBOX_SESSION_DIR /qemu_cmdline
732- if [ $? != 0 ] ; then
730+ then
733731 exit_error " Failed to find out how $qemu_path should be started"
734732 fi
735733
@@ -740,7 +738,7 @@ check_qemu_features()
740738 -L $SBOX_LIBSB2 -- \
741739 $qemu_cmdline -h \
742740 > $SBOX_SESSION_DIR /qemu_help
743- # we don't test $? here, qemu -h returns with a non-zero
741+ # we don't test the exit status here, qemu -h returns with a non-zero
744742 # argument anyway
745743
746744 #
@@ -917,11 +915,11 @@ guess_ld_so()
917915{
918916 local prefix=" $1 "
919917
920- if [ " $( uname -m) " = ' x86_64' -a -r " $prefix /lib/ld-linux-x86-64.so.2" ]
918+ if [ " $( uname -m) " = ' x86_64' ] && [ -r " $prefix /lib/ld-linux-x86-64.so.2" ]
921919 then
922920 printf " $prefix /lib/ld-linux-x86-64.so.2"
923921 else
924- printf " $prefix /lib/ld-linux.so.2"
922+ printf " $prefix /lib/ld-linux.so.2"
925923 fi
926924}
927925
@@ -996,7 +994,7 @@ write_libsb2_and_ld_so_state_to_exec_config()
996994 # First try if it exists in the same directory where
997995 # libsb2.so is:
998996 ld_so_candidate2=$libsb2_dirname /$ld_so_with_version
999- if [ -n " $libsb2_dirname " -a -f $ld_so_candidate2 ]; then
997+ if [ -n " $libsb2_dirname " ] && [ -f $ld_so_candidate2 ]; then
1000998 check_ld_so_features $rootdir \
1001999 $ld_so_candidate2
10021000
@@ -1154,7 +1152,7 @@ END
11541152 library_interface=$( LD_LIBRARY_PATH=$SBOX_DIR /lib/libsb2:$LD_LIBRARY_PATH $SBOX_DIR /bin/sb2-show libraryinterface)
11551153
11561154 # 1. Exec settings for tools
1157- if [ -n " $SBOX_TOOLS_ROOT " -a " $SBOX_TOOLS_ROOT " != " /" ]; then
1155+ if [ -n " $SBOX_TOOLS_ROOT " ] && [ " $SBOX_TOOLS_ROOT " != " /" ]; then
11581156 tools_basename=$( basename $SBOX_TOOLS_ROOT )
11591157 write_ld_library_path_replacement_to_exec_config \
11601158 $SBOX_TOOLS_ROOT conf_tools_ld_so_library_path \
@@ -1332,8 +1330,8 @@ get_SBOX_SESSION_DIR_from_file()
13321330 exit_error " '$file ' is not a valid SB2 session information file"
13331331 fi
13341332
1335- if [ ! -d " $SBOX_SESSION_DIR " -o \
1336- ! -f $SBOX_SESSION_DIR /.joinable-session ]; then
1333+ if [ ! -d " $SBOX_SESSION_DIR " ] || \
1334+ [ ! -f $SBOX_SESSION_DIR /.joinable-session ]; then
13371335 exit_error " Session '$SBOX_SESSION_DIR ' does not exist"
13381336 fi
13391337 # else the session seems to be valid.
@@ -1385,8 +1383,8 @@ add_map_mode()
13851383initialize_new_sb2_session ()
13861384{
13871385 # Create a new session
1388- if [ -n " $SBOX_WRITE_SESSION_INFO_TO_FILE " -a \
1389- -f " $SBOX_WRITE_SESSION_INFO_TO_FILE " ]; then
1386+ if [ -n " $SBOX_WRITE_SESSION_INFO_TO_FILE " ] && \
1387+ [ -f " $SBOX_WRITE_SESSION_INFO_TO_FILE " ]; then
13901388 exit_error " File '$SBOX_WRITE_SESSION_INFO_TO_FILE ' already exists."
13911389 fi
13921390
@@ -1396,16 +1394,14 @@ initialize_new_sb2_session()
13961394 else
13971395 # Create session directories
13981396 date_and_time_now=$( date +%Y%m%d-%H%M%S)
1399- SBOX_SESSION_DIR=$( mktemp -d /tmp/sb2-$USER -$date_and_time_now .XXXXXX)
1400- if [ $? != 0 ]; then
1397+ if ! SBOX_SESSION_DIR=$( mktemp -d /tmp/sb2-$USER -$date_and_time_now .XXXXXX) ; then
14011398 exit_error " Failed to create directory for session (problems with /tmp ?)"
14021399 fi
14031400 fi
14041401 # resolve possible symlinks in SBOX_SESSION_DIR
14051402 SBOX_SESSION_DIR=$( readlink -f $SBOX_SESSION_DIR )
14061403
1407- mkdir -p $SBOX_SESSION_DIR
1408- if [ $? != 0 ]; then
1404+ if ! mkdir -p $SBOX_SESSION_DIR ; then
14091405 exit_error " Failed to create directory for session"
14101406 fi
14111407 mkdir $SBOX_SESSION_DIR /tmp
@@ -1684,7 +1680,7 @@ done
16841680shift $(( $OPTIND - 1 ))
16851681
16861682
1687- if [ -n " $SBOX_SESSION_DIR " -a -d " $SBOX_SESSION_DIR /rules" ]; then
1683+ if [ -n " $SBOX_SESSION_DIR " ] && [ -d " $SBOX_SESSION_DIR /rules" ]; then
16881684 # already inside an sb2 session; ignore all options and just exec the command.
16891685 echo " WARNING: recursive calls to sb2 are not supported (session already exists)"
16901686 echo " WARNING: going to execute '$* ' in this session"
16931689
16941690# ----------- Check parameters
16951691
1696- # First check that we are not running under "fakeroot"; it
1692+ # First check that we are not running under "fakeroot"; it
16971693# will just mess up things and must not be combined with SB2.
16981694case " $LD_PRELOAD " in
16991695 (* fakeroot* )
@@ -1709,8 +1705,7 @@ esac
17091705
17101706if [ -n " $SBOX_LOG_AND_GRAPH_DIR " ]; then
17111707 if [ ! -d " $SBOX_LOG_AND_GRAPH_DIR " ]; then
1712- mkdir -p " $SBOX_LOG_AND_GRAPH_DIR "
1713- if [ $? != 0 ]; then
1708+ if ! mkdir -p " $SBOX_LOG_AND_GRAPH_DIR " ; then
17141709 exit_error " Failed to create directory $SBOX_LOG_AND_GRAPH_DIR "
17151710 fi
17161711 else
@@ -1720,7 +1715,7 @@ if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then
17201715 export SBOX_LOG_AND_GRAPH_DIR
17211716 export SBOX_COLLECT_ACCT_DATA
17221717
1723- if [ " $SBOX_MAPPING_DEBUG " != " 1" -a -n " $SBOX_LOG_AND_GRAPH_DIR " ]; then
1718+ if [ " $SBOX_MAPPING_DEBUG " != " 1" ] && [ -n " $SBOX_LOG_AND_GRAPH_DIR " ]; then
17241719 # Log & graphs requested, but log isn't active.
17251720 export SBOX_MAPPING_DEBUG=1
17261721 export SBOX_MAPPING_LOGLEVEL=info
@@ -1729,13 +1724,13 @@ if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then
17291724 if [ -n " $SBOX_COLLECT_ACCT_DATA " ]; then
17301725 # First try to activate it directly
17311726 touch $SBOX_LOG_AND_GRAPH_DIR /acct-data
1732- $SBOX_DIR /bin/sb2-show acct_on $SBOX_LOG_AND_GRAPH_DIR /acct-data 2> /dev/null
1733- if [ $? != 0 ] ; then
1727+ if ! $SBOX_DIR /bin/sb2-show acct_on \
1728+ $SBOX_LOG_AND_GRAPH_DIR /acct-data 2> /dev/null ; then
17341729 if [ -z " $SBOX_QUIET " ]; then
17351730 echo " WARNING: Can't activate process accounting. Retrying with 'sudo', password may be needed."
17361731 fi
1737- sudo $SBOX_DIR /bin/sb2-show acct_on $SBOX_LOG_AND_GRAPH_DIR /acct-data 2> /dev/null
1738- if [ $? != 0 ] ; then
1732+ if ! sudo $SBOX_DIR /bin/sb2-show acct_on \
1733+ $SBOX_LOG_AND_GRAPH_DIR /acct-data 2> /dev/null ; then
17391734 if [ -z " $SBOX_QUIET " ]; then
17401735 echo " WARNING: Failed to activate process accounting. Acct data won't be included in the graphs."
17411736 fi
@@ -1855,7 +1850,7 @@ export SBOX_SESSION_DIR
18551850
18561851sboxify_environment
18571852
1858- if [ -z " $SB2_INTERNAL_MAPMODES " -a -z " $SB2_EXTERNAL_RULEFILES " ]; then
1853+ if [ -z " $SB2_INTERNAL_MAPMODES " ] && [ -z " $SB2_EXTERNAL_RULEFILES " ]; then
18591854 # mapping mode was not specified by an option, SBOX_MAPMODE has been
18601855 # set from the config file by sboxify_environment
18611856 SB2_INTERNAL_MAPMODES=$SBOX_MAPMODE
@@ -1887,14 +1882,13 @@ if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then
18871882 # deleted when session is terminated.)
18881883 #
18891884 # sb2d will execute "init.lua" before returning.
1890- SB2_DEFAULT_NETWORK_MODE=" $SBOX_DEFAULT_NETWORK_MODE " \
1891- SB2_ALL_NET_MODES=" $SB2_ALL_NET_MODES " \
1892- SB2_ALL_MODES=" $SB2_INTERNAL_MAPMODES " \
1885+ if ! SB2_DEFAULT_NETWORK_MODE=" $SBOX_DEFAULT_NETWORK_MODE " \
1886+ SB2_ALL_NET_MODES=" $SB2_ALL_NET_MODES " \
1887+ SB2_ALL_MODES=" $SB2_INTERNAL_MAPMODES " \
18931888 sb2d -s $SBOX_SESSION_DIR -p $SBOX_SESSION_DIR /sb2d.pid \
18941889 -l - $SB2D_OPTIONS \
18951890 > $SBOX_SESSION_DIR /sb2d.out \
1896- 2> $SBOX_SESSION_DIR /sb2d.err
1897- if [ $? != 0 ]; then
1891+ 2> $SBOX_SESSION_DIR /sb2d.err ; then
18981892 grep ERROR $SBOX_SESSION_DIR /sb2d.out
18991893 cat $SBOX_SESSION_DIR /sb2d.err
19001894 exit_error " startup of sb2d failed."
19691963# (If logging was activated earlier,
19701964# several bogus errors would be logged because of
19711965# missing auto-generated rules)
1972- if [ $# -gt 0 -o " $STDIN " = true ] ; then
1966+ if [ $# -gt 0 ] || [ " $STDIN " = true ] ; then
19731967 initialize_sb_logging $( echo $1 | sed -e ' s/\//_/g' -e ' s/^\.//' ) " $args "
19741968else
19751969 initialize_sb_logging sb2
@@ -2011,7 +2005,7 @@ SBOX_CONFIG_DIR=$HOME/.scratchbox2/$SBOX_TARGET/sb2.config.d
20112005#
20122006__SB2_BINARYNAME=" sb2:StartupTrampoline"
20132007export __SB2_BINARYNAME
2014- if [ $# -gt 0 -o " $STDIN " = true ]; then
2008+ if [ $# -gt 0 ] || [ " $STDIN " = true ]; then
20152009 binary=" $1 "
20162010 shift 1
20172011
0 commit comments