From 6b5fe69bb65b1584272bc1161a85e07fb95b66cb Mon Sep 17 00:00:00 2001 From: "Kurt J. Bosch" Date: Fri, 24 Jun 2011 09:28:25 +0200 Subject: Some cosmetics --- functions | 51 ++++++++++++++++++++++++++------------------------- rc.shutdown | 17 +++++++++-------- rc.sysinit | 39 +++++++++++++++++++-------------------- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/functions b/functions index ea5b11f..d57fe16 100644 --- a/functions +++ b/functions @@ -25,14 +25,14 @@ calc_columns () { # is /usr/share/terminfo already mounted, and TERM recognized? STAT_COL=$(/bin/tput cols) fi - if ((STAT_COL==0)); then + if (( STAT_COL == 0 )); then # if output was 0 (serial console), set default width to 80 STAT_COL=80 USECOLOR="" fi # we use 13 characters for our own stuff - STAT_COL=$(($STAT_COL - 13)) + STAT_COL=$(( $STAT_COL - 13 )) if [[ -t 1 ]]; then SAVE_POSITION="\e[s" @@ -49,7 +49,7 @@ calc_columns # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" -if (($? != 3)); then +if (( $? != 3 )); then case $TERM_COLORS in *[!0-9]*) USECOLOR="";; [0-7]) USECOLOR="";; @@ -65,14 +65,14 @@ unset TZ unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ LC_MEASUREMENT LC_IDENTIFICATION LC_ALL -if [[ $DAEMON_LOCALE =~ yes|YES && -n $LOCALE ]]; then +if [[ $DAEMON_LOCALE = [yY][eE][sS] && $LOCALE ]]; then export LANG="${LOCALE}" else export LANG=C fi # set colors -if [[ $USECOLOR =~ yes|YES ]]; then +if [[ $USECOLOR = [yY][eE][sS] ]]; then if /bin/tput setaf 0 &>/dev/null; then C_CLEAR="$(tput sgr0)" # clear text C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text @@ -247,17 +247,17 @@ ck_status() { # Return PID of $1 get_pid() { - pidof -o %PPID $1 || return 1 + pidof -o %PPID $1 || return 1 } # Check if PID-file $1 is still the active PID-file for command $2 ck_pidfile() { - if [[ -f "$1" ]]; then - read -r fpid <"$1" - ppid=$(get_pid $2) - [[ "$fpid" = "$ppid" ]] && return 0 - fi - return 1 + if [[ -f "$1" ]]; then + read -r fpid <"$1" + ppid=$(get_pid $2) + [[ "$fpid" = "$ppid" ]] && return 0 + fi + return 1 } # PIDs to be omitted by killall5 @@ -279,9 +279,9 @@ kill_everything() { done # Shutdown daemons in reverse order - for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do - [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do + [[ ${DAEMONS[i]} = '!'* ]] && continue + ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} done # Terminate all processes @@ -291,12 +291,12 @@ kill_everything() { for pid in ${omit_pids[@]}; do k5args+=" -o $pid" done - /sbin/killall5 -15 $k5args &> /dev/null + /sbin/killall5 -15 $k5args &>/dev/null /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &> /dev/null + /sbin/killall5 -9 $k5args &>/dev/null /bin/sleep 1 stat_done @@ -304,7 +304,7 @@ kill_everything() { } activate_vgs() { - [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]] || return + [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" @@ -330,7 +330,7 @@ read_crypttab() { # $1 = function to call with the split out line from the crypttab local line nspo failed=0 while read line; do - [[ $line && ${line:0:1} != '#' ]] || continue + [[ $line && $line != '#'* ]] || continue eval nspo=("${line%#*}") if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then crypto_unlocked=1 @@ -353,7 +353,7 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? - if ((fsckret > 1)); then + if (( fsckret > 1 )); then stat_fail else stat_done @@ -367,7 +367,7 @@ fsck_reboot() { # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' if (( ($1 | 33) == 33 )); then return 0 - elif (($1 & 2)); then + elif (( $1 & 2 )); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -442,7 +442,7 @@ mount_all() { # Declare add_hook and run_hook as read-only to prevent overwriting them. # Too bad we cannot do the same thing with hook_funcs -if [[ $RC_FUNCTIONS_HOOK_FUNCS_DEFINED -ne 1 ]]; then +if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then declare -A hook_funcs add_hook() { @@ -468,11 +468,12 @@ set_consolefont() { stat_busy "Loading Console Font: $CONSOLEFONT" #CONSOLEMAP in UTF-8 shouldn't be used [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" + local i for i in /dev/tty[0-9]*; do /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} >/dev/null 2>&1 + $CONSOLEFONT -C ${i} &>/dev/null done - if (($? != 0)); then + if (( $? )); then stat_fail elif [[ $CONSOLEMAP ]]; then cat <<"EOF" >>/etc/profile.d/locale.sh @@ -491,7 +492,7 @@ done # Exit current shell if user is not root need_root() { - (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 + (( EUID )) && printf 'You need to be root.\n' && exit 1 } # Quit script if it's not running by root diff --git a/rc.shutdown b/rc.shutdown index 4014df2..2d23554 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -32,7 +32,7 @@ if [[ -r $POOL_FILE ]]; then else POOL_SIZE=512 fi -dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null +dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null stat_done if [[ $TIMEZONE ]]; then @@ -48,7 +48,7 @@ status "Deactivating Swap" swapoff -a # stop monitoring of lvm2 groups before unmounting filesystems if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then status "Deactivating monitoring of LVM2 groups" \ - vgchange --monitor n >/dev/null 2>&1 + vgchange --monitor n &>/dev/null fi stat_busy "Unmounting Filesystems" @@ -63,16 +63,16 @@ stat_done run_hook shutdown_postumount # Kill non-root encrypted partition mappings -if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then +if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" # Maybe someone has LVM on an encrypted block device # executing an extra vgchange is errorless if [[ $USELVM = [Yy][Ee][Ss] ]]; then - vgchange --sysinit -a n >/dev/null 2>&1 + vgchange --sysinit -a n &>/dev/null fi do_lock() { stat_append "${1}.." - if $CS remove "$1" >/dev/null 2>&1; then + if $CS remove "$1" &>/dev/null; then stat_append "ok " else stat_append "failed " @@ -83,10 +83,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then fi if [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]]; then - status "Deactivating LVM2 groups" vgchange --sysinit -a n >/dev/null 2>&1 + status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null fi -status "Remounting Root Filesystem Read-only" mount -n -o remount,ro / +status "Remounting Root Filesystem Read-only" \ + mount -n -o remount,ro / run_hook shutdown_poweroff @@ -98,7 +99,7 @@ if [[ $RUNLEVEL = 0 ]]; then else printhl "${C_H2}REBOOTING" # if kexec is installed and a kernel is loaded, use it - [[ -x $(type -P kexec) ]] && kexec -e > /dev/null 2>&1 + [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null reboot -d -f -i fi diff --git a/rc.sysinit b/rc.sysinit index 2b86011..5167a14 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -19,14 +19,14 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems) mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev -mountpoint -q /run || mount -n -t tmpfs run /run -o mode=755,size=10M,nosuid,nodev +mountpoint -q /run || mount -n -t tmpfs run /run -o mode=0755,size=10M,nosuid,nodev mountpoint -q /dev || mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid &>/dev/null \ || mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid mkdir -p -m 1777 /run/lock mkdir -p /dev/{pts,shm} -mountpoint -q /dev/pts || mount -n /dev/pts &> /dev/null \ - || mount -n -t devpts devpts /dev/pts -o mode=620,gid=5,nosuid,noexec -mountpoint -q /dev/shm || mount -n /dev/shm &> /dev/null \ +mountpoint -q /dev/pts || mount -n /dev/pts &>/dev/null \ + || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec +mountpoint -q /dev/shm || mount -n /dev/shm &>/dev/null \ || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev # remount root ro to allow for fsck later on, we remount now to @@ -84,7 +84,6 @@ stat_done if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then status "Loading Modules" modprobe -ab "${MODULES[@]}" fi -unset mods status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} @@ -111,7 +110,7 @@ fi activate_vgs # Set up non-root encrypted partition mappings -if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then +if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then modprobe -q dm-crypt 2>/dev/null stat_busy "Unlocking encrypted volumes:" do_unlock() { @@ -143,11 +142,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then # This sanity check _should_ be sufficient, but it might not. # This may cause dataloss if it is not used carefully. blkid -p "$2" &>/dev/null - if [[ $? -eq 2 ]]; then + if (( $? == 2 )); then _overwriteokay=1 fi fi - if [[ $_overwriteokay -eq 0 ]]; then + if (( _overwriteokay == 0 )); then false elif $CS -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then stat_append "creating swapspace.." @@ -185,7 +184,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then *) echo "$3" | $CS $4 $open "$a" "$b" >/dev/null;; esac - if (($? != 0)); then + if (( $? )); then failed=1 stat_append "failed " else @@ -199,7 +198,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && grep -q ^[^#] /etc/crypttab; then else stat_fail fi - if [[ ${crypto_unlocked} -eq 1 ]]; then + if (( crypto_unlocked == 1 )); then # Maybe someone has LVM on an encrypted block device activate_vgs fi @@ -213,16 +212,16 @@ fi status "Remounting Root Read/Write" \ mount -n -o remount,rw / - # don't touch /etc/mtab if it is a symlink to /proc/self/mounts - if [[ -L /etc/mtab ]]; then - : - elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab - else - cat /proc/mounts >| /etc/mtab - fi +# don't touch /etc/mtab if it is a symlink to /proc/self/mounts +if [[ -L /etc/mtab ]]; then + : +elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab +else + cat /proc/mounts >| /etc/mtab +fi - # now mount all the local filesystems +# now mount all the local filesystems mount_all # enable monitoring of lvm2 groups, now that the filesystems are mounted rw @@ -254,7 +253,7 @@ stat_busy "Removing Leftover Files" ln -s /run/daemons /var/run/daemons install -Tm 0664 -o root -g utmp <(:) /var/run/utmp # Keep {x,k,g}dm happy with xorg - mkdir -m1777 /tmp/.{X11,ICE}-unix + mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done if [[ $HOSTNAME ]]; then -- cgit v1.2.3