From: Andreas Schneider Date: Mon, 21 Feb 2022 13:06:36 +0000 (+0100) Subject: selftest: Reformat shell scripts X-Git-Tag: tevent-0.12.0~581 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1399b2430a06f4a4b82f99643bf41b732183b5cb;p=thirdparty%2Fsamba.git selftest: Reformat shell scripts shfmt -f selftest/ | xargs shfmt -w -p -i 0 -fn Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/selftest/checkpassword_arg1.sh b/selftest/checkpassword_arg1.sh index 42e1b5e7df5..ecaeb2ed374 100755 --- a/selftest/checkpassword_arg1.sh +++ b/selftest/checkpassword_arg1.sh @@ -6,7 +6,7 @@ set -u ACCOUNT_NAME="${SAMBA_CPS_ACCOUNT_NAME}" INVALIDPW="$1" -NEWPW=`cat -` +NEWPW=$(cat -) echo -n "${NEWPW}" | grep -q "^${INVALIDPW}\$" && { echo "Found invalid password" >&1 diff --git a/selftest/gdb_backtrace b/selftest/gdb_backtrace index 0aad62f3233..ec2396a630e 100755 --- a/selftest/gdb_backtrace +++ b/selftest/gdb_backtrace @@ -1,6 +1,6 @@ #!/bin/sh -BASENAME=`basename $0` +BASENAME=$(basename $0) unset LD_PRELOAD @@ -11,14 +11,13 @@ fi if [ "x$PLEASE_NO_GDB_BACKTRACE" != "x" ]; then echo "${BASENAME}: Not running debugger because PLEASE_NO_GDB_BACKTRACE is set" - exit 0 + exit 0 fi - # we want everything on stderr, so the program is not disturbed exec 1>&2 -UNAME=`uname` +UNAME=$(uname) PID=$1 BINARY=$2 @@ -30,31 +29,31 @@ test x"${PID}" = x"" && { DB_LIST="gdb" case "${UNAME}" in - # - # on Tru64 we need to try ladebug first - # because gdb crashes itself... - # - OSF1) - DB_LIST="ladebug ${DB_LIST}" +# +# on Tru64 we need to try ladebug first +# because gdb crashes itself... +# +OSF1) + DB_LIST="ladebug ${DB_LIST}" ;; - # - # On solaris dbx is working way more better than gdb - # let's try it first - # - SunOS) - DB_LIST="dbx ${DB_LIST}" +# +# On solaris dbx is working way more better than gdb +# let's try it first +# +SunOS) + DB_LIST="dbx ${DB_LIST}" ;; - # - # FreeBSD comes with a flavor that works gdb66 and one that don't gdb - # (gdb 6.1) let's try it first the one that works ! - # - FreeBSD) - DB_LIST="gdb66 ${DB_LIST}" +# +# FreeBSD comes with a flavor that works gdb66 and one that don't gdb +# (gdb 6.1) let's try it first the one that works ! +# +FreeBSD) + DB_LIST="gdb66 ${DB_LIST}" ;; esac for DB in ${DB_LIST}; do - DB_BIN=`which ${DB} 2>/dev/null | grep '^/'` + DB_BIN=$(which ${DB} 2>/dev/null | grep '^/') test x"${DB_BIN}" != x"" && { break } @@ -68,59 +67,59 @@ test x"${DB_BIN}" = x"" && { need_binary="no" case "${DB}" in # These debuggers need the process binary specified: - ladebug) +ladebug) need_binary="yes" ;; - gdb66) +gdb66) need_binary="yes" ;; - dbx) +dbx) need_binary="yes" ;; esac test x"${need_binary}" = x"yes" && { -# we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris -# then fallback to the binary from the commandline -# then we search for the commandline argument with -# 'which' -# + # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris + # then fallback to the binary from the commandline + # then we search for the commandline argument with + # 'which' + # test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe" - test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'` + test -f "/proc/${PID}/path/a.out" && BINARY=$(ls -l /proc/${PID}/path/a.out | sed 's/.*-> //') test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe" - test -f "${BINARY}" || BINARY=`which ${BINARY}` - + test -f "${BINARY}" || BINARY=$(which ${BINARY}) + test -f "${BINARY}" || { - echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'." - exit 1 + echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'." + exit 1 } } -BATCHFILE_PRE=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX` +BATCHFILE_PRE=$(mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX) test -n "${BATCHFILE_PRE}" || { echo "mktemp doesn't work" 1>&2 exit 1 } -BATCHFILE_MAIN=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX` +BATCHFILE_MAIN=$(mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX) test -n "${BATCHFILE_MAIN}" || { echo "mktemp doesn't work" 1>&2 exit 1 } case "${DB}" in - ladebug) -cat << EOF > ${BATCHFILE_PRE} +ladebug) + cat <${BATCHFILE_PRE} set \$stoponattach EOF -cat << EOF > ${BATCHFILE_MAIN} + cat <${BATCHFILE_MAIN} where quit EOF ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}" ;; - gdb66) -cat << EOF > ${BATCHFILE_MAIN} +gdb66) + cat <${BATCHFILE_MAIN} set height 1000 bt full info locals @@ -129,15 +128,15 @@ quit EOF ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}" ;; - gdb) -cat << EOF > ${BATCHFILE_MAIN} +gdb) + cat <${BATCHFILE_MAIN} set height 0 bt full thread apply all bt full info locals quit EOF - ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null + ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" &2 exit 1 } -cat << EOF > $TMPFILE +cat <$TMPFILE run bt EOF diff --git a/selftest/in_screen b/selftest/in_screen index 024cb50754a..d7d1b53d920 100755 --- a/selftest/in_screen +++ b/selftest/in_screen @@ -7,12 +7,12 @@ SERVERNAME="$ENVNAME" basedir=$TMPDIR [ -r $basedir/$SERVERNAME.pid ] && { - for i in {2..100}; do - if [ ! -r "$basedir/${SERVERNAME}-$i.pid" ]; then - SERVERNAME="${SERVERNAME}-$i" - break - fi - done + for i in {2..100}; do + if [ ! -r "$basedir/${SERVERNAME}-$i.pid" ]; then + SERVERNAME="${SERVERNAME}-$i" + break + fi + done } rm -f $basedir/$SERVERNAME.{launch,log,parent.pid,pid,status} @@ -20,11 +20,11 @@ rm -f $basedir/$SERVERNAME.{launch,log,parent.pid,pid,status} # set most of the environment vars we have in the screen session too _ENV="" printenv | - egrep -v '^TERMCAP|^WINDOW|^SHELL|^STY|^SHLVL|^SAMBA_VALGRIND|\$' | - egrep '^[A-Z]' | - sed "s/\(^[^=]*=\)\(.*\)/export \1'\2'/g" > $basedir/$SERVERNAME.vars + egrep -v '^TERMCAP|^WINDOW|^SHELL|^STY|^SHLVL|^SAMBA_VALGRIND|\$' | + egrep '^[A-Z]' | + sed "s/\(^[^=]*=\)\(.*\)/export \1'\2'/g" >$basedir/$SERVERNAME.vars -cat < $basedir/$SERVERNAME.launch +cat <$basedir/$SERVERNAME.launch cd $PWD echo \$\$ > $basedir/$SERVERNAME.pid . $basedir/$SERVERNAME.vars @@ -36,58 +36,59 @@ cd $PWD EOF pid=$$ -cleanup() { - trap "exit 1" SIGINT SIGTERM SIGPIPE - [ -r $basedir/$SERVERNAME.status ] && { - read status < $basedir/$SERVERNAME.status - echo "$(date) samba exited with status $status" >> $basedir/$SERVERNAME.log - exit $status - } +cleanup() +{ + trap "exit 1" SIGINT SIGTERM SIGPIPE + [ -r $basedir/$SERVERNAME.status ] && { + read status <$basedir/$SERVERNAME.status + echo "$(date) samba exited with status $status" >>$basedir/$SERVERNAME.log + exit $status + } - case $ENVNAME in - *.nmbd|*.smbd|*.winbindd|*.samba|*.samba_dcerpcd) - kill $(cat $basedir/../"${ENVNAME%\.*}"/pid/"${ENVNAME##*\.}".pid) - ;; - esac + case $ENVNAME in + *.nmbd | *.smbd | *.winbindd | *.samba | *.samba_dcerpcd) + kill $(cat $basedir/../"${ENVNAME%\.*}"/pid/"${ENVNAME##*\.}".pid) + ;; + esac - read pid < $basedir/$SERVERNAME.pid - echo "$(date) Killing samba pid $pid from $$" >> $basedir/$SERVERNAME.log - if [ "$pid" = "$$" ]; then + read pid <$basedir/$SERVERNAME.pid + echo "$(date) Killing samba pid $pid from $$" >>$basedir/$SERVERNAME.log + if [ "$pid" = "$$" ]; then + exit 1 + fi + kill -9 $pid 2>&1 exit 1 - fi - kill -9 $pid 2>&1 - exit 1 } -echo $$ > $basedir/$SERVERNAME.parent.pid +echo $$ >$basedir/$SERVERNAME.parent.pid trap cleanup SIGINT SIGTERM SIGPIPE if [[ "$TMUX" ]]; then - TMUX_CMD=tmux - if [[ $TMUX = *tmate* ]]; then - TMUX_CMD=tmate - fi + TMUX_CMD=tmux + if [[ $TMUX = *tmate* ]]; then + TMUX_CMD=tmate + fi - $TMUX_CMD new-window -n test:$SERVERNAME "bash $basedir/$SERVERNAME.launch" + $TMUX_CMD new-window -n test:$SERVERNAME "bash $basedir/$SERVERNAME.launch" - # tmux seems to lag a bit for new sessions. Don't create them too - # quickly one after another - sleep .1 + # tmux seems to lag a bit for new sessions. Don't create them too + # quickly one after another + sleep .1 else - screen -r -X screen -t test:$SERVERNAME bash $basedir/$SERVERNAME.launch + screen -r -X screen -t test:$SERVERNAME bash $basedir/$SERVERNAME.launch fi -echo "$(date) waiting in $$" >> $basedir/$SERVERNAME.log +echo "$(date) waiting in $$" >>$basedir/$SERVERNAME.log read stdin_var -echo "$(date) EOF on stdin" >> $basedir/$SERVERNAME.log +echo "$(date) EOF on stdin" >>$basedir/$SERVERNAME.log case $ENVNAME in - *.nmbd|*.smbd|*.winbindd|*.samba|*.samba_dcerpcd) +*.nmbd | *.smbd | *.winbindd | *.samba | *.samba_dcerpcd) kill $(cat $basedir/../"${ENVNAME%\.*}"/pid/"${ENVNAME##*\.}".pid) ;; esac -read pid < $basedir/$SERVERNAME.pid -echo "$(date) killing $pid" >> $basedir/$SERVERNAME.log -kill $pid 2> /dev/null -echo "$(date) exiting" >> $basedir/$SERVERNAME.log +read pid <$basedir/$SERVERNAME.pid +echo "$(date) killing $pid" >>$basedir/$SERVERNAME.log +kill $pid 2>/dev/null +echo "$(date) exiting" >>$basedir/$SERVERNAME.log exit 0 diff --git a/selftest/ns/add_bridge_iface.sh b/selftest/ns/add_bridge_iface.sh index da9d53a5987..4090319cf70 100755 --- a/selftest/ns/add_bridge_iface.sh +++ b/selftest/ns/add_bridge_iface.sh @@ -10,13 +10,11 @@ bridge=$2 # we need to wait for the child namespace to start up and add the new # interface back to our new namespace -while ! ip link show $interface > /dev/null 2>&1 -do - sleep 0.1 - echo "Waiting for $interface to be created..." +while ! ip link show $interface >/dev/null 2>&1; do + sleep 0.1 + echo "Waiting for $interface to be created..." done # bring the bridge-end of the link up and add it to the bridge ip link set dev $interface up ip link set $interface master $bridge - diff --git a/selftest/ns/create_bridge.sh b/selftest/ns/create_bridge.sh index 9766cd8a565..74f7ecafedc 100755 --- a/selftest/ns/create_bridge.sh +++ b/selftest/ns/create_bridge.sh @@ -15,5 +15,3 @@ ip link add $br_name type bridge ip addr add $ip_addr/24 dev $br_name ip addr add $ipv6_addr/112 dev $br_name ip link set $br_name up - - diff --git a/selftest/ns/mk_nsenter.sh b/selftest/ns/mk_nsenter.sh index f175d6bae73..c97fda9ea44 100755 --- a/selftest/ns/mk_nsenter.sh +++ b/selftest/ns/mk_nsenter.sh @@ -23,10 +23,9 @@ helper_script="$(dirname $0)/nsenter-helper.sh $exports_file" # generate the dynamic script dyn_script="$(dirname $2)/nsenter.sh" -echo "#!/bin/sh" > $dyn_script -echo "$nsenter_cmd $helper_script" >> $dyn_script +echo "#!/bin/sh" >$dyn_script +echo "$nsenter_cmd $helper_script" >>$dyn_script chmod 755 $dyn_script # return the script we created echo "$dyn_script" - diff --git a/selftest/ns/nsenter-helper.sh b/selftest/ns/nsenter-helper.sh index f396ed4d98c..4242227eaae 100755 --- a/selftest/ns/nsenter-helper.sh +++ b/selftest/ns/nsenter-helper.sh @@ -4,9 +4,9 @@ # session to a given namespace testenv. This basically just sets up the same # environment variables as you normally get with selftest, for convenience. -if [ $# -lt 1 ] ; then - echo "Usage: $0 " - exit 1 +if [ $# -lt 1 ]; then + echo "Usage: $0 " + exit 1 fi # we get passed a exports file with all the environment variables defined @@ -14,11 +14,11 @@ exports_file=$1 # read the exports file so the new shell has appropriate variables setup # (we export rather than sourcing here so they get inherited by the subshell) -while read -r line ; do - export $line - # dump them for the user too - echo $line -done < $exports_file +while read -r line; do + export $line + # dump them for the user too + echo $line +done <$exports_file echo "" echo "Entered $NETBIOSNAME namespace, with above variables defined." @@ -27,5 +27,3 @@ echo "" # start a shell session in the new namespace $SHELL - - diff --git a/selftest/save.env.sh b/selftest/save.env.sh index 9906f95e1ae..ff9ba32933f 100755 --- a/selftest/save.env.sh +++ b/selftest/save.env.sh @@ -1,15 +1,15 @@ #!/bin/sh { - vars=`set | \ - grep "^[a-zA-Z][^=]*='[^']*'$" | \ - grep -v '^IFS=' | \ - grep -v '^TERM' | \ - grep -v '^PPID' | \ - grep -v '^PS[1-9]=' | \ - cat ` + vars=$(set | + grep "^[a-zA-Z][^=]*='[^']*'$" | + grep -v '^IFS=' | + grep -v '^TERM' | + grep -v '^PPID' | + grep -v '^PS[1-9]=' | + cat) echo "${vars}" echo "${vars}" | sed -e 's!^\([a-zA-Z][^=]*\)=.*$!export \1!' -} > bin/restore.env.source +} >bin/restore.env.source echo "RUN: '. bin/restore.env.source'"