From dad5bfbd18bf233126263bf985777ef6f28cbc1e Mon Sep 17 00:00:00 2001 From: HW42 Date: Thu, 5 Feb 2015 03:14:41 +0100 Subject: [PATCH] remove 'bashisms' or explicit use bash --- debian/qubes-core-agent.postrm | 4 ++-- debian/qubes-core-agent.preinst | 2 +- debian/qubes-core-agent.prerm | 2 +- misc/dispvm-prerun.sh | 4 ++-- network/30-qubes-external-ip | 4 ++-- network/iptables-updates-proxy | 2 +- network/qubes-firewall | 12 ++++++------ network/qubes-netwatcher | 10 +++++----- network/show-hide-nm-applet.sh | 2 +- qubes-rpc/prepare-suspend | 4 ++-- qubes-rpc/qubes.Backup | 3 +-- qubes-rpc/qubes.GetImageRGBA | 16 ++++++++-------- qubes-rpc/qubes.Restore | 3 +-- qubes-rpc/qvm-open-in-dvm | 2 +- qubes-rpc/qvm-open-in-vm | 2 +- qubes-rpc/qvm-run | 2 +- vm-init.d/qubes-core | 2 +- vm-init.d/qubes-core-appvm | 2 +- vm-init.d/qubes-core-netvm | 2 +- vm-init.d/qubes-firewall | 2 +- vm-init.d/qubes-netwatcher | 2 +- vm-init.d/qubes-qrexec-agent | 2 +- vm-init.d/qubes-updates-proxy | 2 +- vm-systemd/qubes-sysinit.sh | 2 +- vm-systemd/qubes-update-check.service | 2 +- 25 files changed, 45 insertions(+), 47 deletions(-) diff --git a/debian/qubes-core-agent.postrm b/debian/qubes-core-agent.postrm index 537679c..1c0d124 100755 --- a/debian/qubes-core-agent.postrm +++ b/debian/qubes-core-agent.postrm @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # postrm script for core-agent-linux # # see: dh_installdeb(1) @@ -37,7 +37,7 @@ set -e # the debian-policy package if [ "${1}" = "remove" ] ; then - /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &> /dev/null || : + /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas > /dev/null 2>&1 || : if [ -L /lib/firmware/updates ]; then rm /lib/firmware/updates diff --git a/debian/qubes-core-agent.preinst b/debian/qubes-core-agent.preinst index 0302e29..eddbf68 100755 --- a/debian/qubes-core-agent.preinst +++ b/debian/qubes-core-agent.preinst @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # preinst script for core-agent-linux # # see: dh_installdeb(1) diff --git a/debian/qubes-core-agent.prerm b/debian/qubes-core-agent.prerm index 502a13a..6790be4 100755 --- a/debian/qubes-core-agent.prerm +++ b/debian/qubes-core-agent.prerm @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # prerm script for core-agent-linux # # see: dh_installdeb(1) diff --git a/misc/dispvm-prerun.sh b/misc/dispvm-prerun.sh index 9489144..d9db237 100755 --- a/misc/dispvm-prerun.sh +++ b/misc/dispvm-prerun.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh apps="evince /usr/libexec/evinced soffice firefox" @@ -18,7 +18,7 @@ echo "Sleeping..." PREV_IO=0 while true; do IO=`vmstat -D | awk '/read|write/ {IOs+=$1} END {print IOs}'` - if [ $IO -lt $[ $PREV_IO + 50 ] ]; then + if [ $IO -lt $(( $PREV_IO + 50 )) ]; then break; fi PREV_IO=$IO diff --git a/network/30-qubes-external-ip b/network/30-qubes-external-ip index 1d46834..3dd5ec1 100755 --- a/network/30-qubes-external-ip +++ b/network/30-qubes-external-ip @@ -1,8 +1,8 @@ #!/bin/sh -if [ x$2 == xup ]; then +if [ x$2 = xup ]; then INET=$(/sbin/ip addr show dev $1 | /bin/grep inet) qubesdb-write /qubes-netvm-external-ip "$INET" fi -if [ x$2 == xdown ]; then +if [ x$2 = xdown ]; then qubesdb-write /qubes-netvm-external-ip "" fi diff --git a/network/iptables-updates-proxy b/network/iptables-updates-proxy index f81a7c1..3bddd5c 100755 --- a/network/iptables-updates-proxy +++ b/network/iptables-updates-proxy @@ -3,7 +3,7 @@ RULE_FILTER="INPUT -i vif+ -p tcp --dport 8082 -j ACCEPT" RULE_NAT="PR-QBS-SERVICES -i vif+ -d 10.137.255.254 -p tcp --dport 8082 -j REDIRECT" -if [ "$1" == "start" ]; then +if [ "$1" = "start" ]; then cat <<__EOF__ | iptables-restore -n *filter -I $RULE_FILTER diff --git a/network/qubes-firewall b/network/qubes-firewall index f636a36..1cf5986 100755 --- a/network/qubes-firewall +++ b/network/qubes-firewall @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e PIDFILE=/var/run/qubes/qubes-firewall.pid @@ -7,10 +7,10 @@ XENSTORE_IPTABLES_HEADER=/qubes-iptables-header XENSTORE_ERROR=/qubes-iptables-error OLD_RULES="" # PIDfile handling -[[ -e $PIDFILE ]] && kill -s 0 $(<$PIDFILE) 2>/dev/null && exit 0 +[ -e "$PIDFILE" ] && kill -s 0 $(cat "$PIDFILE") 2>/dev/null && exit 0 echo $$ >$PIDFILE -trap 'exit 0' SIGTERM +trap 'exit 0' TERM FIRST_TIME=yes @@ -36,11 +36,11 @@ while true; do RULES=$(qubesdb-read $XENSTORE_IPTABLES_HEADER) IPTABLES_SAVE=$(iptables-save | sed '/^\*filter/,/^COMMIT/d') - OUT=`echo -e "$RULES\n$IPTABLES_SAVE" | iptables-restore 2>&1 || true` + OUT=$(printf '%s\n%s\n' "$RULES" "$IPTABLES_SAVE" | sed 's/\\n/\n/g' | iptables-restore 2>&1 || true) for i in $(qubesdb-list -f /qubes-iptables-domainrules) ; do RULES=$(qubesdb-read "$i") - ERRS=`echo -e "$RULES" | /sbin/iptables-restore -n 2>&1 || true` + ERRS=$(printf '%s\n' "$RULES" | sed 's/\\n/\n/g' | /sbin/iptables-restore -n 2>&1 || true) if [ -n "$ERRS" ]; then echo "Failed applying rules for $i: $ERRS" >&2 OUT="$OUT$ERRS" @@ -48,7 +48,7 @@ while true; do done qubesdb-write $XENSTORE_ERROR "$OUT" if [ -n "$OUT" ]; then - DISPLAY=:0 /usr/bin/notify-send -t 3000 "Firewall loading error ($HOSTNAME)" "$OUT" || : + DISPLAY=:0 /usr/bin/notify-send -t 3000 "Firewall loading error ($(hostname))" "$OUT" || : fi # Check if user didn't define some custom rules to be applied as well... diff --git a/network/qubes-netwatcher b/network/qubes-netwatcher index 81edffe..3cd46be 100755 --- a/network/qubes-netwatcher +++ b/network/qubes-netwatcher @@ -1,23 +1,23 @@ -#!/bin/bash +#!/bin/sh set -e PIDFILE=/var/run/qubes/qubes-netwatcher.pid CURR_NETCFG="" # PIDfile handling -[[ -e $PIDFILE ]] && kill -s 0 $(<$PIDFILE) 2>/dev/null && exit 0 +[ -e "$PIDFILE" ] && kill -s 0 $(cat "$PIDFILE") 2>/dev/null && exit 0 echo $$ >$PIDFILE -trap 'exit 0' SIGTERM +trap 'exit 0' TERM while true; do NET_DOMID=$(xenstore-read qubes-netvm-domid || :) - if [[ -n "$NET_DOMID" ]] && [[ $NET_DOMID -gt 0 ]]; then + if [ -n "$NET_DOMID" ] && [ $NET_DOMID -gt 0 ]; then UNTRUSTED_NETCFG=$(xenstore-read /local/domain/$NET_DOMID/qubes-netvm-external-ip || :) # UNTRUSTED_NETCFG is not parsed in any way # thus, no sanitization ready # but be careful when passing it to other shell scripts - if [[ "$UNTRUSTED_NETCFG" != "$CURR_NETCFG" ]]; then + if [ "$UNTRUSTED_NETCFG" != "$CURR_NETCFG" ]; then /sbin/service qubes-firewall stop /sbin/service qubes-firewall start CURR_NETCFG="$UNTRUSTED_NETCFG" diff --git a/network/show-hide-nm-applet.sh b/network/show-hide-nm-applet.sh index 46b4846..da66bf8 100644 --- a/network/show-hide-nm-applet.sh +++ b/network/show-hide-nm-applet.sh @@ -1,6 +1,6 @@ #!/bin/sh -type nm-applet > /dev/null 2>&1 || exit 0 +which nm-applet > /dev/null 2>&1 || exit 0 # Hide nm-applet when network-manager is disabled nm_enabled=false diff --git a/qubes-rpc/prepare-suspend b/qubes-rpc/prepare-suspend index 975e06f..bf22344 100755 --- a/qubes-rpc/prepare-suspend +++ b/qubes-rpc/prepare-suspend @@ -11,7 +11,7 @@ if [ -r /rw/config/suspend-module-blacklist ]; then MODULES_BLACKLIST="$MODULES_BLACKLIST `cat /rw/config/suspend-module-blacklist`" fi -if [ x"$action" == x"suspend" ]; then +if [ x"$action" = x"suspend" ]; then dbus-send --system --print-reply \ --dest=org.freedesktop.NetworkManager \ /org/freedesktop/NetworkManager \ @@ -19,7 +19,7 @@ if [ x"$action" == x"suspend" ]; then service NetworkManager stop # Force interfaces down, just in case when NM didn't done it for if in `ls /sys/class/net|grep -v "lo\|vif"`; do - if [ "`cat /sys/class/net/$if/device/devtype 2>/dev/null`" == "vif" ]; then + if [ "`cat /sys/class/net/$if/device/devtype 2>/dev/null`" = "vif" ]; then continue fi ip l s $if down diff --git a/qubes-rpc/qubes.Backup b/qubes-rpc/qubes.Backup index cb194d0..399f08a 100644 --- a/qubes-rpc/qubes.Backup +++ b/qubes-rpc/qubes.Backup @@ -9,8 +9,7 @@ if [ -d "$args" ] ; then else echo "Checking if arguments is matching a command" COMMAND=`echo $args | cut -d ' ' -f 1` - TYPE=`type -t $COMMAND` - if [ "$TYPE" == "file" ] ; then + if which "$COMMAND"; then echo "Redirecting STDIN to $args" # Parsing args to handle quotes correctly # Dangerous method if args are uncontrolled diff --git a/qubes-rpc/qubes.GetImageRGBA b/qubes-rpc/qubes.GetImageRGBA index e032486..873727e 100644 --- a/qubes-rpc/qubes.GetImageRGBA +++ b/qubes-rpc/qubes.GetImageRGBA @@ -1,31 +1,31 @@ set -e read filename -if [[ "${filename}" = xdgicon:* ]]; then +if [ "${filename%%:*}" = xdgicon ]; then # get biggest icon from hicolor theme filename="${filename#*:}.png" candidate= - for dir in /usr/share/icons/{hicolor/,}; do + for dir in /usr/share/icons/hicolor/ /usr/share/icons/; do candidate=$(find -L "${dir}" -type f -name "${filename}") - if [[ -n "${candidate}" ]]; then + if [ -n "${candidate}" ]; then candidate=$(echo "${candidate}" | xargs ls --sort=size | head -1) break fi done - [[ -n "${candidate}" ]] + [ -n "${candidate}" ] filename="${candidate}" -elif [[ "${filename}" = "-" ]] || [[ "${filename}" = *":-" ]]; then +elif [ "${filename}" = "-" ] || [ "${filename##*:}" = "-" ]; then tmpfile="$(mktemp /tmp/qimg-XXXXXXXX)" cat > "${tmpfile}" - if [[ "$filename" = *":-" ]]; then + if [ "${filename##*:}" = "-" ]; then tmpfile="${filename%:*}:${tmpfile}" fi filename="${tmpfile}" -elif ! [[ -r "${filename}" ]]; then +elif ! [ -r "${filename}" ]; then exit 1 fi @@ -34,6 +34,6 @@ fi identify -format '%w %h\n' "$filename" | sed -e '/^$/d' convert -depth 8 "$filename" rgba:- -[[ -n "${tmpfile}" ]] && rm -f ${tmpfile} || true +[ -n "${tmpfile}" ] && rm -f ${tmpfile} || true # vim: ft=sh ts=4 sw=4 et diff --git a/qubes-rpc/qubes.Restore b/qubes-rpc/qubes.Restore index c77774f..ad73c39 100644 --- a/qubes-rpc/qubes.Restore +++ b/qubes-rpc/qubes.Restore @@ -11,8 +11,7 @@ if [ -f "$args" ] ; then else echo "Checking if arguments is matching a command" >&2 COMMAND=`echo $args | cut -d ' ' -f 1` - TYPE=`type -t $COMMAND` - if [ "$TYPE" == "file" ] ; then + if which "$COMMAND"; then tmpdir=`mktemp -d` mkfifo $tmpdir/backup-data echo "Redirecting $args to STDOUT" >&2 diff --git a/qubes-rpc/qvm-open-in-dvm b/qubes-rpc/qvm-open-in-dvm index 0351401..cfcae2e 100755 --- a/qubes-rpc/qvm-open-in-dvm +++ b/qubes-rpc/qvm-open-in-dvm @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes-rpc/qvm-open-in-vm b/qubes-rpc/qvm-open-in-vm index c96d129..b30779d 100755 --- a/qubes-rpc/qvm-open-in-vm +++ b/qubes-rpc/qvm-open-in-vm @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/qubes-rpc/qvm-run b/qubes-rpc/qvm-run index 7d58b60..a8a1aec 100755 --- a/qubes-rpc/qvm-run +++ b/qubes-rpc/qvm-run @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # The Qubes OS Project, http://www.qubes-os.org # diff --git a/vm-init.d/qubes-core b/vm-init.d/qubes-core index ce6a9cc..9284069 100755 --- a/vm-init.d/qubes-core +++ b/vm-init.d/qubes-core @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 90 90 # description: Executes Qubes core scripts at VM boot diff --git a/vm-init.d/qubes-core-appvm b/vm-init.d/qubes-core-appvm index 02ec92c..c1696de 100755 --- a/vm-init.d/qubes-core-appvm +++ b/vm-init.d/qubes-core-appvm @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 85 85 # description: Executes Qubes core scripts at AppVM boot diff --git a/vm-init.d/qubes-core-netvm b/vm-init.d/qubes-core-netvm index 16033dc..4cf4955 100755 --- a/vm-init.d/qubes-core-netvm +++ b/vm-init.d/qubes-core-netvm @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 90 90 # description: Executes Qubes core scripts at NetVM boot diff --git a/vm-init.d/qubes-firewall b/vm-init.d/qubes-firewall index 989cced..4b17649 100755 --- a/vm-init.d/qubes-firewall +++ b/vm-init.d/qubes-firewall @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 91 91 # description: Starts Qubes Firewall monitor diff --git a/vm-init.d/qubes-netwatcher b/vm-init.d/qubes-netwatcher index 5f7a921..316c271 100755 --- a/vm-init.d/qubes-netwatcher +++ b/vm-init.d/qubes-netwatcher @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 92 92 # description: Starts Qubes Network monitor diff --git a/vm-init.d/qubes-qrexec-agent b/vm-init.d/qubes-qrexec-agent index 70923ec..7fecd51 100755 --- a/vm-init.d/qubes-qrexec-agent +++ b/vm-init.d/qubes-qrexec-agent @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # chkconfig: 345 90 90 # description: Executes Qubes core scripts at VM boot diff --git a/vm-init.d/qubes-updates-proxy b/vm-init.d/qubes-updates-proxy index 2959bf6..ae71762 100755 --- a/vm-init.d/qubes-updates-proxy +++ b/vm-init.d/qubes-updates-proxy @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # tinyproxy Startup script for the tinyproxy server as Qubes updates proxy # diff --git a/vm-systemd/qubes-sysinit.sh b/vm-systemd/qubes-sysinit.sh index a0d0670..877447e 100755 --- a/vm-systemd/qubes-sysinit.sh +++ b/vm-systemd/qubes-sysinit.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # List of services enabled by default (in case of absence of qubesdb entry) DEFAULT_ENABLED_NETVM="network-manager qubes-network qubes-update-check qubes-updates-proxy" diff --git a/vm-systemd/qubes-update-check.service b/vm-systemd/qubes-update-check.service index 9879080..bca933b 100644 --- a/vm-systemd/qubes-update-check.service +++ b/vm-systemd/qubes-update-check.service @@ -4,4 +4,4 @@ ConditionPathExists=/var/run/qubes-service/qubes-update-check [Service] Type=oneshot -ExecStart=/usr/lib/qubes/qrexec-client-vm dom0 qubes.NotifyUpdates /bin/sh -c 'if [ -e /usr/bin/yum ]; then yum -q check-update >/dev/null; [ $? -eq 100 ] && echo 1 || echo 0; else apt-get -q update > /dev/null; apt-get -s upgrade | awk "/^Inst/{ print $2 }" | [[ $(wc -L) -eq 0 ]] && echo 0 || echo 1; fi' +ExecStart=/usr/lib/qubes/qrexec-client-vm dom0 qubes.NotifyUpdates /bin/sh -c 'if [ -e /usr/bin/yum ]; then yum -q check-update >/dev/null; [ $? -eq 100 ] && echo 1 || echo 0; else apt-get -q update > /dev/null; apt-get -s upgrade | awk "/^Inst/{ print $2 }" | [ $(wc -L) -eq 0 ] && echo 0 || echo 1; fi'