From 1bd28d6f7da5e51e1dadc9a974ca0236d676399b Mon Sep 17 00:00:00 2001 From: Arerep Serdna Date: Thu, 20 May 2010 19:46:05 -0700 Subject: [PATCH] dash compatibility All scripts are now dash(1) compatible. However, coloring and column alignment does not work as expected because of faulty [ -t ] checks. Maybe using test(1) could help, after moving it to /bin. Signed-off-by: Arerep Serdna --- adjtime.cron | 2 +- functions | 24 ++++++++++-------------- netfs | 3 +-- network | 32 ++++++++++++++++---------------- rc.conf | 14 +++++++------- rc.local | 2 +- rc.local.shutdown | 2 +- rc.multi | 8 ++++---- rc.shutdown | 24 +++++++++++++----------- rc.single | 20 +++++++++++--------- rc.sysinit | 26 ++++++++++++++------------ 11 files changed, 79 insertions(+), 78 deletions(-) diff --git a/adjtime.cron b/adjtime.cron index b1c8950..b651d21 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Update our hwclock for system drift . /etc/rc.conf diff --git a/functions b/functions index 672eed2..277263b 100644 --- a/functions +++ b/functions @@ -16,7 +16,7 @@ elif [ -t 0 ]; then else # is /usr/share/terminfo already mounted, and TERM recognized? - /bin/tput cols &>/dev/null + /bin/tput cols >/dev/null 2>&1 if [ $? -eq 0 ]; then STAT_COL=$(/bin/tput cols) fi @@ -77,6 +77,7 @@ else RESTORE_POSITION="" DEL_TEXT="" fi +unset STAT_COL # prefixes: @@ -155,11 +156,7 @@ in_array() { [ -z "$1" ] && return 1 # Not Found local item for item in "$@"; do - local c="${item:0:1}" - if [ "x$c" = "x@" ]; then - item="${item:1}" - fi - [ "$item" = "$needle" ] && return 0 # Found + [ "${item#@}" = "$needle" ] && return 0 # Found done return 1 # Not Found } @@ -204,12 +201,12 @@ stop_daemon() { # Status functions status_started() { deltext - echo -ne "$C_OTHER[${C_STRT}STARTED$C_OTHER]$C_CLEAR " + printf "$C_OTHER[${C_STRT}STARTED$C_OTHER]$C_CLEAR " } status_stopped() { deltext - echo -ne "$C_OTHER[${C_STRT}STOPPED$C_OTHER]$C_CLEAR " + printf "$C_OTHER[${C_STRT}STOPPED$C_OTHER]$C_CLEAR " } ck_status() { @@ -255,18 +252,16 @@ ck_status() { # # Make sure to never override the add_hook and run_hook functions via functions.d -declare -A hook_funcs - add_hook() { [ -z "$1" -o -z "$2" ] && return 1 - hook_funcs["$1"]="${hook_funcs["$1"]} $2" + eval "$1=\$$1\ $2" } run_hook() { - local func - [ -z "$1" ] && return 1 - for func in ${hook_funcs["$1"]}; do + local func + eval "local hook=\$$1" + for func in $hook; do ${func} done } @@ -303,6 +298,7 @@ for f in /etc/rc.d/functions.d/*; do . $f fi done +unset f # End of file # vim: set ft=sh sw=2 ts=2 et: diff --git a/netfs b/netfs index cdfdf98..a5be8c9 100755 --- a/netfs +++ b/netfs @@ -1,6 +1,5 @@ -#!/bin/bash +#!/bin/sh -# sourcing our current rc.conf requires this to be a bash script . /etc/rc.conf . /etc/rc.d/functions diff --git a/network b/network index d23b3a9..a3e6930 100755 --- a/network +++ b/network @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh . /etc/rc.conf . /etc/rc.d/functions @@ -50,11 +50,11 @@ wi_up() [ "$iwcfg" = "" ] && return 0 /usr/sbin/iwconfig $iwcfg - [[ -z "$WIRELESS_TIMEOUT" ]] && WIRELESS_TIMEOUT=2 + [ -z "$WIRELESS_TIMEOUT" ] && WIRELESS_TIMEOUT=2 sleep $WIRELESS_TIMEOUT bssid=`iwgetid $1 -ra` - if [[ "$bssid" = "00:00:00:00:00:00" ]]; then + if [ "$bssid" = "00:00:00:00:00:00" ]; then printhl "Could not associate $1 - try increasing WIRELESS_TIMEOUT and check network is WEP or has no security" return 1 fi @@ -80,7 +80,7 @@ ifdown() iflist() { - for ifline in ${INTERFACES[@]}; do + for ifline in ${INTERFACES}; do if [ "$ifline" = "${ifline#!}" ]; then printf " $ifline:\t" else @@ -98,7 +98,7 @@ rtup() return 1 fi eval routecfg="\$${1}" - if grep -q :: <<< $routecfg; then + if echo $routecfg | grep -q ::; then /sbin/route -A inet6 add $routecfg else /sbin/route add $routecfg @@ -113,7 +113,7 @@ rtdown() return 1 fi eval routecfg="\$${1}" - if grep -q :: <<< $routecfg; then + if echo $routecfg | grep -q ::; then /sbin/route -A inet6 del $routecfg else /sbin/route del $routecfg @@ -123,7 +123,7 @@ rtdown() rtlist() { - for rtline in ${ROUTES[@]}; do + for rtline in ${ROUTES}; do if [ "$rtline" = "${rtline#!}" ]; then printf " $rtline:\t" else @@ -136,7 +136,7 @@ rtlist() bond_up() { - for ifline in ${BOND_INTERFACES[@]}; do + for ifline in ${BOND_INTERFACES}; do if [ "$ifline" = "${ifline#!}" ]; then eval bondcfg="\$bond_${ifline}" if [ -n "${bondcfg}" ]; then @@ -148,7 +148,7 @@ bond_up() bond_down() { - for ifline in ${BOND_INTERFACES[@]}; do + for ifline in ${BOND_INTERFACES}; do if [ "$ifline" = "${ifline#!}" ]; then eval bondcfg="\$bond_${ifline}" /sbin/ifenslave -d $ifline $bondcfg || error=1 @@ -158,7 +158,7 @@ bond_down() bridge_up() { - for br in ${BRIDGE_INTERFACES[@]}; do + for br in ${BRIDGE_INTERFACES}; do if [ "$br" = "${br#!}" ]; then # if the bridge already exists, remove it if [ "$(/sbin/ifconfig $br 2>/dev/null)" ]; then @@ -169,7 +169,7 @@ bridge_up() eval brifs="\$bridge_${br}" for brif in $brifs; do if [ "$brif" = "${brif#!}" ]; then - for ifline in ${BOND_INTERFACES[@]}; do + for ifline in ${BOND_INTERFACES}; do if [ "$brif" = "$ifline" ] && [ "$ifline" = "${ifline#!}" ]; then ifup $ifline eval bondcfg="\$bond_${ifline}" @@ -187,7 +187,7 @@ bridge_up() bridge_down() { - for br in ${BRIDGE_INTERFACES[@]}; do + for br in ${BRIDGE_INTERFACES}; do if [ "$br" = "${br#!}" ]; then /usr/sbin/brctl delbr $br fi @@ -207,7 +207,7 @@ case "$1" in # bring up bridge interfaces bridge_up # bring up ethernet interfaces - for ifline in ${INTERFACES[@]}; do + for ifline in ${INTERFACES}; do if [ "$ifline" = "${ifline#!}" ]; then ifup $ifline || error=1 fi @@ -215,7 +215,7 @@ case "$1" in # bring up bond interfaces bond_up # bring up routes - for rtline in "${ROUTES[@]}"; do + for rtline in ${ROUTES}; do if [ "$rtline" = "${rtline#!}" ]; then rtup $rtline || error=1 fi @@ -236,14 +236,14 @@ case "$1" in stat_busy "Stopping Network" rm_daemon network error=0 - for rtline in "${ROUTES[@]}"; do + for rtline in ${ROUTES}; do if [ "$rtline" = "${rtline#!}" ]; then rtdown $rtline || error=1 fi done # bring down bond interfaces bond_down - for ifline in ${INTERFACES[@]}; do + for ifline in ${INTERFACES}; do if [ "$ifline" = "${ifline#!}" ]; then ifdown $ifline || error=1 fi diff --git a/rc.conf b/rc.conf index 252a9b1..f4f1dd9 100644 --- a/rc.conf +++ b/rc.conf @@ -34,8 +34,8 @@ USECOLOR="yes" # NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES array. # MOD_AUTOLOAD="yes" -#MOD_BLACKLIST=() #deprecated -MODULES=() +#MOD_BLACKLIST="" #deprecated +MODULES="" # Scan for LVM volume groups at startup, required if you use LVM USELVM="no" @@ -62,15 +62,15 @@ HOSTNAME="myhost" #Static IP example #eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255" eth0="dhcp" -INTERFACES=(eth0) +INTERFACES="eth0" # Routes to start at boot-up (in this order) # Declare each route then list in ROUTES # - prefix an entry in ROUTES with a ! to disable it # gateway="default gw 192.168.0.1" -ROUTES=(!gateway) - +ROUTES="!gateway" + # Enable these network profiles at boot-up. These are only useful # if you happen to need multiple network configurations (ie, laptop users) # - set to 'menu' to present a menu during boot-up (dialog package required) @@ -80,7 +80,7 @@ ROUTES=(!gateway) # # This now requires the netcfg package # -#NETWORKS=(main) +#NETWORKS="main" # ----------------------------------------------------------------------- # DAEMONS @@ -90,4 +90,4 @@ ROUTES=(!gateway) # - prefix a daemon with a ! to disable it # - prefix a daemon with a @ to start it up in the background # -DAEMONS=(syslog-ng network netfs crond) +DAEMONS="syslog-ng network netfs crond" diff --git a/rc.local b/rc.local index 4950cba..e51ecc1 100755 --- a/rc.local +++ b/rc.local @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.local: Local multi-user startup script. # diff --git a/rc.local.shutdown b/rc.local.shutdown index fe60462..e96ac7d 100755 --- a/rc.local.shutdown +++ b/rc.local.shutdown @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.local.shutdown: Local shutdown script. # diff --git a/rc.multi b/rc.multi index a7ea703..acb2106 100755 --- a/rc.multi +++ b/rc.multi @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.multi # @@ -9,15 +9,15 @@ run_hook multi_start # Load sysctl variables if sysctl.conf is present -[ -r /etc/sysctl.conf ] && /sbin/sysctl -q -p &>/dev/null +[ -r /etc/sysctl.conf ] && /sbin/sysctl -q -p >/dev/null 2>&1 # Start daemons -for daemon in "${DAEMONS[@]}"; do +for daemon in ${DAEMONS}; do if [ "$daemon" = "${daemon#!}" ]; then if [ "$daemon" = "${daemon#@}" ]; then start_daemon $daemon else - start_daemon_bkgd ${daemon:1} + start_daemon_bkgd ${daemon#@} fi fi done diff --git a/rc.shutdown b/rc.shutdown index 187e29e..74752bc 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.shutdown # @@ -27,29 +27,31 @@ fi # Find daemons NOT in the DAEMONS array. Shut these down first if [ -d /var/run/daemons ]; then for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then + if ! in_array $daemon ${DAEMONS}; then stop_daemon $daemon fi done fi # Shutdown daemons in reverse order -let i=${#DAEMONS[@]}-1 -while [ $i -ge 0 ]; do - if [ "${DAEMONS[$i]:0:1}" != '!' ]; then - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} +set -- $DAEMONS +i=$# +while [ $i -gt 0 ]; do + eval 'daemon=${'$i'#@}' + if [ "${daemon%%!*}" ]; then + ck_daemon $daemon || stop_daemon $daemon fi - let i=i-1 + i=$((i - 1)) done # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook shutdown_prekillall -/sbin/killall5 -15 &> /dev/null +/sbin/killall5 -15 > /dev/null 2>&1 /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" -/sbin/killall5 -9 &> /dev/null +/sbin/killall5 -9 > /dev/null 2>&1 /bin/sleep 1 stat_done @@ -57,7 +59,7 @@ run_hook shutdown_postkillall stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed -[ -d $(dirname $RANDOM_SEED) ] || mkdir -p $(dirname $RANDOM_SEED) +[ -d $(/usr/bin/dirname $RANDOM_SEED) ] || mkdir -p $(/usr/bin/dirname $RANDOM_SEED) : > $RANDOM_SEED /bin/chmod 0600 $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize @@ -66,7 +68,7 @@ if [ -r $POOL_FILE ]; then else POOL_SIZE=512 fi -/bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null +/bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE > /dev/null 2>&1 stat_done stat_busy "Saving System Clock" diff --git a/rc.single b/rc.single index e8b6f08..f586c57 100755 --- a/rc.single +++ b/rc.single @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.single: Single-user startup script. # @@ -13,29 +13,31 @@ if [ "$PREVLEVEL" != "N" ]; then # Find daemons NOT in the DAEMONS array. Shut these down first if [ -d /var/run/daemons ]; then for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then + if ! in_array $daemon ${DAEMONS}; then stop_daemon $daemon fi done fi # Shutdown daemons in reverse order - let i=${#DAEMONS[@]}-1 - while [ $i -ge 0 ]; do - if [ "${DAEMONS[$i]:0:1}" != '!' ]; then - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + set -- $DAEMONS + i=$# + while [ $i -gt 0 ]; do + eval 'daemon=${'$i'#@}' + if [ "${daemon%%!*}" ]; then + ck_daemon $daemon || stop_daemon $daemon fi - let i=i-1 + i=$((i - 1)) done # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook single_prekillall - /sbin/killall5 -15 &> /dev/null + /sbin/killall5 -15 > /dev/null 2>&1 /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 &> /dev/null + /sbin/killall5 -9 > /dev/null 2>&1 /bin/sleep 1 stat_done diff --git a/rc.sysinit b/rc.sysinit index c558745..2c59411 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # /etc/rc.sysinit # @@ -77,17 +77,17 @@ run_hook sysinit_udevlaunched # Trigger udev uevents if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then - stat_busy "Triggering UDev uevents" - /sbin/udevadm control --property=STARTUP=1 - /sbin/udevadm trigger - stat_done + stat_busy "Triggering UDev uevents" + /sbin/udevadm control --property=STARTUP=1 + /sbin/udevadm trigger + stat_done fi # Load modules from the MODULES array defined in rc.conf if ! [ "$load_modules" = "off" ]; then if [ -f /proc/modules ]; then stat_busy "Loading Modules" - for mod in "${MODULES[@]}"; do + for mod in ${MODULES}; do if [ "$mod" = "${mod#!}" ]; then /sbin/modprobe $mod fi @@ -185,7 +185,7 @@ if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" else $CS $copts create $cname $csrc < /dev/console fi - elif [ "${cpass:0:1}" != "/" ]; then + elif [ "${cpass%%/*}" ]; then if $CS isLuks $csrc 2>/dev/null; then echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null else @@ -323,12 +323,14 @@ if [ -f $RANDOM_SEED ]; then fi stat_busy "Removing Leftover Files" -/bin/rm -f /etc/nologin &>/dev/null -/bin/rm -f /etc/shutdownpid &>/dev/null -/bin/rm -f /var/lock/* &>/dev/null -/bin/rm -rf /tmp/* /tmp/.* &>/dev/null -/bin/rm -f /forcefsck &>/dev/null +{ +/bin/rm -f /etc/nologin +/bin/rm -f /etc/shutdownpid +/bin/rm -f /var/lock/* +/bin/rm -rf /tmp/* /tmp/.* +/bin/rm -f /forcefsck (cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +} >/dev/null 2>&1 : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1