[arch-projects] [PATCH 0/7] Bash cleanup and migration away from net-tools
Hi all, Hoping to get some movement on this list started early, so I'm peeling off some patches from my git tree that I've had sitting around for a while. The first 6 are rudimentary cleanup -- they don't try to affect functionality, but rather are meant to clean inconsistant or questionable syntax used, as well as possibly shave off a few CPU cycles here and there. The final patch is a little more controversial and proposes to remove the decade old net-tools from the network service. This is a fairly straightforward change that was patched in a similar manner several years ago by James Raynor (iphitus), in response to FS #10160 which was eventually closed as "deferred". For the uninitiated, net-tools still uses the old deprecated ioctl kernel interface for getting/setting network data. While I'm not convinced that this interface will ever go away, it seems reasonable to me to switch to iproute2 which uses netlink sockets to communicate with the kernel. We can leave net-tools available, but imo we should make an effort to eventually move it from core and into extra. To that extent, there's a few of changes we'll need to make elsewhere that I'll outline: 1) net-tools currently provides /bin/hostname. coreutils can provide this as well -- we just need to enable it in ./configure. 2) Move yp-tools into core. With the above, coreutils' hostname util does not have a facility to set a nis/yp domainname. yp-tools provides this in /bin/domainname which needs to be enabled in ./configure. I'll further suggest that we create the same symlinks net-tools provides to /bin/domainname to ease the transition. 3) In conjunction with the above changes, we'll of course need to change net-tools to not provide /bin/{host,{nis,yp,}domain}name. This last patch really is more of an RFC, and I'm just looking to get the ball rolling. I realize this would be a significant change and should not be taken lightly. Regards, dave
* adhere to a consistant vim modeline * use top-right/bottom-left braces for functions Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 207 ++++++++++++++-------------- network | 445 +++++++++++++++++++++++++++++------------------------------ rc.multi | 12 +- rc.shutdown | 12 +- rc.single | 14 +- rc.sysinit | 40 +++--- 6 files changed, 359 insertions(+), 371 deletions(-) diff --git a/functions b/functions index 909b756..090f099 100644 --- a/functions +++ b/functions @@ -6,20 +6,20 @@ STAT_COL=80 if [[ ! -t 1 ]]; then - USECOLOR="" + USECOLOR="" elif [[ -t 0 ]]; then - # stty will fail when stdin isn't a terminal - STAT_COL="$(/bin/stty size)" - # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" + # stty will fail when stdin isn't a terminal + STAT_COL="$(/bin/stty size)" + # stty gives "rows cols"; strip the rows number, we just want columns + STAT_COL="${STAT_COL##* }" elif /bin/tput cols &>/dev/null; then - # is /usr/share/terminfo already mounted, and TERM recognized? - STAT_COL=$(/bin/tput cols) + # is /usr/share/terminfo already mounted, and TERM recognized? + STAT_COL=$(/bin/tput cols) fi if ((STAT_COL==0)); then - # if output was 0 (serial console), set default width to 80 - STAT_COL=80 - USECOLOR="" + # if output was 0 (serial console), set default width to 80 + STAT_COL=80 + USECOLOR="" fi # we use 13 characters for our own stuff @@ -28,11 +28,11 @@ STAT_COL=$(($STAT_COL - 13)) # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" if (($? != 3)); then - case $TERM_COLORS in - *[!0-9]*) USECOLOR="";; - [0-7]) USECOLOR="";; - '') USECOLOR="";; - esac + case $TERM_COLORS in + *[!0-9]*) USECOLOR="";; + [0-7]) USECOLOR="";; + '') USECOLOR="";; + esac fi unset TERM_COLORS @@ -146,13 +146,13 @@ status() { # 1 - not found # Copied from makepkg in_array() { - [[ $2 ]] || return 1 - local needle=$1; shift - local item - for item in "$@"; do - [[ ${item#@} = $needle ]] && return 0 - done - return 1 # Not Found + [[ $2 ]] || return 1 + local needle=$1; shift + local item + for item in "$@"; do + [[ ${item#@} = $needle ]] && return 0 + done + return 1 # Not Found } # daemons: @@ -171,17 +171,17 @@ ck_daemon() { } have_daemon() { - [[ -x /etc/rc.d/$1 ]] + [[ -x /etc/rc.d/$1 ]] } start_daemon() { - have_daemon "$1" && /etc/rc.d/"$1" start + have_daemon "$1" && /etc/rc.d/"$1" start } ck_depends() { - for daemon in "$@"; do - ck_daemon "$daemon" && start_daemon "$daemon" - done + for daemon in "$@"; do + ck_daemon "$daemon" && start_daemon "$daemon" + done } start_daemon_bkgd() { @@ -195,64 +195,64 @@ stop_daemon() { # Status functions status_started() { - deltext - echo -ne "$C_OTHER[${C_STRT}STARTED$C_OTHER]$C_CLEAR " + deltext + echo -ne "$C_OTHER[${C_STRT}STARTED$C_OTHER]$C_CLEAR " } status_stopped() { - deltext - echo -ne "$C_OTHER[${C_STRT}STOPPED$C_OTHER]$C_CLEAR " + deltext + echo -ne "$C_OTHER[${C_STRT}STOPPED$C_OTHER]$C_CLEAR " } ck_status() { - if ! ck_daemon "$1"; then - status_started - else - status_stopped - fi + if ! ck_daemon "$1"; then + status_started + else + status_stopped + fi } kill_everything() { - # $1 = where we are being called from. - # This is used to determine which hooks to run. - # Find daemons NOT in the DAEMONS array. Shut these down first - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} - in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" - 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]#@} - done + # $1 = where we are being called from. + # This is used to determine which hooks to run. + # Find daemons NOT in the DAEMONS array. Shut these down first + for daemon in /var/run/daemons/*; do + [[ -f $daemon ]] || continue + daemon=${daemon##*/} + in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + 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]#@} + done # Terminate all processes - stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" - /sbin/killall5 -15 &> /dev/null - /bin/sleep 5 - stat_done - - stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 &> /dev/null - /bin/sleep 1 - stat_done - - run_hook "$1_postkillall" + stat_busy "Sending SIGTERM To Processes" + run_hook "$1_prekillall" + /sbin/killall5 -15 &> /dev/null + /bin/sleep 5 + stat_done + + stat_busy "Sending SIGKILL To Processes" + /sbin/killall5 -9 &> /dev/null + /bin/sleep 1 + stat_done + + run_hook "$1_postkillall" } activate_vgs() { - [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]] || return - # Kernel 2.6.x, LVM2 groups - /sbin/modprobe -q dm-mod 2>/dev/null - stat_busy "Activating LVM2 groups" - if /sbin/vgchange --sysinit -a y >/dev/null; then - stat_done - else - stat_fail - fi + [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]] || return + # Kernel 2.6.x, LVM2 groups + /sbin/modprobe -q dm-mod 2>/dev/null + stat_busy "Activating LVM2 groups" + if /sbin/vgchange --sysinit -a y >/dev/null; then + stat_done + else + stat_fail + fi } # Arch cryptsetup packages traditionally contained the binaries @@ -262,23 +262,23 @@ activate_vgs() { # Newer packages will only have /sbin/cryptsetup and no static binary # This ensures maximal compatibility with the old and new layout for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ - /sbin/cryptsetup.static ''; do - [[ -x $CS ]] && break + /sbin/cryptsetup.static ''; do + [[ -x $CS ]] && break done 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 - eval nspo=("${line%#*}") - if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then - crypto_unlocked=1 - else - failed=1 - fi - done < /etc/crypttab - return $failed + # $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 + eval nspo=("${line%#*}") + if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then + crypto_unlocked=1 + else + failed=1 + fi + done < /etc/crypttab + return $failed } ############################### @@ -338,31 +338,30 @@ fi # Function for setting console font if required set_consolefont() { - [[ $CONSOLEFONT ]] || return 0 - stat_busy "Loading Console Font: $CONSOLEFONT" - #CONSOLEMAP in UTF-8 shouldn't be used - [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" - for i in /dev/tty[0-9]*; do - /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} >/dev/null 2>&1 - done - if (($? != 0)); then - stat_fail - elif [[ $CONSOLEMAP ]]; then - cat <<"EOF" >>/etc/profile.d/locale.sh + [[ $CONSOLEFONT ]] || return 0 + stat_busy "Loading Console Font: $CONSOLEFONT" + #CONSOLEMAP in UTF-8 shouldn't be used + [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" + for i in /dev/tty[0-9]*; do + /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + $CONSOLEFONT -C ${i} >/dev/null 2>&1 + done + if (($? != 0)); then + stat_fail + elif [[ $CONSOLEMAP ]]; then + cat <<"EOF" >>/etc/profile.d/locale.sh if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi - EOF - stat_done - else - stat_done - fi + stat_done + else + stat_done + fi } # Source additional functions at the end to allow overrides for f in /etc/rc.d/functions.d/*; do - [[ -e $f ]] && . "$f" + [[ -e $f ]] && . "$f" done # End of file -# vim: set ft=sh sw=2 ts=2 et: +# vim: set ts=2 sw=2 noet: diff --git a/network b/network index 4cd45d7..2065dfc 100755 --- a/network +++ b/network @@ -4,261 +4,250 @@ . /etc/rc.d/functions for s in wireless bonding bridges dhcpcd; do - [[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s" + [[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s" done -ifup() -{ - if [[ ! $1 ]]; then - echo "usage: $0 ifup <interface_name>" - return 1 - fi - eval ifcfg="\$${1}" - - # Get the name of the interface from the first token in the string - if [[ $ifcfg = dhcp ]]; then - ifname=$1 - else - ifname=${ifcfg%% *} - fi - - /sbin/ifconfig $ifname up - - wi_up $1 || return 1 - - if [[ $ifcfg = dhcp ]]; then - # remove the .pid file if it exists - /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1 - /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1 - /sbin/dhcpcd $DHCPCD_ARGS ${1} - else - /sbin/ifconfig $ifcfg - fi +ifup() { + if [[ ! $1 ]]; then + echo "usage: $0 ifup <interface_name>" + return 1 + fi + eval ifcfg="\$${1}" + + # Get the name of the interface from the first token in the string + if [[ $ifcfg = dhcp ]]; then + ifname=$1 + else + ifname=${ifcfg%% *} + fi + + /sbin/ifconfig $ifname up + + wi_up $1 || return 1 + + if [[ $ifcfg = dhcp ]]; then + # remove the .pid file if it exists + /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1 + /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1 + /sbin/dhcpcd $DHCPCD_ARGS ${1} + else + /sbin/ifconfig $ifcfg + fi } -wi_up() -{ - eval iwcfg="\$wlan_${1}" - [[ ! $iwcfg ]] && return 0 +wi_up() { + eval iwcfg="\$wlan_${1}" + [[ ! $iwcfg ]] && return 0 - /usr/sbin/iwconfig $iwcfg - [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 - sleep $WIRELESS_TIMEOUT + /usr/sbin/iwconfig $iwcfg + [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 + sleep $WIRELESS_TIMEOUT - bssid=$(iwgetid $1 -ra) - 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 - return 0 + bssid=$(iwgetid $1 -ra) + 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 + return 0 } -ifdown() -{ - if [[ ! $1 ]]; then - echo "usage: $0 ifdown <interface_name>" - return 1 - fi - eval ifcfg="\$${1}" - if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then - /sbin/dhcpcd -k ${1} >/dev/null 2>&1 - fi - # Always bring the interface itself down - /sbin/ifconfig ${1} down >/dev/null 2>&1 +ifdown() { + if [[ ! $1 ]]; then + echo "usage: $0 ifdown <interface_name>" + return 1 + fi + eval ifcfg="\$${1}" + if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then + /sbin/dhcpcd -k ${1} >/dev/null 2>&1 + fi + # Always bring the interface itself down + /sbin/ifconfig ${1} down >/dev/null 2>&1 } -iflist() -{ - for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - printf " $ifline:\t" - else - printf "$ifline:\t" - fi - eval real_ifline=\$${ifline#!} - echo $real_ifline - done +iflist() { + for ifline in ${INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + printf " $ifline:\t" + else + printf "$ifline:\t" + fi + eval real_ifline=\$${ifline#!} + echo $real_ifline + done } -rtup() -{ - if [[ ! $1 ]]; then - echo "usage: $0 rtup <route_name>" - return 1 - fi - eval routecfg="\$${1}" - if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 add $routecfg - else - /sbin/route add $routecfg - fi +rtup() { + if [[ ! $1 ]]; then + echo "usage: $0 rtup <route_name>" + return 1 + fi + eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then + /sbin/route -A inet6 add $routecfg + else + /sbin/route add $routecfg + fi } -rtdown() -{ - if [[ ! $1 ]]; then - echo "usage: $0 rtdown <route_name>" - return 1 - fi - eval routecfg="\$${1}" - if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 del $routecfg - else - /sbin/route del $routecfg - fi +rtdown() { + if [[ ! $1 ]]; then + echo "usage: $0 rtdown <route_name>" + return 1 + fi + eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then + /sbin/route -A inet6 del $routecfg + else + /sbin/route del $routecfg + fi } -rtlist() -{ - for rtline in ${ROUTES[@]}; do - if [[ $rtline = ${rtline#!} ]]; then - printf " $rtline:\t" - else - printf "$rtline:\t" - fi - eval real_rtline=\$${rtline#!} - echo $real_rtline - done +rtlist() { + for rtline in ${ROUTES[@]}; do + if [[ $rtline = ${rtline#!} ]]; then + printf " $rtline:\t" + else + printf "$rtline:\t" + fi + eval real_rtline=\$${rtline#!} + echo $real_rtline + done } -bond_up() -{ - for ifline in ${BOND_INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - if [[ ${bondcfg} ]]; then - /sbin/ifenslave $ifline $bondcfg || error=1 - fi - fi - done +bond_up() { + for ifline in ${BOND_INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + eval bondcfg="\$bond_${ifline}" + if [[ ${bondcfg} ]]; then + /sbin/ifenslave $ifline $bondcfg || error=1 + fi + fi + done } -bond_down() -{ - for ifline in ${BOND_INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave -d $ifline $bondcfg || error=1 - fi - done +bond_down() { + for ifline in ${BOND_INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + eval bondcfg="\$bond_${ifline}" + /sbin/ifenslave -d $ifline $bondcfg || error=1 + fi + done } -bridge_up() -{ - 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 - /sbin/ifconfig $br down - /usr/sbin/brctl delbr $br - fi - /usr/sbin/brctl addbr $br - eval brifs="\$bridge_${br}" - for brif in $brifs; do - if [[ $brif = ${brif#!} ]]; then - for ifline in ${BOND_INTERFACES[@]}; do - if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then - ifup $ifline - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave $ifline $bondcfg || error=1 - unset bond_${ifline} - fi - done - - /usr/sbin/brctl addif $br $brif || error=1 - fi - done - fi - done +bridge_up() { + 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 + /sbin/ifconfig $br down + /usr/sbin/brctl delbr $br + fi + /usr/sbin/brctl addbr $br + eval brifs="\$bridge_${br}" + for brif in $brifs; do + if [[ $brif = ${brif#!} ]]; then + for ifline in ${BOND_INTERFACES[@]}; do + if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then + ifup $ifline + eval bondcfg="\$bond_${ifline}" + /sbin/ifenslave $ifline $bondcfg || error=1 + unset bond_${ifline} + fi + done + + /usr/sbin/brctl addif $br $brif || error=1 + fi + done + fi + done } -bridge_down() -{ - for br in ${BRIDGE_INTERFACES[@]}; do - if [[ $br = ${br#!} ]]; then - /usr/sbin/brctl delbr $br - fi - done +bridge_down() { + for br in ${BRIDGE_INTERFACES[@]}; do + if [[ $br = ${br#!} ]]; then + /usr/sbin/brctl delbr $br + fi + done } case "$1" in - start) - if ! ck_daemon network; then - echo "Network is already running. Try 'network restart'" - exit - fi - - stat_busy "Starting Network" - error=0 - # bring up bridge interfaces - bridge_up - # bring up ethernet interfaces - for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - ifup $ifline || error=1 - fi - done - # bring up bond interfaces - bond_up - # bring up routes - for rtline in "${ROUTES[@]}"; do - if [ "$rtline" = "${rtline#!}" ]; then - rtup $rtline || error=1 - fi - done - if ((error == 0)); then - add_daemon network - stat_done - else - stat_fail - fi - ;; - stop) - #if ck_daemon network; then - # echo "Network is not running. Try 'network start'" - # exit - #fi - - if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then - status "Skipping Network Shutdown" true - exit 0 - fi - - stat_busy "Stopping Network" - rm_daemon network - error=0 - 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 - if [[ $ifline = ${ifline#!} ]]; then - ifdown $ifline || error=1 - fi - done - # bring down bridge interfaces - bridge_down - if ((error == 0)); then - stat_done - else - stat_fail - fi - ;; - restart) - $0 stop - /bin/sleep 2 - $0 start - ;; - ifup|ifdown|iflist|rtup|rtdown|rtlist) - $1 $2 - ;; - *) - echo "usage: $0 {start|stop|restart}" - echo " $0 {ifup|ifdown|iflist|rtup|rtdown|rtlist}";; + start) + if ! ck_daemon network; then + echo "Network is already running. Try 'network restart'" + exit + fi + + stat_busy "Starting Network" + error=0 + # bring up bridge interfaces + bridge_up + # bring up ethernet interfaces + for ifline in ${INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + ifup $ifline || error=1 + fi + done + # bring up bond interfaces + bond_up + # bring up routes + for rtline in "${ROUTES[@]}"; do + if [ "$rtline" = "${rtline#!}" ]; then + rtup $rtline || error=1 + fi + done + if ((error == 0)); then + add_daemon network + stat_done + else + stat_fail + fi + ;; + stop) + #if ck_daemon network; then + # echo "Network is not running. Try 'network start'" + # exit + #fi + + if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then + status "Skipping Network Shutdown" true + exit 0 + fi + + stat_busy "Stopping Network" + rm_daemon network + error=0 + 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 + if [[ $ifline = ${ifline#!} ]]; then + ifdown $ifline || error=1 + fi + done + # bring down bridge interfaces + bridge_down + if ((error == 0)); then + stat_done + else + stat_fail + fi + ;; + restart) + $0 stop + /bin/sleep 2 + $0 start + ;; + ifup|ifdown|iflist|rtup|rtdown|rtlist) + $1 $2 + ;; + *) + echo "usage: $0 {start|stop|restart}" + echo " $0 {ifup|ifdown|iflist|rtup|rtdown|rtlist}";; esac -# vim: set ts=4 sw=4 noet: +# vim: set ts=2 sw=2 noet: diff --git a/rc.multi b/rc.multi index 660f649..693223d 100755 --- a/rc.multi +++ b/rc.multi @@ -13,11 +13,11 @@ run_hook multi_start # Start daemons for daemon in "${DAEMONS[@]}"; do - case ${daemon:0:1} in - '!') continue;; # Skip this daemon. - '@') start_daemon_bkgd "${daemon#@}";; - *) start_daemon "$daemon";; - esac + case ${daemon:0:1} in + '!') continue;; # Skip this daemon. + '@') start_daemon_bkgd "${daemon#@}";; + *) start_daemon "$daemon";; + esac done if [[ -x /etc/rc.local ]]; then @@ -26,4 +26,4 @@ fi run_hook multi_end -# vim: set ts=2 noet: +# vim: set ts=2 sw=2 noet: diff --git a/rc.shutdown b/rc.shutdown index 0acca49..499459f 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -43,9 +43,9 @@ fi HWCLOCK_PARAMS="--systohc" case $HARDWARECLOCK in - UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; - *) HWCLOCK_PARAMS="";; + UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; + localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + *) HWCLOCK_PARAMS="";; esac [[ $HWCLOCK_PARAMS ]] && /sbin/hwclock $HWCLOCK_PARAMS stat_done @@ -87,9 +87,9 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then fi if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then - stat_busy "Deactivating LVM2 groups" - /sbin/vgchange --sysinit -a n >/dev/null 2>&1 - stat_done + stat_busy "Deactivating LVM2 groups" + /sbin/vgchange --sysinit -a n >/dev/null 2>&1 + stat_done fi stat_busy "Remounting Root Filesystem Read-only" diff --git a/rc.single b/rc.single index 4d22cf1..2420873 100755 --- a/rc.single +++ b/rc.single @@ -9,7 +9,7 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then - kill_everything single + kill_everything single stat_busy "Starting UDev Daemon" /sbin/udevd --daemon stat_done @@ -18,11 +18,11 @@ if [[ $PREVLEVEL != N ]]; then # 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 --action=add --type=devices - /sbin/udevadm trigger --action=add --type=subsystems - stat_done + stat_busy "Triggering UDev uevents" + /sbin/udevadm control --property=STARTUP=1 + /sbin/udevadm trigger --action=add --type=devices + /sbin/udevadm trigger --action=add --type=subsystems + stat_done fi # Wait for udev uevents @@ -55,4 +55,4 @@ if [[ $RUNLEVEL = 1 ]]; then fi # End of file -# vim: set ts=2 noet: +# vim: set ts=2 sw=2 noet: diff --git a/rc.sysinit b/rc.sysinit index 9797611..cd74db4 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -21,11 +21,11 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" /bin/mountpoint -q /sys || /bin/mount -n -t sysfs sysfs /sys -o nosuid,noexec,nodev if ! /bin/mountpoint -q /dev; then - if grep -q devtmpfs /proc/filesystems 2>/dev/null; then - /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid - else - /bin/mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid - fi + if grep -q devtmpfs /proc/filesystems 2>/dev/null; then + /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid + else + /bin/mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid + fi fi # start up our mini logger until syslog takes over @@ -41,9 +41,9 @@ fi HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in - UTC) HWCLOCK_PARAMS+=" --utc";; - localtime) HWCLOCK_PARAMS+=" --localtime";; - *) HWCLOCK_PARAMS="";; + UTC) HWCLOCK_PARAMS+=" --utc";; + localtime) HWCLOCK_PARAMS+=" --localtime";; + *) HWCLOCK_PARAMS="";; esac if [[ $HWCLOCK_PARAMS ]]; then @@ -52,11 +52,11 @@ if [[ $HWCLOCK_PARAMS ]]; then # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor - done + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do + [[ -e $dev ]] || continue + IFS=: read -r major minor < "$dev" + /bin/mknod /dev/rtc c $major $minor + done fi # Do a clock set here for a few reasons: @@ -82,11 +82,11 @@ 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 --action=add --type=devices - /sbin/udevadm trigger --action=add --type=subsystems - stat_done + stat_busy "Triggering UDev uevents" + /sbin/udevadm control --property=STARTUP=1 + /sbin/udevadm trigger --action=add --type=devices + /sbin/udevadm trigger --action=add --type=subsystems + stat_done fi # Load modules from the MODULES array defined in rc.conf @@ -319,8 +319,8 @@ if [[ $HWCLOCK_PARAMS ]]; then # take ~1 second because of the clock granularity, and we might as well # stay busy. ( - /sbin/hwclock --adjust - /sbin/hwclock $HWCLOCK_PARAMS + /sbin/hwclock --adjust + /sbin/hwclock $HWCLOCK_PARAMS ) & clock_pid=$! fi -- 1.7.4.1
On Saturday 26 March 2011 16:31:57 Dave Reisner wrote:
* adhere to a consistant vim modeline * use top-right/bottom-left braces for functions
Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 207 ++++++++++++++-------------- network | 445 +++++++++++++++++++++++++++++------------------------------ rc.multi | 12 +- rc.shutdown | 12 +- rc.single | 14 +- rc.sysinit | 40 +++--- 6 files changed, 359 insertions(+), 371 deletions(-)
[...]
-ifdown() -{ - if [[ ! $1 ]]; then - echo "usage: $0 ifdown <interface_name>" - return 1 - fi - eval ifcfg="\$${1}" - if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then - /sbin/dhcpcd -k ${1} >/dev/null 2>&1 - fi - # Always bring the interface itself down - /sbin/ifconfig ${1} down >/dev/null 2>&1 +ifdown() { + if [[ ! $1 ]]; then + echo "usage: $0 ifdown <interface_name>" + return 1 + fi + eval ifcfg="\$${1}" + if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then + /sbin/dhcpcd -k ${1} >/dev/null 2>&1
Here you introduced a whitespace error at the end of the line. In general: Any reason why the vim modeline was not added to all the files (netfs/minilog.c)? I guess someone might complain that this will cause lots of conflicts if they have lots of pending patches, except for that it looked fine by me. Cheers, Tom
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.single | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.single b/rc.single index 2420873..aab2b58 100755 --- a/rc.single +++ b/rc.single @@ -50,7 +50,7 @@ if [[ $RUNLEVEL = 1 ]]; then printsep printhl "Entering single-user mode..." # make sure /dev/initctl is in place - /bin/kill -HUP 1 + kill -HUP 1 exec /sbin/init -t1 S fi -- 1.7.4.1
On Saturday 26 March 2011 16:31:58 Dave Reisner wrote:
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.single | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.single b/rc.single index 2420873..aab2b58 100755 --- a/rc.single +++ b/rc.single @@ -50,7 +50,7 @@ if [[ $RUNLEVEL = 1 ]]; then printsep printhl "Entering single-user mode..." # make sure /dev/initctl is in place - /bin/kill -HUP 1 + kill -HUP 1 exec /sbin/init -t1 S fi
Looks fine to me. -t
On Sat, Mar 26, 2011 at 11:14 PM, Tom Gundersen <teg@jklm.no> wrote:
On Saturday 26 March 2011 16:31:58 Dave Reisner wrote:
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.single | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.single b/rc.single index 2420873..aab2b58 100755 --- a/rc.single +++ b/rc.single @@ -50,7 +50,7 @@ if [[ $RUNLEVEL = 1 ]]; then printsep printhl "Entering single-user mode..." # make sure /dev/initctl is in place - /bin/kill -HUP 1 + kill -HUP 1 exec /sbin/init -t1 S fi
Looks fine to me.
me too. -- Sébastien Luttringer www.seblu.net
* replace use of eval with variable indirection * scope variables to functions Signed-off-by: Dave Reisner <d@falconindy.com> --- network | 48 +++++++++++++++++++++++++++--------------------- 1 files changed, 27 insertions(+), 21 deletions(-) diff --git a/network b/network index 2065dfc..5a261b4 100755 --- a/network +++ b/network @@ -8,11 +8,12 @@ for s in wireless bonding bridges dhcpcd; do done ifup() { + local ifcfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 ifup <interface_name>" return 1 fi - eval ifcfg="\$${1}" # Get the name of the interface from the first token in the string if [[ $ifcfg = dhcp ]]; then @@ -36,10 +37,11 @@ ifup() { } wi_up() { - eval iwcfg="\$wlan_${1}" - [[ ! $iwcfg ]] && return 0 + local iwcfg=wlan_$1 + + [[ ${!iwcfg} ]] || return 0 - /usr/sbin/iwconfig $iwcfg + /usr/sbin/iwconfig ${!iwcfg} [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 sleep $WIRELESS_TIMEOUT @@ -52,11 +54,13 @@ wi_up() { } ifdown() { + local ifcfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 ifdown <interface_name>" return 1 fi - eval ifcfg="\$${1}" + if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then /sbin/dhcpcd -k ${1} >/dev/null 2>&1 fi @@ -71,17 +75,18 @@ iflist() { else printf "$ifline:\t" fi - eval real_ifline=\$${ifline#!} - echo $real_ifline + echo ${!ifline#!} done } rtup() { + local routecfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 rtup <route_name>" return 1 fi - eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 add $routecfg else @@ -90,11 +95,13 @@ rtup() { } rtdown() { + local routecfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 rtdown <route_name>" return 1 fi - eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 del $routecfg else @@ -109,17 +116,16 @@ rtlist() { else printf "$rtline:\t" fi - eval real_rtline=\$${rtline#!} - echo $real_rtline + echo ${!rtline#!} done } bond_up() { for ifline in ${BOND_INTERFACES[@]}; do if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - if [[ ${bondcfg} ]]; then - /sbin/ifenslave $ifline $bondcfg || error=1 + bondcfg="bond_$ifline" + if [[ ${!bondcfg} ]]; then + /sbin/ifenslave $ifline ${!bondcfg} || error=1 fi fi done @@ -128,8 +134,8 @@ bond_up() { bond_down() { for ifline in ${BOND_INTERFACES[@]}; do if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave -d $ifline $bondcfg || error=1 + bondcfg="bond_$ifline" + /sbin/ifenslave -d $ifline ${!bondcfg} || error=1 fi done } @@ -143,15 +149,15 @@ bridge_up() { /usr/sbin/brctl delbr $br fi /usr/sbin/brctl addbr $br - eval brifs="\$bridge_${br}" - for brif in $brifs; do + brifs="bridge_$br" + for brif in ${!brifs}; do if [[ $brif = ${brif#!} ]]; then for ifline in ${BOND_INTERFACES[@]}; do if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then ifup $ifline - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave $ifline $bondcfg || error=1 - unset bond_${ifline} + bondcfg="bond_$ifline" + /sbin/ifenslave $ifline ${!bondcfg} || error=1 + unset bond_$ifline fi done -- 1.7.4.1
On Saturday 26 March 2011 16:31:59 Dave Reisner wrote:
* replace use of eval with variable indirection * scope variables to functions
Signed-off-by: Dave Reisner <d@falconindy.com> --- network | 48 +++++++++++++++++++++++++++--------------------- 1 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/network b/network index 2065dfc..5a261b4 100755 --- a/network +++ b/network @@ -8,11 +8,12 @@ for s in wireless bonding bridges dhcpcd; do done
ifup() { + local ifcfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 ifup <interface_name>" return 1 fi - eval ifcfg="\$${1}"
# Get the name of the interface from the first token in the string if [[ $ifcfg = dhcp ]]; then @@ -36,10 +37,11 @@ ifup() { }
wi_up() { - eval iwcfg="\$wlan_${1}" - [[ ! $iwcfg ]] && return 0 + local iwcfg=wlan_$1 + + [[ ${!iwcfg} ]] || return 0
- /usr/sbin/iwconfig $iwcfg + /usr/sbin/iwconfig ${!iwcfg} [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 sleep $WIRELESS_TIMEOUT
@@ -52,11 +54,13 @@ wi_up() { }
ifdown() { + local ifcfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 ifdown <interface_name>" return 1 fi - eval ifcfg="\$${1}" + if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then /sbin/dhcpcd -k ${1} >/dev/null 2>&1 fi @@ -71,17 +75,18 @@ iflist() { else printf "$ifline:\t" fi - eval real_ifline=\$${ifline#!} - echo $real_ifline + echo ${!ifline#!} done }
rtup() { + local routecfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 rtup <route_name>" return 1 fi - eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 add $routecfg else @@ -90,11 +95,13 @@ rtup() { }
rtdown() { + local routecfg=${!1} + if [[ ! $1 ]]; then echo "usage: $0 rtdown <route_name>" return 1 fi - eval routecfg="\$${1}" + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 del $routecfg else @@ -109,17 +116,16 @@ rtlist() { else printf "$rtline:\t" fi - eval real_rtline=\$${rtline#!} - echo $real_rtline + echo ${!rtline#!} done }
bond_up() { for ifline in ${BOND_INTERFACES[@]}; do if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - if [[ ${bondcfg} ]]; then - /sbin/ifenslave $ifline $bondcfg || error=1 + bondcfg="bond_$ifline" + if [[ ${!bondcfg} ]]; then + /sbin/ifenslave $ifline ${!bondcfg} || error=1 fi fi done @@ -128,8 +134,8 @@ bond_up() { bond_down() { for ifline in ${BOND_INTERFACES[@]}; do if [[ $ifline = ${ifline#!} ]]; then - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave -d $ifline $bondcfg || error=1 + bondcfg="bond_$ifline" + /sbin/ifenslave -d $ifline ${!bondcfg} || error=1 fi done } @@ -143,15 +149,15 @@ bridge_up() { /usr/sbin/brctl delbr $br fi /usr/sbin/brctl addbr $br - eval brifs="\$bridge_${br}" - for brif in $brifs; do + brifs="bridge_$br" + for brif in ${!brifs}; do if [[ $brif = ${brif#!} ]]; then for ifline in ${BOND_INTERFACES[@]}; do if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then ifup $ifline - eval bondcfg="\$bond_${ifline}" - /sbin/ifenslave $ifline $bondcfg || error=1 - unset bond_${ifline} + bondcfg="bond_$ifline" + /sbin/ifenslave $ifline ${!bondcfg} || error=1 + unset bond_$ifline fi done
Looks fine to me, and I trust your judgement of what bashisms are the best ones... -t
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.sysinit | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index cd74db4..3d0eb02 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -334,11 +334,8 @@ 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 -f /etc/{nologin,shutdownpid} /var/lock/* /forcefsck &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null -/bin/rm -f /forcefsck &>/dev/null [[ -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp -- 1.7.4.1
On Saturday 26 March 2011 16:32:00 Dave Reisner wrote:
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.sysinit | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index cd74db4..3d0eb02 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -334,11 +334,8 @@ 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 -f /etc/{nologin,shutdownpid} /var/lock/* /forcefsck &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null -/bin/rm -f /forcefsck &>/dev/null [[ -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete
: >| /var/run/utmp
/bin/chmod 0664 /var/run/utmp
Looks fine to me. -t
On Sat, Mar 26, 2011 at 11:15 PM, Tom Gundersen <teg@jklm.no> wrote:
On Saturday 26 March 2011 16:32:00 Dave Reisner wrote:
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.sysinit | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index cd74db4..3d0eb02 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -334,11 +334,8 @@ 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 -f /etc/{nologin,shutdownpid} /var/lock/* /forcefsck &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null -/bin/rm -f /forcefsck &>/dev/null [[ -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete
: >| /var/run/utmp
/bin/chmod 0664 /var/run/utmp
Looks fine to me.
me too. -- Sébastien Luttringer www.seblu.net
* checks for variable existance should not use -n or quotes * avoid using -eq, this is what arithmetic expansion is for * always quote the LHS of a [[ * always quote proper arrays expanded with @ Signed-off-by: Dave Reisner <d@falconindy.com> --- network | 40 ++++++++++++++++++++-------------------- rc.shutdown | 6 +++--- rc.single | 2 +- rc.sysinit | 18 +++++++++--------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/network b/network index 5a261b4..27df68a 100755 --- a/network +++ b/network @@ -69,7 +69,7 @@ ifdown() { } iflist() { - for ifline in ${INTERFACES[@]}; do + for ifline in "${INTERFACES[@]}"; do if [[ $ifline = ${ifline#!} ]]; then printf " $ifline:\t" else @@ -110,8 +110,8 @@ rtdown() { } rtlist() { - for rtline in ${ROUTES[@]}; do - if [[ $rtline = ${rtline#!} ]]; then + for rtline in "${ROUTES[@]}"; do + if [[ "$rtline" = ${rtline#!} ]]; then printf " $rtline:\t" else printf "$rtline:\t" @@ -121,8 +121,8 @@ rtlist() { } bond_up() { - for ifline in ${BOND_INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then + for ifline in "${BOND_INTERFACES[@]}"; do + if [[ "$ifline" = ${ifline#!} ]]; then bondcfg="bond_$ifline" if [[ ${!bondcfg} ]]; then /sbin/ifenslave $ifline ${!bondcfg} || error=1 @@ -132,8 +132,8 @@ bond_up() { } bond_down() { - for ifline in ${BOND_INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then + for ifline in "${BOND_INTERFACES[@]}"; do + if [[ "$ifline" = ${ifline#!} ]]; then bondcfg="bond_$ifline" /sbin/ifenslave -d $ifline ${!bondcfg} || error=1 fi @@ -141,8 +141,8 @@ bond_down() { } bridge_up() { - for br in ${BRIDGE_INTERFACES[@]}; do - if [[ $br = ${br#!} ]]; then + 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 /sbin/ifconfig $br down @@ -151,9 +151,9 @@ bridge_up() { /usr/sbin/brctl addbr $br brifs="bridge_$br" for brif in ${!brifs}; do - if [[ $brif = ${brif#!} ]]; then + if [[ "$brif" = ${brif#!} ]]; then for ifline in ${BOND_INTERFACES[@]}; do - if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then + if [[ "$brif" = $ifline && "$ifline" = ${ifline#!} ]]; then ifup $ifline bondcfg="bond_$ifline" /sbin/ifenslave $ifline ${!bondcfg} || error=1 @@ -169,8 +169,8 @@ bridge_up() { } bridge_down() { - for br in ${BRIDGE_INTERFACES[@]}; do - if [[ $br = ${br#!} ]]; then + for br in "${BRIDGE_INTERFACES[@]}"; do + if [[ "$br" = ${br#!} ]]; then /usr/sbin/brctl delbr $br fi done @@ -189,8 +189,8 @@ case "$1" in # bring up bridge interfaces bridge_up # bring up ethernet interfaces - for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then + for ifline in "${INTERFACES[@]}"; do + if [[ "$ifline" = ${ifline#!} ]]; then ifup $ifline || error=1 fi done @@ -198,7 +198,7 @@ case "$1" in bond_up # bring up routes for rtline in "${ROUTES[@]}"; do - if [ "$rtline" = "${rtline#!}" ]; then + if [[ "$rtline" = ${rtline#!} ]]; then rtup $rtline || error=1 fi done @@ -215,7 +215,7 @@ case "$1" in # exit #fi - if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then + if [[ "$NETWORK_PERSIST" =~ yes|YES && "$RUNLEVEL" = [06] ]]; then status "Skipping Network Shutdown" true exit 0 fi @@ -224,20 +224,20 @@ case "$1" in rm_daemon network error=0 for rtline in "${ROUTES[@]}"; do - if [[ $rtline = ${rtline#!} ]]; then + if [[ "$rtline" = ${rtline#!} ]]; then rtdown $rtline || error=1 fi done # bring down bond interfaces bond_down for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then + if [[ "$ifline" = ${ifline#!} ]]; then ifdown $ifline || error=1 fi done # bring down bridge interfaces bridge_down - if ((error == 0)); then + if (( error == 0 )); then stat_done else stat_fail diff --git a/rc.shutdown b/rc.shutdown index 499459f..9a04014 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -61,7 +61,7 @@ stat_busy "Deactivating Swap" stat_done # stop monitoring of lvm2 groups before unmounting filesystems -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating monitoring of LVM2 groups" /sbin/vgchange --monitor n >/dev/null 2>&1 stat_done @@ -86,7 +86,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then stat_done fi -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating LVM2 groups" /sbin/vgchange --sysinit -a n >/dev/null 2>&1 stat_done @@ -100,7 +100,7 @@ run_hook shutdown_poweroff # Power off or reboot printsep -if [[ $RUNLEVEL = 0 ]]; then +if (( RUNLEVEL == 0 )); then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i else diff --git a/rc.single b/rc.single index aab2b58..de50a47 100755 --- a/rc.single +++ b/rc.single @@ -46,7 +46,7 @@ fi run_hook single_end -if [[ $RUNLEVEL = 1 ]]; then +if (( RUNLEVEL == 1 )); then printsep printhl "Entering single-user mode..." # make sure /dev/initctl is in place diff --git a/rc.sysinit b/rc.sysinit index 3d0eb02..b08d927 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -33,7 +33,7 @@ fi # anything more serious than KERN_WARNING goes to the console # 'verbose' cmdline parameter enables more messages -if [[ -n "$verbose" ]]; then +if [[ $verbose ]]; then /bin/dmesg -n 8 else /bin/dmesg -n 3 @@ -162,11 +162,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/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. /sbin/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.." @@ -204,7 +204,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then *) echo "$3" | $CS $4 $open "$a" "$b" >/dev/null;; esac - if (($? != 0)); then + if (( $? != 0 )); then failed=1 stat_append "failed " else @@ -218,7 +218,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/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 @@ -246,11 +246,11 @@ if [[ -x /sbin/fsck ]]; then run_hook sysinit_prefsck /sbin/fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR fsckret=$? - if ((fsckret > 1)); then + if (( fsckret > 1 )); then stat_fail fi run_hook sysinit_postfsck - if (( ( fsckret & 2) == 2)); then + if (( (fsckret & 2) == 2 )); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -260,7 +260,7 @@ if [[ -x /sbin/fsck ]]; then echo /bin/sleep 15 fsck_reboot - elif ((fsckret > 1 && fsckret != 32)); then + elif (( fsckret > 1 && fsckret != 32 )); then echo echo "***************** FILESYSTEM CHECK FAILED ****************" echo "* *" @@ -280,7 +280,7 @@ fi stat_busy "Mounting Local Filesystems" /bin/mount -n -o remount,rw / -if [ -x /bin/findmnt -a -e /proc/self/mountinfo ]; then +if [[ -x /bin/findmnt && -e /proc/self/mountinfo ]]; then /bin/findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab else cat /proc/mounts >| /etc/mtab -- 1.7.4.1
On Saturday 26 March 2011 16:32:01 Dave Reisner wrote: > * checks for variable existance should not use -n or quotes > * avoid using -eq, this is what arithmetic expansion is for > * always quote the LHS of a [[ > * always quote proper arrays expanded with @ > > Signed-off-by: Dave Reisner <d@falconindy.com> > --- > network | 40 ++++++++++++++++++++-------------------- > rc.shutdown | 6 +++--- > rc.single | 2 +- > rc.sysinit | 18 +++++++++--------- > 4 files changed, 33 insertions(+), 33 deletions(-) > > diff --git a/network b/network > index 5a261b4..27df68a 100755 > --- a/network > +++ b/network > @@ -69,7 +69,7 @@ ifdown() { > } > > iflist() { > - for ifline in ${INTERFACES[@]}; do > + for ifline in "${INTERFACES[@]}"; do > if [[ $ifline = ${ifline#!} ]]; then > printf " $ifline:\t" > else > @@ -110,8 +110,8 @@ rtdown() { > } > > rtlist() { > - for rtline in ${ROUTES[@]}; do > - if [[ $rtline = ${rtline#!} ]]; then > + for rtline in "${ROUTES[@]}"; do > + if [[ "$rtline" = ${rtline#!} ]]; then > printf " $rtline:\t" > else > printf "$rtline:\t" > @@ -121,8 +121,8 @@ rtlist() { > } > > bond_up() { > - for ifline in ${BOND_INTERFACES[@]}; do > - if [[ $ifline = ${ifline#!} ]]; then > + for ifline in "${BOND_INTERFACES[@]}"; do > + if [[ "$ifline" = ${ifline#!} ]]; then > bondcfg="bond_$ifline" > if [[ ${!bondcfg} ]]; then > /sbin/ifenslave $ifline ${!bondcfg} || error=1 > @@ -132,8 +132,8 @@ bond_up() { > } > > bond_down() { > - for ifline in ${BOND_INTERFACES[@]}; do > - if [[ $ifline = ${ifline#!} ]]; then > + for ifline in "${BOND_INTERFACES[@]}"; do > + if [[ "$ifline" = ${ifline#!} ]]; then > bondcfg="bond_$ifline" > /sbin/ifenslave -d $ifline ${!bondcfg} || error=1 > fi > @@ -141,8 +141,8 @@ bond_down() { > } > > bridge_up() { > - for br in ${BRIDGE_INTERFACES[@]}; do > - if [[ $br = ${br#!} ]]; then > + 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 > /sbin/ifconfig $br down > @@ -151,9 +151,9 @@ bridge_up() { > /usr/sbin/brctl addbr $br > brifs="bridge_$br" > for brif in ${!brifs}; do > - if [[ $brif = ${brif#!} ]]; then > + if [[ "$brif" = ${brif#!} ]]; then > for ifline in ${BOND_INTERFACES[@]}; do > - if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then > + if [[ "$brif" = $ifline && "$ifline" = ${ifline#!} ]]; then > ifup $ifline > bondcfg="bond_$ifline" > /sbin/ifenslave $ifline ${!bondcfg} || error=1 > @@ -169,8 +169,8 @@ bridge_up() { > } > > bridge_down() { > - for br in ${BRIDGE_INTERFACES[@]}; do > - if [[ $br = ${br#!} ]]; then > + for br in "${BRIDGE_INTERFACES[@]}"; do > + if [[ "$br" = ${br#!} ]]; then > /usr/sbin/brctl delbr $br > fi > done > @@ -189,8 +189,8 @@ case "$1" in > # bring up bridge interfaces > bridge_up > # bring up ethernet interfaces > - for ifline in ${INTERFACES[@]}; do > - if [[ $ifline = ${ifline#!} ]]; then > + for ifline in "${INTERFACES[@]}"; do > + if [[ "$ifline" = ${ifline#!} ]]; then > ifup $ifline || error=1 > fi > done > @@ -198,7 +198,7 @@ case "$1" in > bond_up > # bring up routes > for rtline in "${ROUTES[@]}"; do > - if [ "$rtline" = "${rtline#!}" ]; then > + if [[ "$rtline" = ${rtline#!} ]]; then > rtup $rtline || error=1 > fi > done > @@ -215,7 +215,7 @@ case "$1" in > # exit > #fi > > - if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then > + if [[ "$NETWORK_PERSIST" =~ yes|YES && "$RUNLEVEL" = [06] ]]; then > status "Skipping Network Shutdown" true > exit 0 > fi > @@ -224,20 +224,20 @@ case "$1" in > rm_daemon network > error=0 > for rtline in "${ROUTES[@]}"; do > - if [[ $rtline = ${rtline#!} ]]; then > + if [[ "$rtline" = ${rtline#!} ]]; then > rtdown $rtline || error=1 > fi > done > # bring down bond interfaces > bond_down > for ifline in ${INTERFACES[@]}; do > - if [[ $ifline = ${ifline#!} ]]; then > + if [[ "$ifline" = ${ifline#!} ]]; then > ifdown $ifline || error=1 > fi > done > # bring down bridge interfaces > bridge_down > - if ((error == 0)); then > + if (( error == 0 )); then > stat_done > else > stat_fail > diff --git a/rc.shutdown b/rc.shutdown > index 499459f..9a04014 100755 > --- a/rc.shutdown > +++ b/rc.shutdown > @@ -61,7 +61,7 @@ stat_busy "Deactivating Swap" > stat_done > > # stop monitoring of lvm2 groups before unmounting filesystems > -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then > +if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then > stat_busy "Deactivating monitoring of LVM2 groups" > /sbin/vgchange --monitor n >/dev/null 2>&1 > stat_done > @@ -86,7 +86,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] > /etc/crypttab; then stat_done > fi > > -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then > +if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then > stat_busy "Deactivating LVM2 groups" > /sbin/vgchange --sysinit -a n >/dev/null 2>&1 > stat_done > @@ -100,7 +100,7 @@ run_hook shutdown_poweroff > > # Power off or reboot > printsep > -if [[ $RUNLEVEL = 0 ]]; then > +if (( RUNLEVEL == 0 )); then > printhl "${C_H2}POWER OFF" > /sbin/poweroff -d -f -h -i > else > diff --git a/rc.single b/rc.single > index aab2b58..de50a47 100755 > --- a/rc.single > +++ b/rc.single > @@ -46,7 +46,7 @@ fi > > run_hook single_end > > -if [[ $RUNLEVEL = 1 ]]; then > +if (( RUNLEVEL == 1 )); then > printsep > printhl "Entering single-user mode..." > # make sure /dev/initctl is in place > diff --git a/rc.sysinit b/rc.sysinit > index 3d0eb02..b08d927 100755 > --- a/rc.sysinit > +++ b/rc.sysinit > @@ -33,7 +33,7 @@ fi > > # anything more serious than KERN_WARNING goes to the console > # 'verbose' cmdline parameter enables more messages > -if [[ -n "$verbose" ]]; then > +if [[ $verbose ]]; then > /bin/dmesg -n 8 > else > /bin/dmesg -n 3 > @@ -162,11 +162,11 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/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. > /sbin/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.." > @@ -204,7 +204,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q > ^[^#] /etc/crypttab; then *) > echo "$3" | $CS $4 $open "$a" "$b" >/dev/null;; > esac > - if (($? != 0)); then > + if (( $? != 0 )); then > failed=1 > stat_append "failed " > else > @@ -218,7 +218,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/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 > @@ -246,11 +246,11 @@ if [[ -x /sbin/fsck ]]; then > run_hook sysinit_prefsck > /sbin/fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK > >$FSCK_OUT 2>$FSCK_ERR fsckret=$? > - if ((fsckret > 1)); then > + if (( fsckret > 1 )); then > stat_fail > fi > run_hook sysinit_postfsck > - if (( ( fsckret & 2) == 2)); then > + if (( (fsckret & 2) == 2 )); then > echo > echo "********************** REBOOT REQUIRED *********************" > echo "* *" > @@ -260,7 +260,7 @@ if [[ -x /sbin/fsck ]]; then > echo > /bin/sleep 15 > fsck_reboot > - elif ((fsckret > 1 && fsckret != 32)); then > + elif (( fsckret > 1 && fsckret != 32 )); then > echo > echo "***************** FILESYSTEM CHECK FAILED ****************" > echo "* *" > @@ -280,7 +280,7 @@ fi > > stat_busy "Mounting Local Filesystems" > /bin/mount -n -o remount,rw / > -if [ -x /bin/findmnt -a -e /proc/self/mountinfo ]; then > +if [[ -x /bin/findmnt && -e /proc/self/mountinfo ]]; then > /bin/findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab > else > cat /proc/mounts >| /etc/mtab Looks fine to me, and I trust your judgement of what bashisms are the best ones... -t
On Sat, Mar 26, 2011 at 9:32 PM, Dave Reisner <d@falconindy.com> wrote:
* checks for variable existance should not use -n or quotes * avoid using -eq, this is what arithmetic expansion is for * always quote the LHS of a [[ why?
* always quote proper arrays expanded with @ why too?
diff --git a/network b/network index 5a261b4..27df68a 100755 --- a/network +++ b/network @@ -69,7 +69,7 @@ ifdown() { }
iflist() { - for ifline in ${INTERFACES[@]}; do + for ifline in "${INTERFACES[@]}"; do if [[ $ifline = ${ifline#!} ]]; then here you miss quoting LHS, no?
-- Sébastien Luttringer www.seblu.net
This avoids having to use =~ for checking options and allows more tolerance for checking user input. Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.shutdown | 6 ++++-- rc.sysinit | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 9a04014..5fc682a 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions +shopt -s nocasematch + run_hook shutdown_start # avoid staircase effect @@ -61,7 +63,7 @@ stat_busy "Deactivating Swap" stat_done # stop monitoring of lvm2 groups before unmounting filesystems -if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating monitoring of LVM2 groups" /sbin/vgchange --monitor n >/dev/null 2>&1 stat_done @@ -86,7 +88,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then stat_done fi -if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating LVM2 groups" /sbin/vgchange --sysinit -a n >/dev/null 2>&1 stat_done diff --git a/rc.sysinit b/rc.sysinit index b08d927..bf2f83e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions +shopt -s nocasematch + echo " " printhl "Arch Linux\n" printhl "${C_H2}http://www.archlinux.org" @@ -113,12 +115,12 @@ run_hook sysinit_udevsettled status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up # SoftRAID devices detection -if [[ $USEMDADM =~ yes|YES && -x /sbin/mdadm ]]; then +if [[ "$USEMDADM" = yes && -x /sbin/mdadm ]]; then status "Activating SoftRAID arrays" /sbin/mdadm --assemble --scan fi # FakeRAID devices detection -if [[ $USEDMRAID =~ yes|YES && -x /sbin/dmraid ]]; then +if [[ "$USEDMRAID" = yes && -x /sbin/dmraid ]]; then status "Activating FakeRAID arrays" /sbin/dmraid -i -ay fi @@ -291,7 +293,7 @@ run_hook sysinit_premount stat_done # enable monitoring of lvm2 groups, now that the filesystems are mounted rw -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Activating monitoring of LVM2 groups" if /sbin/vgchange --monitor y >/dev/null; then stat_done @@ -366,7 +368,7 @@ stat_busy "Setting Locale: $LOCALE" echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done -if [[ ${LOCALE,,} =~ utf ]]; then +if [[ $LOCALE =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel # this code is needed not only for older kernels, -- 1.7.4.1
On Saturday 26 March 2011 16:32:02 Dave Reisner wrote:
This avoids having to use =~ for checking options and allows more tolerance for checking user input.
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.shutdown | 6 ++++-- rc.sysinit | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/rc.shutdown b/rc.shutdown index 9a04014..5fc682a 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions
+shopt -s nocasematch + run_hook shutdown_start
# avoid staircase effect @@ -61,7 +63,7 @@ stat_busy "Deactivating Swap" stat_done
# stop monitoring of lvm2 groups before unmounting filesystems -if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating monitoring of LVM2 groups" /sbin/vgchange --monitor n >/dev/null 2>&1 stat_done @@ -86,7 +88,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then stat_done fi
-if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating LVM2 groups" /sbin/vgchange --sysinit -a n >/dev/null 2>&1 stat_done diff --git a/rc.sysinit b/rc.sysinit index b08d927..bf2f83e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions
+shopt -s nocasematch + echo " " printhl "Arch Linux\n" printhl "${C_H2}http://www.archlinux.org" @@ -113,12 +115,12 @@ run_hook sysinit_udevsettled status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up
# SoftRAID devices detection -if [[ $USEMDADM =~ yes|YES && -x /sbin/mdadm ]]; then +if [[ "$USEMDADM" = yes && -x /sbin/mdadm ]]; then status "Activating SoftRAID arrays" /sbin/mdadm --assemble --scan fi
# FakeRAID devices detection -if [[ $USEDMRAID =~ yes|YES && -x /sbin/dmraid ]]; then +if [[ "$USEDMRAID" = yes && -x /sbin/dmraid ]]; then status "Activating FakeRAID arrays" /sbin/dmraid -i -ay fi
@@ -291,7 +293,7 @@ run_hook sysinit_premount stat_done
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Activating monitoring of LVM2 groups" if /sbin/vgchange --monitor y >/dev/null; then stat_done @@ -366,7 +368,7 @@ stat_busy "Setting Locale: $LOCALE" echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done
-if [[ ${LOCALE,,} =~ utf ]]; then +if [[ $LOCALE =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel # this code is needed not only for older kernels,
Looks fine to me. -t
On Sat, Mar 26, 2011 at 11:16 PM, Tom Gundersen <teg@jklm.no> wrote:
On Saturday 26 March 2011 16:32:02 Dave Reisner wrote:
This avoids having to use =~ for checking options and allows more tolerance for checking user input.
Signed-off-by: Dave Reisner <d@falconindy.com> --- rc.shutdown | 6 ++++-- rc.sysinit | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/rc.shutdown b/rc.shutdown index 9a04014..5fc682a 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions
+shopt -s nocasematch + run_hook shutdown_start
# avoid staircase effect @@ -61,7 +63,7 @@ stat_busy "Deactivating Swap" stat_done
# stop monitoring of lvm2 groups before unmounting filesystems -if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating monitoring of LVM2 groups" /sbin/vgchange --monitor n >/dev/null 2>&1 stat_done @@ -86,7 +88,7 @@ if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then stat_done fi
-if [[ "$USELVM" =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Deactivating LVM2 groups" /sbin/vgchange --sysinit -a n >/dev/null 2>&1 stat_done diff --git a/rc.sysinit b/rc.sysinit index b08d927..bf2f83e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -6,6 +6,8 @@ . /etc/rc.conf . /etc/rc.d/functions
+shopt -s nocasematch + echo " " printhl "Arch Linux\n" printhl "${C_H2}http://www.archlinux.org" @@ -113,12 +115,12 @@ run_hook sysinit_udevsettled status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up
# SoftRAID devices detection -if [[ $USEMDADM =~ yes|YES && -x /sbin/mdadm ]]; then +if [[ "$USEMDADM" = yes && -x /sbin/mdadm ]]; then status "Activating SoftRAID arrays" /sbin/mdadm --assemble --scan fi
# FakeRAID devices detection -if [[ $USEDMRAID =~ yes|YES && -x /sbin/dmraid ]]; then +if [[ "$USEDMRAID" = yes && -x /sbin/dmraid ]]; then status "Activating FakeRAID arrays" /sbin/dmraid -i -ay fi
@@ -291,7 +293,7 @@ run_hook sysinit_premount stat_done
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw -if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then +if [[ "$USELVM" = yes && -x /sbin/lvm && -d /sys/block ]]; then stat_busy "Activating monitoring of LVM2 groups" if /sbin/vgchange --monitor y >/dev/null; then stat_done @@ -366,7 +368,7 @@ stat_busy "Setting Locale: $LOCALE" echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done
-if [[ ${LOCALE,,} =~ utf ]]; then +if [[ $LOCALE =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel # this code is needed not only for older kernels,
Looks fine to me.
Code is more elegant like that. Great idea. -- Sébastien Luttringer www.seblu.net
At this point, coreutils should be providing /bin/hostname instead of net-tools. If users wish to set an NIS/YS domain name, they should use core/yptools. Signed-off-by: Dave Reisner <d@falconindy.com> --- PKGBUILD | 2 +- network | 45 ++++++++++++++++----------------------------- rc.conf | 17 ++++++++++------- rc.sysinit | 10 ++-------- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 6f862e8..206f41b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -10,7 +10,7 @@ conflicts=('initscripts') provides=('initscripts=9999') backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' - 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') + 'iproute2' 'ncurses' 'kbd' 'findutils' 'sysvinit') optdepends=('bridge-utils: Network bridging support' 'dhcpcd: DHCP network configuration' 'ifenslave: Networking bonding support' diff --git a/network b/network index 27df68a..aeddef2 100755 --- a/network +++ b/network @@ -8,31 +8,25 @@ for s in wireless bonding bridges dhcpcd; do done ifup() { - local ifcfg=${!1} + local ifname ifcfg=${!1} if [[ ! $1 ]]; then echo "usage: $0 ifup <interface_name>" return 1 fi - # Get the name of the interface from the first token in the string - if [[ $ifcfg = dhcp ]]; then - ifname=$1 - else - ifname=${ifcfg%% *} - fi - - /sbin/ifconfig $ifname up + # Split the config string into interface name and config + read -r ifname ifcfg <<< "$ifcfg" + /usr/sbin/ip link set up dev $ifname || return 1 wi_up $1 || return 1 - if [[ $ifcfg = dhcp ]]; then + if [[ "$ifcfg" = dhcp ]]; then # remove the .pid file if it exists - /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1 - /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1 - /sbin/dhcpcd $DHCPCD_ARGS ${1} + /bin/rm -f /var/run/dhcpcd-$ifname.{pid,cache} >/dev/null 2>&1 + /sbin/dhcpcd $DHCPCD_ARGS $ifname else - /sbin/ifconfig $ifcfg + /usr/sbin/ip addr add $ifcfg dev $ifname fi } @@ -42,8 +36,7 @@ wi_up() { [[ ${!iwcfg} ]] || return 0 /usr/sbin/iwconfig ${!iwcfg} - [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 - sleep $WIRELESS_TIMEOUT + sleep ${WIRELESS_TIMEOUT:-2} bssid=$(iwgetid $1 -ra) if [[ $bssid = 00:00:00:00:00:00 ]]; then @@ -64,8 +57,10 @@ ifdown() { if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then /sbin/dhcpcd -k ${1} >/dev/null 2>&1 fi + # Always bring the interface itself down - /sbin/ifconfig ${1} down >/dev/null 2>&1 + /usr/sbin/ip addr flush dev $1 + /usr/sbin/ip link set down dev $1 } iflist() { @@ -87,11 +82,7 @@ rtup() { return 1 fi - if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 add $routecfg - else - /sbin/route add $routecfg - fi + /usr/sbin/ip route add $routecfg } rtdown() { @@ -102,11 +93,7 @@ rtdown() { return 1 fi - if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 del $routecfg - else - /sbin/route del $routecfg - fi + /usr/sbin/ip route del $routecfg } rtlist() { @@ -144,8 +131,8 @@ bridge_up() { 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 - /sbin/ifconfig $br down + if [[ -d /sys/class/net/$br ]]; then + ifdown $br /usr/sbin/brctl delbr $br fi /usr/sbin/brctl addbr $br diff --git a/rc.conf b/rc.conf index d2b0517..d96bea6 100644 --- a/rc.conf +++ b/rc.conf @@ -59,29 +59,32 @@ USELVM="no" # HOSTNAME="myhost" -# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces. +# Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces. # # Interfaces to start at boot-up (in this order) # Declare each interface then list in INTERFACES # - prefix an entry in INTERFACES with a ! to disable it # - no hyphens in your interface names - Bash doesn't like it -# +# # DHCP: Set your interface to "dhcp" (eth0="dhcp") # Wireless: See network profiles below # -#Static IP example -#eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255" -eth0="dhcp" +# Static IP example +#eth0="eth0 192.168.0.2/24" + +# Dynamic IP example +eth0="eth0 dhcp" + 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" +gateway="default via 192.168.0.1" ROUTES=(!gateway) - + # Setting this to "yes" will skip network shutdown. # This is required if your root device is on NFS. NETWORK_PERSIST="no" diff --git a/rc.sysinit b/rc.sysinit index bf2f83e..08a0768 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -111,8 +111,8 @@ fi run_hook sysinit_udevsettled # bring up the loopback interface -[[ -d /sys/class/net/lo ]] && \ - status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up +[[ -d /sys/class/net/lo ]] && + status "Bringing up loopback interface" /usr/sbin/ip link set up dev lo # SoftRAID devices detection if [[ "$USEMDADM" = yes && -x /sbin/mdadm ]]; then @@ -351,12 +351,6 @@ if [[ $HOSTNAME ]]; then status "Setting Hostname: $HOSTNAME" /bin/hostname "$HOSTNAME" fi -# Set the NIS domain name, if necessary -[[ -f /etc/conf.d/nisdomainname ]] && . /etc/conf.d/nisdomainname -if [[ $NISDOMAINNAME ]]; then - status "Setting NIS Domain Name: $NISDOMAINNAME" /bin/nisdomainname "$NISDOMAINNAME" -fi - status "Updating Module Dependencies" /sbin/depmod -A # Flush old locale settings -- 1.7.4.1
This patch did not apply due to a problem with PKGBUILD. I fixed it up manually. I did not test this at all, but at first glance it looks like the right approach. What userintervention does this require? I guess those who use nisdomainname, must install yp-tools and enable them in the DAEMONS array. Is that correct? Does any configuration files need adjustment? Anything else? Cheers, Tom On Saturday 26 March 2011 16:32:03 Dave Reisner wrote:
At this point, coreutils should be providing /bin/hostname instead of net-tools. If users wish to set an NIS/YS domain name, they should use core/yptools.
Signed-off-by: Dave Reisner <d@falconindy.com> --- PKGBUILD | 2 +- network | 45 ++++++++++++++++----------------------------- rc.conf | 17 ++++++++++------- rc.sysinit | 10 ++-------- 4 files changed, 29 insertions(+), 45 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD index 6f862e8..206f41b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -10,7 +10,7 @@ conflicts=('initscripts') provides=('initscripts=9999') backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' - 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') + 'iproute2' 'ncurses' 'kbd' 'findutils' 'sysvinit') optdepends=('bridge-utils: Network bridging support' 'dhcpcd: DHCP network configuration' 'ifenslave: Networking bonding support' diff --git a/network b/network index 27df68a..aeddef2 100755 --- a/network +++ b/network @@ -8,31 +8,25 @@ for s in wireless bonding bridges dhcpcd; do done
ifup() { - local ifcfg=${!1} + local ifname ifcfg=${!1}
if [[ ! $1 ]]; then echo "usage: $0 ifup <interface_name>" return 1 fi
- # Get the name of the interface from the first token in the string - if [[ $ifcfg = dhcp ]]; then - ifname=$1 - else - ifname=${ifcfg%% *} - fi - - /sbin/ifconfig $ifname up + # Split the config string into interface name and config + read -r ifname ifcfg <<< "$ifcfg"
+ /usr/sbin/ip link set up dev $ifname || return 1 wi_up $1 || return 1
- if [[ $ifcfg = dhcp ]]; then + if [[ "$ifcfg" = dhcp ]]; then # remove the .pid file if it exists - /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1 - /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1 - /sbin/dhcpcd $DHCPCD_ARGS ${1} + /bin/rm -f /var/run/dhcpcd-$ifname.{pid,cache} >/dev/null 2>&1 + /sbin/dhcpcd $DHCPCD_ARGS $ifname else - /sbin/ifconfig $ifcfg + /usr/sbin/ip addr add $ifcfg dev $ifname fi }
@@ -42,8 +36,7 @@ wi_up() { [[ ${!iwcfg} ]] || return 0
/usr/sbin/iwconfig ${!iwcfg} - [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 - sleep $WIRELESS_TIMEOUT + sleep ${WIRELESS_TIMEOUT:-2}
bssid=$(iwgetid $1 -ra) if [[ $bssid = 00:00:00:00:00:00 ]]; then @@ -64,8 +57,10 @@ ifdown() { if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then /sbin/dhcpcd -k ${1} >/dev/null 2>&1 fi + # Always bring the interface itself down - /sbin/ifconfig ${1} down >/dev/null 2>&1 + /usr/sbin/ip addr flush dev $1 + /usr/sbin/ip link set down dev $1 }
iflist() { @@ -87,11 +82,7 @@ rtup() { return 1 fi
- if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 add $routecfg - else - /sbin/route add $routecfg - fi + /usr/sbin/ip route add $routecfg }
rtdown() { @@ -102,11 +93,7 @@ rtdown() { return 1 fi
- if [[ $routecfg =~ :: ]]; then - /sbin/route -A inet6 del $routecfg - else - /sbin/route del $routecfg - fi + /usr/sbin/ip route del $routecfg }
rtlist() { @@ -144,8 +131,8 @@ bridge_up() { 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 - /sbin/ifconfig $br down + if [[ -d /sys/class/net/$br ]]; then + ifdown $br /usr/sbin/brctl delbr $br fi /usr/sbin/brctl addbr $br diff --git a/rc.conf b/rc.conf index d2b0517..d96bea6 100644 --- a/rc.conf +++ b/rc.conf @@ -59,29 +59,32 @@ USELVM="no" # HOSTNAME="myhost"
-# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces. +# Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces. # # Interfaces to start at boot-up (in this order) # Declare each interface then list in INTERFACES # - prefix an entry in INTERFACES with a ! to disable it # - no hyphens in your interface names - Bash doesn't like it -# +# # DHCP: Set your interface to "dhcp" (eth0="dhcp") # Wireless: See network profiles below #
-#Static IP example -#eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255" -eth0="dhcp" +# Static IP example +#eth0="eth0 192.168.0.2/24" + +# Dynamic IP example +eth0="eth0 dhcp" + 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" +gateway="default via 192.168.0.1" ROUTES=(!gateway) - + # Setting this to "yes" will skip network shutdown. # This is required if your root device is on NFS. NETWORK_PERSIST="no" diff --git a/rc.sysinit b/rc.sysinit index bf2f83e..08a0768 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -111,8 +111,8 @@ fi run_hook sysinit_udevsettled
# bring up the loopback interface -[[ -d /sys/class/net/lo ]] && \ - status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up +[[ -d /sys/class/net/lo ]] && + status "Bringing up loopback interface" /usr/sbin/ip link set up dev lo
# SoftRAID devices detection if [[ "$USEMDADM" = yes && -x /sbin/mdadm ]]; then @@ -351,12 +351,6 @@ if [[ $HOSTNAME ]]; then status "Setting Hostname: $HOSTNAME" /bin/hostname "$HOSTNAME" fi
-# Set the NIS domain name, if necessary -[[ -f /etc/conf.d/nisdomainname ]] && . /etc/conf.d/nisdomainname -if [[ $NISDOMAINNAME ]]; then - status "Setting NIS Domain Name: $NISDOMAINNAME" /bin/nisdomainname "$NISDOMAINNAME" -fi - status "Updating Module Dependencies" /sbin/depmod -A
# Flush old locale settings
On Sun, Mar 27, 2011 at 12:02:37AM +0100, Tom Gundersen wrote:
This patch did not apply due to a problem with PKGBUILD. I fixed it up manually.
I did not test this at all, but at first glance it looks like the right approach.
What userintervention does this require?
I guess those who use nisdomainname, must install yp-tools and enable them in the DAEMONS array. Is that correct? Does any configuration files need adjustment?
Anything else?
Cheers,
Tom
Yes, the big deal about this change is that it affects syntax in /etc/rc.conf. Best way to illustrate with examples, perhaps: # net-tools eth0="eth0 192.168.2.100 netmask 255.255.255.0" gateway="default gw 192.168.2.1" # iproute2 eth0="eth0 192.168.2.100/24" gateway="default via 192.168.2.1" DHCP is the same, excepting the fact that you need to declare the name of the interface. Two reasons: uniformity, and to be friendly towards interfaces with a dash (-) in the name. Simply, eth0="eth0 dhcp" Thomas has suggested that if we're going to change the config format that we use something a little more universal. Should the need ever arise to switch to yet another userspace tool some time off in the future, we could do the swap-out without bothering end users. I'm not sure what that config would look like, but it seems reasonable to me, provided that we're very clear about the limitations of the network service. dave
Hi Dave, Thanks for getting the ball rolling! On Saturday 26 March 2011 16:31:56 Dave Reisner wrote:
Hoping to get some movement on this list started early, so I'm peeling off some patches from my git tree that I've had sitting around for a while. The first 6 are rudimentary cleanup -- they don't try to affect functionality, but rather are meant to clean inconsistant or questionable syntax used, as well as possibly shave off a few CPU cycles here and there.
I thought that I'll treat patches to initscripts in the following way: I'll ask everyone to post them to this mailinglist as you have done, then I'll let some time pass for people to review and ack/nack (depending on how serious the patches are) before applying them. In this case, if there has been no objections in a few days I'll take that as a sign that everything is ok.
The final patch is a little more controversial and proposes to remove the decade old net-tools from the network service. This is a fairly straightforward change that was patched in a similar manner several years ago by James Raynor (iphitus), in response to FS #10160 which was eventually closed as "deferred".
Without having looked at the details yet, I think this initiative is great! I hope we'll get some people to review/ack this before proceeding. Cheers, Tom
Hi Dave, On Sat, Mar 26, 2011 at 9:31 PM, Dave Reisner <d@falconindy.com> wrote:
Hoping to get some movement on this list started early, so I'm peeling off some patches from my git tree that I've had sitting around for a while. The first 6 are rudimentary cleanup -- they don't try to affect functionality, but rather are meant to clean inconsistant or questionable syntax used, as well as possibly shave off a few CPU cycles here and there.
I pushed out patches 1-4, and I'll wait for a new version of 5 before I push out 5-6. I guess the last patch needs more discussion as it would require user intervention (but I'm all for it eventually). Cheers, Tom
participants (3)
-
Dave Reisner
-
Seblu
-
Tom Gundersen