Some of the system scripts make inconsistent use of ksh-specific features, specifically "print" and "[[" as efficient replacements for "echo" and "[". This change makes the /etc/ksh.kshrc and all the rc scripts use "print" and "[[" exclusively.
Switching from echo to print only brought up one interesting issue: /etc/rc.d/mountd uses "print -n >foo" instead of "touch foo". The latter is arguably more transparent but I didn't change to it. Switching from [ to [[ makes a lot of things more readable; most of the improvements result from removing unnecessary quotation marks. We also don't have to test for unset variables as aggressively; a number of awkward [ X"$foo" = XYes ] constructions were replaced with [[ $foo = Yes ]] . The test [[ ${_args} = "${_args# }" ]] appears in rcctl; I left the quotation marks on the right-hand side because I'm afraid of breaking something I don't understand. The rcctl script also has a lot of lines like: daemon_timeout="$(svc_getdef ${_svc} timeout)" I think the quotation marks are unnecessary but the original author went to a lot of trouble to escape internal quotes, e.g. daemon_flags="$(eval print \"\${${_svc}_flags}\")" so I'll give him the benefit of the doubt. I would encourage somone with greater confidence to take a closer look. I replaced `backticks` with $(subshell notation) in a few places, but only in places where I was already changing [ to [[. I wanted to remove them all but I can't really justify the change in terms of either readability or process efficiency. Regarding numeric changes: in ksh, [[ 0 -eq 00 ]] is true (numeric comparison) but [[ 0 = 00 ]] is false (string comparison). The latter is more readable, so I made the switch in places where the left-hand side is a system output, e.g. [[ $(id -u ) = 0 ]] or [[ $# > 0 ]]. I would not expect id(1) to print the string "00" for root, nor would I expect the shell to print "00" for $#. But I did *not* change comparison operators in more complicated situations, like the bottom of /etc/rc which has [[ ${daemon_rtable} -eq 0 ]]. It isn't immediately obvious what sort of string is in ${daemon_rtable} so the numeric comparison seems appropriate here. I corrected a comment at the top of /etc/rc; it said that "set +o sh" turned Strict Bourne shell mode off. I'm pretty sure it's actually turning strict mode on. My system still boots with these changes, and rcctl still appears to work. I can't easily test all of the code paths in each of the rc scripts. But the changes involved here are straightforward, and you can validate this diff line-by-line. Index: etc/ksh.kshrc =================================================================== RCS file: /open/anoncvs/cvs/src/etc/ksh.kshrc,v retrieving revision 1.20 diff -u -p -u -r1.20 ksh.kshrc --- etc/ksh.kshrc 18 Feb 2015 08:39:32 -0000 1.20 +++ etc/ksh.kshrc 5 Sep 2016 04:03:43 -0000 @@ -62,7 +62,7 @@ case "$-" in case "$TERM" in sun*-s) # sun console with status line - if [ "$tty" != "$console" ]; then + if [[ $tty != $console ]]; then # ilabel ILS='\033]L'; ILE='\033\\' # window title bar @@ -81,7 +81,7 @@ case "$-" in *) ;; esac # do we want window decorations? - if [ "$ILS" ]; then + if [[ -n $ILS ]]; then function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; } function label { print -n "${WLS}$*${WLE}">/dev/tty; } @@ -136,14 +136,14 @@ function no_path { } # if $1 exists and is not in path, append it function add_path { - [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" + [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1" } # if $1 exists and is not in path, prepend it function pre_path { - [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" + [[ -d ${1:-.} ]] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}" } # if $1 is in path, remove it function del_path { - no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: | + no_path $* || eval ${2:-PATH}=`eval print :'$'${2:-PATH}: | sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"` } Index: etc/rc =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc,v retrieving revision 1.486 diff -u -p -u -r1.486 rc --- etc/rc 10 Jul 2016 09:08:18 -0000 1.486 +++ etc/rc 4 Sep 2016 14:26:10 -0000 @@ -4,7 +4,7 @@ # Output and error are redirected to console by init, and the console is the # controlling terminal. -# Turn off Strict Bourne shell. +# Turn on Strict Bourne shell. set +o sh # Subroutines (have to come first). @@ -137,14 +137,14 @@ make_keys() { local _iked_pub=/etc/iked/local.pub if [[ ! -f $_isakmpd_key ]]; then - echo -n "openssl: generating isakmpd/iked RSA keys... " + print -n "openssl: generating isakmpd/iked RSA keys... " if openssl genrsa -out $_isakmpd_key 2048 >/dev/null 2>&1 && chmod 600 $_isakmpd_key && openssl rsa -out $_isakmpd_pub -in $_isakmpd_key \ -pubout >/dev/null 2>&1; then - echo done. + print done. else - echo failed. + print failed. fi fi @@ -167,7 +167,7 @@ reorder_libs() { # Skip if /usr/lib is on a nfs mounted filesystem. [[ $_mp == *' type nfs '* ]] && return - echo -n 'reordering libraries:' + print -n 'reordering libraries:' # Only choose the latest version of the libraries. for _liba in /usr/lib/libc.so.*.a; do @@ -183,7 +183,7 @@ reorder_libs() { if mount -u -w $_dkdev; then _remount=true else - echo ' failed.' + print ' failed.' return fi fi @@ -210,9 +210,9 @@ reorder_libs() { fi if $_error; then - echo ' failed.' + print ' failed.' else - echo ' done.' + print ' done.' fi } @@ -237,21 +237,21 @@ do_fsck() { 0) ;; 2) exit 1 ;; - 4) echo "Rebooting..." + 4) print "Rebooting..." reboot - echo "Reboot failed; help!" + print "Reboot failed; help!" exit 1 ;; - 8) echo "Automatic file system check failed; help!" + 8) print "Automatic file system check failed; help!" exit 1 ;; - 12) echo "Boot interrupted." + 12) print "Boot interrupted." exit 1 ;; 130) # Interrupt before catcher installed. exit 1 ;; - *) echo "Unknown error; help!" + *) print "Unknown error; help!" exit 1 ;; esac @@ -282,26 +282,26 @@ FUNCS_ONLY=1 . /etc/rc.d/rc.subr _rc_parse_conf if [[ $1 == shutdown ]]; then - if echo 2>/dev/null >>/var/db/host.random || \ - echo 2>/dev/null >>/etc/random.seed; then + if print 2>/dev/null >>/var/db/host.random || \ + print 2>/dev/null >>/etc/random.seed; then random_seed else - echo warning: cannot write random seed to disk + print warning: cannot write random seed to disk fi # If we are in secure level 0, assume single user mode. if (($(sysctl -n kern.securelevel) == 0)); then - echo 'single user: not running shutdown scripts' + print 'single user: not running shutdown scripts' else pkg_scripts=${pkg_scripts%%*( )} if [[ -n $pkg_scripts ]]; then - echo -n 'stopping package daemons:' + print -n 'stopping package daemons:' while [[ -n $pkg_scripts ]]; do _d=${pkg_scripts##* } pkg_scripts=${pkg_scripts%%*( )$_d} [[ -x /etc/rc.d/$_d ]] && /etc/rc.d/$_d stop done - echo '.' + print '.' fi [[ -f /etc/rc.shutdown ]] && sh /etc/rc.shutdown @@ -319,13 +319,13 @@ fi swapctl -A -t blk if [[ -e /fastboot ]]; then - echo "Fast boot: skipping disk checks." + print "Fast boot: skipping disk checks." elif [[ $1 == autoboot ]]; then - echo "Automatic boot in progress: starting file system checks." + print "Automatic boot in progress: starting file system checks." do_fsck fi -trap "echo 'Boot interrupted.'; exit 1" 3 +trap "print 'Boot interrupted.'; exit 1" 3 umount -a >/dev/null 2>&1 mount -a -t nonfs,vnd @@ -333,7 +333,7 @@ mount -uw / # root on nfs requires this rm -f /fastboot # XXX (root now writeable) # Set flags on ttys. (Do early, in case they use tty for SLIP in netstart.) -echo 'setting tty flags' +print 'setting tty flags' ttyflags -a # Set keyboard encoding. @@ -378,7 +378,7 @@ fill_baddynamic tcp sysctl_conf -echo 'starting network' +print 'starting network' # Set carp interlock by increasing the demotion counter. # Prevents carp from preempting until the system is booted. @@ -420,24 +420,24 @@ dmesg >/var/run/dmesg.boot # Save a copy make_keys -echo -n 'starting early daemons:' +print -n 'starting early daemons:' start_daemon syslogd ldattach pflogd nsd rebound unbound ntpd start_daemon iscsid isakmpd iked sasyncd ldapd npppd -echo '.' +print '.' # Load IPsec rules. if [[ $ipsec != NO && -f /etc/ipsec.conf ]]; then ipsecctl -f /etc/ipsec.conf fi -echo -n 'starting RPC daemons:' +print -n 'starting RPC daemons:' start_daemon portmap ypldap rm -f /var/run/ypbind.lock if [[ -n $(domainname) ]]; then start_daemon ypserv ypbind fi start_daemon mountd nfsd lockd statd amd -echo '.' +print '.' # Check and mount remaining file systems and enable additional swap. mount -a @@ -452,9 +452,9 @@ if [[ -d /var/crash ]]; then fi if [[ $check_quotas == YES ]]; then - echo -n 'checking quotas:' + print -n 'checking quotas:' quotacheck -a - echo ' done.' + print ' done.' quotaon -a fi @@ -472,7 +472,7 @@ if [[ -f /etc/ptmp ]]; then 'password file may be incorrect -- /etc/ptmp exists' fi -echo clearing /tmp +print clearing /tmp # Prune quickly with one rm, then use find to clean up /tmp/[lqv]* # (not needed with mfs /tmp, but doesn't hurt there...). @@ -497,7 +497,7 @@ if [[ ! -f /etc/motd ]]; then fi if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then sysctl -n kern.version | sed 1q >$T - echo "" >>$T + print "" >>$T sed '1,/^$/d' </etc/motd >>$T cmp -s $T /etc/motd || cp $T /etc/motd rm -f $T @@ -505,23 +505,23 @@ fi if [[ $accounting == YES ]]; then [[ ! -f /var/account/acct ]] && touch /var/account/acct - echo 'turning on accounting' + print 'turning on accounting' accton /var/account/acct fi if [[ -x /sbin/ldconfig ]]; then - echo 'creating runtime link editor directory cache.' + print 'creating runtime link editor directory cache.' [[ -d /usr/local/lib ]] && shlib_dirs="/usr/local/lib $shlib_dirs" [[ -d /usr/X11R6/lib ]] && shlib_dirs="/usr/X11R6/lib $shlib_dirs" ldconfig $shlib_dirs fi -echo 'preserving editor files.'; /usr/libexec/vi.recover +print 'preserving editor files.'; /usr/libexec/vi.recover # If rc.sysmerge exists, run it just once, and make sure it is deleted. run_upgrade_script sysmerge -echo -n 'starting network daemons:' +print -n 'starting network daemons:' start_daemon ldomd vmd sshd snmpd ldpd ripd ospfd ospf6d bgpd ifstated start_daemon relayd dhcpd dhcrelay mrouted dvmrpd radiusd eigrpd @@ -534,22 +534,22 @@ fi start_daemon hostapd lpd smtpd slowcgi httpd ftpd start_daemon ftpproxy ftpproxy6 tftpd tftpproxy identd inetd rarpd bootparamd start_daemon rbootd mopd spamd spamlogd sndiod -echo '.' +print '.' # If rc.firsttime exists, run it just once, and make sure it is deleted. run_upgrade_script firsttime # Run rc.d(8) scripts from packages. if [[ -n $pkg_scripts ]]; then - echo -n 'starting package daemons:' + print -n 'starting package daemons:' for _daemon in $pkg_scripts; do if [[ -x /etc/rc.d/$_daemon ]]; then start_daemon $_daemon else - echo -n " ${_daemon}(absent)" + print -n " ${_daemon}(absent)" fi done - echo '.' + print '.' fi [[ -f /etc/rc.local ]] && sh /etc/rc.local @@ -558,9 +558,9 @@ ifconfig -g carp -carpdemote 128 # Disab mixerctl_conf -echo -n 'starting local daemons:' +print -n 'starting local daemons:' start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xdm -echo '.' +print '.' date exit 0 Index: etc/rc.d/amd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/amd,v retrieving revision 1.7 diff -u -p -u -r1.7 amd --- etc/rc.d/amd 15 Jul 2015 13:50:54 -0000 1.7 +++ etc/rc.d/amd 5 Sep 2016 01:54:10 -0000 @@ -11,7 +11,7 @@ rc_reload=NO rc_stop=NO rc_pre() { - [ -e ${amd_master} ] || return 1 + [[ -e ${amd_master} ]] || return 1 daemon_flags="${daemon_flags} $(print -rn -- $(< ${amd_master}))" } Index: etc/rc.d/bootparamd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/bootparamd,v retrieving revision 1.2 diff -u -p -u -r1.2 bootparamd --- etc/rc.d/bootparamd 8 Jul 2011 02:15:34 -0000 1.2 +++ etc/rc.d/bootparamd 5 Sep 2016 01:54:29 -0000 @@ -9,7 +9,7 @@ daemon="/usr/sbin/rpc.bootparamd" rc_reload=NO rc_pre() { - [ -s /etc/bootparams ] + [[ -s /etc/bootparams ]] } rc_cmd $1 Index: etc/rc.d/iked =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/iked,v retrieving revision 1.3 diff -u -p -u -r1.3 iked --- etc/rc.d/iked 19 Dec 2015 13:45:12 -0000 1.3 +++ etc/rc.d/iked 5 Sep 2016 02:58:28 -0000 @@ -9,7 +9,7 @@ daemon="/sbin/iked" pexp="iked: parent.*" rc_pre() { - [ X"${sasyncd_flags}" != X"NO" ] && \ + [[ ${sasyncd_flags} != NO ]] && \ daemon_flags="-S ${daemon_flags}" #return 0 # child will not return a config parsing error to the parent Index: etc/rc.d/isakmpd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/isakmpd,v retrieving revision 1.1 diff -u -p -u -r1.1 isakmpd --- etc/rc.d/isakmpd 6 Jul 2011 18:55:36 -0000 1.1 +++ etc/rc.d/isakmpd 5 Sep 2016 02:57:07 -0000 @@ -9,7 +9,7 @@ daemon="/sbin/isakmpd" pexp="isakmpd: monitor \[priv\]" rc_pre() { - [ X"${sasyncd_flags}" != X"NO" ] && \ + [[ ${sasyncd_flags} != NO ]] && \ daemon_flags="-S ${daemon_flags}" return 0 } Index: etc/rc.d/ldattach =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/ldattach,v retrieving revision 1.2 diff -u -p -u -r1.2 ldattach --- etc/rc.d/ldattach 8 Jul 2011 02:15:34 -0000 1.2 +++ etc/rc.d/ldattach 5 Sep 2016 03:37:53 -0000 @@ -9,7 +9,7 @@ daemon="/sbin/ldattach" rc_reload=NO rc_pre() { - [ -n "${ldattach_flags}" ] + [[ -n ${ldattach_flags} ]] } rc_cmd $1 Index: etc/rc.d/mopd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/mopd,v retrieving revision 1.3 diff -u -p -u -r1.3 mopd --- etc/rc.d/mopd 19 Sep 2011 20:42:24 -0000 1.3 +++ etc/rc.d/mopd 5 Sep 2016 01:56:08 -0000 @@ -10,7 +10,7 @@ daemon_flags="-a" rc_reload=NO rc_pre() { - [ -d /tftpboot/mop ] + [[ -d /tftpboot/mop ]] } rc_cmd $1 Index: etc/rc.d/mountd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/mountd,v retrieving revision 1.6 diff -u -p -u -r1.6 mountd --- etc/rc.d/mountd 26 Dec 2015 09:55:15 -0000 1.6 +++ etc/rc.d/mountd 5 Sep 2016 01:56:19 -0000 @@ -10,9 +10,9 @@ pexp="mountd: \[priv\]" rc_stop=NO rc_pre() { - [ -s /etc/exports ] && grep -qv '^#' /etc/exports && \ + [[ -s /etc/exports ]] && grep -qv '^#' /etc/exports && \ rm -f /var/db/mountdtab && \ - echo -n > /var/db/mountdtab + print -n > /var/db/mountdtab } rc_cmd $1 Index: etc/rc.d/nfsd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/nfsd,v retrieving revision 1.6 diff -u -p -u -r1.6 nfsd --- etc/rc.d/nfsd 22 Aug 2014 08:10:38 -0000 1.6 +++ etc/rc.d/nfsd 5 Sep 2016 01:56:28 -0000 @@ -12,7 +12,7 @@ pexp="(${daemon}( |$)|nfsd: (master|serv rc_reload=NO rc_pre() { - [ -s /etc/exports ] && grep -qv '^#' /etc/exports + [[ -s /etc/exports ]] && grep -qv '^#' /etc/exports } rc_cmd $1 Index: etc/rc.d/rarpd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/rarpd,v retrieving revision 1.3 diff -u -p -u -r1.3 rarpd --- etc/rc.d/rarpd 19 Sep 2011 20:42:24 -0000 1.3 +++ etc/rc.d/rarpd 5 Sep 2016 01:56:38 -0000 @@ -10,7 +10,7 @@ daemon_flags="-a" rc_reload=NO rc_pre() { - [ -s /etc/ethers ] + [[ -s /etc/ethers ]] } rc_cmd $1 Index: etc/rc.d/rc.subr =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/rc.subr,v retrieving revision 1.115 diff -u -p -u -r1.115 rc.subr --- etc/rc.d/rc.subr 31 Aug 2016 08:47:11 -0000 1.115 +++ etc/rc.d/rc.subr 5 Sep 2016 03:27:03 -0000 @@ -20,20 +20,20 @@ _rc_actions="start stop restart reload c readonly _rc_actions _rc_err() { - [ -n "${1}" ] && echo "${1}" 1>&2 - [ -n "${2}" ] && exit "${2}" || exit 1 + [[ -n ${1} ]] && print "${1}" 1>&2 + [[ -n ${2} ]] && exit "${2}" || exit 1 } _rc_not_supported() { local _a _enotsup _what=${1} for _a in ${_rc_actions}; do - [ "${_what}" == "restart" ] && _what="stop" - if [ "${_what}" == "${_a}" ]; then + [[ ${_what} == restart ]] && _what="stop" + if [[ ${_what} == ${_a} ]]; then eval _enotsup=\${rc_${_what}} break fi done - [ X"${_enotsup}" == X"NO" ] + [[ ${_enotsup} == NO ]] } _rc_usage() { @@ -45,7 +45,7 @@ _rc_usage() { } _rc_write_runfile() { - [ -d ${_RC_RUNDIR} ] || mkdir -p ${_RC_RUNDIR} && \ + [[ -d ${_RC_RUNDIR} ]] || mkdir -p ${_RC_RUNDIR} && \ cat >${_RC_RUNFILE} <<EOF daemon_class=${daemon_class} daemon_flags=${daemon_flags} @@ -61,8 +61,8 @@ _rc_rm_runfile() { } _rc_do() { - if [ -n "${_RC_DEBUG}" ]; then - echo "doing $@" && "$@" + if [[ -n ${_RC_DEBUG} ]]; then + print "doing $@" && "$@" else "$@" >/dev/null 2>&1 fi @@ -70,14 +70,14 @@ _rc_do() { _rc_exit() { local _pfix - [ -z "${INRC}" -o X"$1" != X"ok" ] && _pfix="($1)" - echo ${INRC:+'-n'} "${_pfix}" - [ X"$1" = X"ok" ] && exit 0 || exit 1 + [[ -z ${INRC} || $1 != ok ]] && _pfix="($1)" + print ${INRC:+'-n'} "${_pfix}" + [[ $1 = ok ]] && exit 0 || exit 1 } _rc_wait() { local _i=0 - while [ $_i -lt ${daemon_timeout} ]; do + while [[ $_i -lt ${daemon_timeout} ]]; do case "$1" in reload|start) _rc_do rc_check && return 0 ;; @@ -95,25 +95,25 @@ _rc_wait() { _rc_quirks() { # special care needed for spamlogd to avoid starting it up and failing # all the time - if [ X"${spamd_flags}" = X"NO" -o X"${spamd_black}" != X"NO" ]; then + if [[ ${spamd_flags} = NO || ${spamd_black} != NO ]]; then spamlogd_flags=NO fi # special care needed for pflogd to avoid starting it up and failing # if pf is not enabled - if [ X"${pf}" = X"NO" ]; then + if [[ ${pf} = NO ]]; then pflogd_flags=NO fi # special care needed if nfs_server=YES to startup nfsd and mountd with # sane default flags - if [ X"${nfs_server}" = X"YES" ]; then - [ X"${nfsd_flags}" = X"NO" ] && nfsd_flags="-tun 4" - [ X"${mountd_flags}" = X"NO" ] && mountd_flags= + if [[ ${nfs_server} = YES ]]; then + [[ ${nfsd_flags} = NO ]] && nfsd_flags="-tun 4" + [[ ${mountd_flags} = NO ]] && mountd_flags= fi # in case domainname is set and /var/yp/binding exists enable ypbind - if [ X"`domainname`" != X"" -a -d /var/yp/binding ]; then + if [[ -n $(domainname) && -d /var/yp/binding ]]; then ypbind_flags= fi } @@ -125,7 +125,7 @@ _rc_parse_conf() { accounting amd_master check_quotas ipsec multicast nfs_server \ pexp pf pkg_scripts shlib_dirs spamd_black - [ $# -gt 0 ] || set -- /etc/rc.conf /etc/rc.conf.local + [[ $# > 0 ]] || set -- /etc/rc.conf /etc/rc.conf.local for _rcfile; do [[ -f $_rcfile ]] || continue while IFS=' ' read -r _l; do @@ -148,7 +148,7 @@ _rc_parse_conf() { } # return if we only want internal functions -[ -n "${FUNCS_ONLY}" ] && return +[[ -n ${FUNCS_ONLY} ]] && return rc_start() { ${rcexec} "${daemon} ${daemon_flags} ${_bg}" @@ -169,34 +169,35 @@ rc_stop() { rc_cmd() { local _bg _n - [ -n "${1}" ] && echo "${_rc_actions}" | grep -qw -- ${1} || _rc_usage + [[ -n ${1} ]] && print "${_rc_actions}" | grep -qw -- ${1} || \ + _rc_usage - [ "$(id -u)" -eq 0 ] || \ - [ X"${rc_usercheck}" != X"NO" -a X"$1" = "Xcheck" ] || \ + [[ $(id -u) = 0 ]] || \ + [[ ${rc_usercheck} != NO && $1 = check ]] || \ _rc_err "$0: need root privileges" if _rc_not_supported $1; then - [ -n "${INRC}" ] && exit 1 + [[ -n ${INRC} ]] && exit 1 _rc_err "$0: $1 is not supported" fi - [ X"${rc_bg}" = X"YES" ] && _bg="&" - [ -n "${_RC_DEBUG}" ] || _n="-n" + [[ ${rc_bg} = YES ]] && _bg="&" + [[ -n ${_RC_DEBUG} ]] || _n="-n" _rc_do _rc_parse_conf ${_RC_RUNFILE} case "$1" in check) - echo $_n "${INRC:+ }${_name}" + print $_n "${INRC:+ }${_name}" _rc_do rc_check && _rc_exit ok _rc_exit failed ;; start) - if [ X"${daemon_flags}" = X"NO" ]; then + if [[ ${daemon_flags} = NO ]]; then _rc_err "$0: need -f to force $1 since ${_name}_flags=NO" fi - [ -z "${INRC}" ] && _rc_do rc_check && exit 0 - echo $_n "${INRC:+ }${_name}" + [[ -z ${INRC} ]] && _rc_do rc_check && exit 0 + print $_n "${INRC:+ }${_name}" while true; do # no real loop, only needed to break if type rc_pre >/dev/null; then _rc_do rc_pre || break @@ -213,7 +214,7 @@ rc_cmd() { ;; stop) _rc_do rc_check || exit 0 - echo $_n "${INRC:+ }${_name}" + print $_n "${INRC:+ }${_name}" _rc_do rc_stop || _rc_exit failed _rc_do _rc_wait stop || _rc_exit failed if type rc_post >/dev/null; then \ @@ -223,7 +224,7 @@ rc_cmd() { _rc_exit ok ;; reload) - echo $_n "${INRC:+ }${_name}" + print $_n "${INRC:+ }${_name}" _rc_do rc_check && _rc_do rc_reload || _rc_exit failed _rc_do _rc_wait reload || _rc_exit failed _rc_exit ok @@ -238,7 +239,7 @@ rc_cmd() { esac } -[ -n "${daemon}" ] || _rc_err "$0: daemon is not set" +[[ -n ${daemon} ]] || _rc_err "$0: daemon is not set" unset _RC_DEBUG _RC_FORCE while getopts "df" c; do @@ -265,28 +266,28 @@ eval _rctimeout=\${${_name}_timeout} # set default values; duplicated in rcctl(8) getcap -f /etc/login.conf ${_name} 1>/dev/null 2>&1 && \ daemon_class=${_name} || daemon_class=daemon -[ -z "${daemon_rtable}" ] && daemon_rtable=0 -[ -z "${daemon_user}" ] && daemon_user=root -[ -z "${daemon_timeout}" ] && daemon_timeout=30 +[[ -z ${daemon_rtable} ]] && daemon_rtable=0 +[[ -z ${daemon_user} ]] && daemon_user=root +[[ -z ${daemon_timeout} ]] && daemon_timeout=30 # use flags from the rc.d script if daemon is not enabled -[ -n "${_RC_FORCE}" -o "$1" != "start" ] && [ X"${_rcflags}" = X"NO" ] && \ +[[ -n ${_RC_FORCE} || $1 != start ]] && [[ ${_rcflags} = NO ]] && \ unset _rcflags -[ -n "${_rcflags}" ] && daemon_flags=${_rcflags} -[ -n "${_rcrtable}" ] && daemon_rtable=${_rcrtable} -[ -n "${_rcuser}" ] && daemon_user=${_rcuser} -[ -n "${_rctimeout}" ] && daemon_timeout=${_rctimeout} - -if [ -n "${_RC_DEBUG}" ]; then - echo -n "${_name}_flags " - [ -n "${_rcflags}" ] || echo -n "empty, using default " - echo ">${daemon_flags}<" +[[ -n ${_rcflags} ]] && daemon_flags=${_rcflags} +[[ -n ${_rcrtable} ]] && daemon_rtable=${_rcrtable} +[[ -n ${_rcuser} ]] && daemon_user=${_rcuser} +[[ -n ${_rctimeout} ]] && daemon_timeout=${_rctimeout} + +if [[ -n ${_RC_DEBUG} ]]; then + print -n "${_name}_flags " + [[ -n ${_rcflags} ]] || print -n "empty, using default " + print ">${daemon_flags}<" fi readonly daemon_class unset _rcflags _rcrtable _rcuser _rctimeout pexp="${daemon}${daemon_flags:+ ${daemon_flags}}" rcexec="su -l -c ${daemon_class} -s /bin/sh ${daemon_user} -c" -[ "${daemon_rtable}" -eq 0 ] || \ +[[ ${daemon_rtable} -eq 0 ]] || \ rcexec="route -T ${daemon_rtable} exec ${rcexec}" Index: etc/rc.d/spamd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/spamd,v retrieving revision 1.7 diff -u -p -u -r1.7 spamd --- etc/rc.d/spamd 15 Jul 2015 13:50:54 -0000 1.7 +++ etc/rc.d/spamd 5 Sep 2016 03:36:37 -0000 @@ -10,7 +10,7 @@ pexp="spamd: \[priv\].*" rc_reload=NO rc_pre() { - [ X"${spamd_black}" != X"NO" ] && \ + [[ ${spamd_black} != NO ]] && \ daemon_flags="-b ${daemon_flags}" return 0 } @@ -18,7 +18,7 @@ rc_pre() { rc_start() { ${rcexec} "${daemon} ${daemon_flags}" || return 1 spamd_setup_flags="-D" - [ X"${spamd_black}" != X"NO" ] && \ + [[ ${spamd_black} != NO ]] && \ spamd_setup_flags="-b ${spamd_setup_flags}" /usr/libexec/spamd-setup ${spamd_setup_flags} } Index: etc/rc.d/spamlogd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/spamlogd,v retrieving revision 1.2 diff -u -p -u -r1.2 spamlogd --- etc/rc.d/spamlogd 8 Aug 2011 17:13:31 -0000 1.2 +++ etc/rc.d/spamlogd 5 Sep 2016 03:37:22 -0000 @@ -9,7 +9,7 @@ daemon="/usr/libexec/spamlogd" rc_reload=NO rc_pre() { - [ X"${spamd_flags}" != X"NO" -a X"${spamd_black}" = X"NO" ] + [[ ${spamd_flags} != X"NO" && ${spamd_black} = NO ]] if pfctl -si | grep -q Enabled; then ifconfig pflog0 create if ifconfig pflog0; then Index: etc/rc.d/ypbind =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/ypbind,v retrieving revision 1.5 diff -u -p -u -r1.5 ypbind --- etc/rc.d/ypbind 18 Oct 2015 03:51:11 -0000 1.5 +++ etc/rc.d/ypbind 5 Sep 2016 03:31:40 -0000 @@ -10,7 +10,7 @@ rc_bg=YES rc_reload=NO rc_pre() { - [ X"`domainname`" != X"" ] + [[ -n $(domainname) ]] } rc_post() { Index: etc/rc.d/yppasswdd =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/yppasswdd,v retrieving revision 1.4 diff -u -p -u -r1.4 yppasswdd --- etc/rc.d/yppasswdd 8 Jul 2011 04:29:54 -0000 1.4 +++ etc/rc.d/yppasswdd 5 Sep 2016 03:33:16 -0000 @@ -9,20 +9,20 @@ daemon="/usr/sbin/rpc.yppasswdd" rc_reload=NO rc_pre() { - [ X"`domainname`" != X"" -a -d /var/yp/`domainname` ] || \ + [[ -n $(domainname) && -d /var/yp/$(domainname) ]] || \ return 1 _host1=`ypwhich -m passwd 2> /dev/null` _host2=`hostname` - if [ `grep '^lookup' /etc/resolv.conf | grep yp | wc -c` -ne 0 ]; then + if [[ `grep '^lookup' /etc/resolv.conf | grep yp | wc -c` -ne 0 ]]; then _host1=`ypmatch $_host1 hosts | cut -d' ' -f2` _host2=`ypmatch $_host2 hosts | cut -d' ' -f2 | head -1` else - _host1=`echo $_host1 | nslookup | grep '^Name: ' | \ + _host1=`print $_host1 | nslookup | grep '^Name: ' | \ sed -e 's/^Name: //'` - _host2=`echo $_host2 | nslookup | grep '^Name: ' | \ + _host2=`print $_host2 | nslookup | grep '^Name: ' | \ sed -e 's/^Name: //'` fi - [ "$_host2" = "$_host1" ] + [[ $_host2 = $_host1 ]] } rc_cmd $1 Index: etc/rc.d/ypserv =================================================================== RCS file: /open/anoncvs/cvs/src/etc/rc.d/ypserv,v retrieving revision 1.4 diff -u -p -u -r1.4 ypserv --- etc/rc.d/ypserv 6 Oct 2011 06:47:50 -0000 1.4 +++ etc/rc.d/ypserv 5 Sep 2016 02:17:52 -0000 @@ -7,7 +7,7 @@ daemon="/usr/sbin/ypserv" . /etc/rc.d/rc.subr rc_pre() { - [ X"`domainname`" != X"" -a -d /var/yp/`domainname` ] + [[ -n $(domainname) && -d /var/yp/$(domainname) ]] } rc_cmd $1 Index: usr.sbin/rcctl/rcctl.sh =================================================================== RCS file: /open/anoncvs/cvs/src/usr.sbin/rcctl/rcctl.sh,v retrieving revision 1.104 diff -u -p -u -r1.104 rcctl.sh --- usr.sbin/rcctl/rcctl.sh 30 Jul 2016 06:25:21 -0000 1.104 +++ usr.sbin/rcctl/rcctl.sh 5 Sep 2016 03:55:04 -0000 @@ -28,7 +28,7 @@ _rc_parse_conf usage() { local _a _i - for _i in ${_rc_actions}; do _a="$(echo -n ${_i}${_a:+|${_a}})"; done + for _i in ${_rc_actions}; do _a="$(print -n ${_i}${_a:+|${_a}})"; done _rc_err \ "usage: rcctl get|getdef|set service | daemon [variable [arguments]] @@ -39,7 +39,7 @@ usage() needs_root() { - [ "$(id -u)" -ne 0 ] && _rc_err "${0##*/}: \"$*\" needs root privileges" + [[ $(id -u) = 0 ]] || _rc_err "${0##*/}: \"$*\" needs root privileges" } rcctl_err() @@ -54,21 +54,21 @@ ls_rcscripts() cd /etc/rc.d && set -- * for _s; do [[ ${_s} = *.* ]] && continue - [ ! -d "${_s}" ] && echo "${_s}" + [[ ! -d "${_s}" ]] && print "${_s}" done } pkg_scripts_append() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return rcconf_edit_begin - if [ -z "${pkg_scripts}" ]; then - echo pkg_scripts="${_svc}" >>${_TMP_RCCONF} - elif ! echo ${pkg_scripts} | grep -qw -- ${_svc}; then + if [[ -z ${pkg_scripts} ]]; then + print pkg_scripts="${_svc}" >>${_TMP_RCCONF} + elif ! print ${pkg_scripts} | grep -qw -- ${_svc}; then grep -v "^pkg_scripts.*=" /etc/rc.conf.local >${_TMP_RCCONF} - echo pkg_scripts="${pkg_scripts} ${_svc}" >>${_TMP_RCCONF} + print pkg_scripts="${pkg_scripts} ${_svc}" >>${_TMP_RCCONF} fi rcconf_edit_end } @@ -76,7 +76,7 @@ pkg_scripts_append() pkg_scripts_order() { local _svcs="$*" - [ -n "${_svcs}" ] || return + [[ -n ${_svcs} ]] || return needs_root ${action} local _pkg_scripts _svc @@ -87,20 +87,20 @@ pkg_scripts_order() rcctl_err "${_svc} is not enabled" fi done - _pkg_scripts=$(echo "${_svcs} ${pkg_scripts}" | tr "[:blank:]" "\n" | \ + _pkg_scripts=$(print "${_svcs} ${pkg_scripts}" | tr "[:blank:]" "\n" | \ awk -v ORS=' ' '!x[$0]++') rcconf_edit_begin grep -v "^pkg_scripts.*=" /etc/rc.conf.local >${_TMP_RCCONF} - echo pkg_scripts=${_pkg_scripts} >>${_TMP_RCCONF} + print pkg_scripts=${_pkg_scripts} >>${_TMP_RCCONF} rcconf_edit_end } pkg_scripts_rm() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return - [ -z "${pkg_scripts}" ] && return + [[ -z ${pkg_scripts} ]] && return rcconf_edit_begin sed "/^pkg_scripts[[:>:]]/{s/[[:<:]]${_svc}[[:>:]]//g @@ -113,7 +113,7 @@ rcconf_edit_begin() { _TMP_RCCONF=$(mktemp -p /etc -t rc.conf.local.XXXXXXXXXX) || \ rcctl_err "cannot create temporary file under /etc" - if [ -f /etc/rc.conf.local ]; then + if [[ -f /etc/rc.conf.local ]]; then cat /etc/rc.conf.local >${_TMP_RCCONF} || \ rcctl_err "cannot append to ${_TMP_RCCONF}" else @@ -128,7 +128,7 @@ rcconf_edit_end() rcctl_err "cannot modify ${_TMP_RCCONF}" cat ${_TMP_RCCONF} >/etc/rc.conf.local || \ rcctl_err "cannot append to /etc/rc.conf.local" - if [ ! -s /etc/rc.conf.local ]; then + if [[ ! -s /etc/rc.conf.local ]]; then rm /etc/rc.conf.local || \ rcctl_err "cannot remove /etc/rc.conf.local" fi @@ -139,21 +139,21 @@ rcconf_edit_end() svc_is_avail() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return - [ -x "/etc/rc.d/${_svc}" ] && return + [[ -x /etc/rc.d/${_svc} ]] && return svc_is_special ${_svc} } svc_is_base() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return local _cached _ret - _cached=$(eval echo \${cached_svc_is_base_${_svc}}) - [ "${_cached}" ] && return "${_cached}" + _cached=$(eval print \${cached_svc_is_base_${_svc}}) + [[ -n ${_cached} ]] && return "${_cached}" grep -qw "^${_svc}_flags" /etc/rc.conf _ret=$? @@ -165,14 +165,14 @@ svc_is_base() svc_is_meta() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return local _cached _ret - _cached=$(eval echo \${cached_svc_is_meta_${_svc}}) - [ "${_cached}" ] && return "${_cached}" + _cached=$(eval print \${cached_svc_is_meta_${_svc}}) + [[ -n ${_cached} ]] && return "${_cached}" - [ -r "/etc/rc.d/${_svc}" ] && ! grep -qw "^rc_cmd" /etc/rc.d/${_svc} + [[ -r /etc/rc.d/${_svc} ]] && ! grep -qw "^rc_cmd" /etc/rc.d/${_svc} _ret=$? set -A cached_svc_is_meta_${_svc} -- ${_ret} @@ -182,14 +182,14 @@ svc_is_meta() svc_is_special() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return local _cached _ret - _cached=$(eval echo \${cached_svc_is_special_${_svc}}) - [ "${_cached}" ] && return "${_cached}" + _cached=$(eval print \${cached_svc_is_special_${_svc}}) + [[ -n ${_cached} ]] && return "${_cached}" - echo ${_special_svcs} | grep -qw -- ${_svc} + print ${_special_svcs} | grep -qw -- ${_svc} _ret=$? set -A cached_svc_is_special_${_svc} -- ${_ret} @@ -199,7 +199,7 @@ svc_is_special() svc_ls() { local _lsarg=$1 - [ -n "${_lsarg}" ] || return + [[ -n ${_lsarg} ]] || return # we do not want to return the "status" nor the rc.d(8) script retcode local _ret=0 _on _svc _started @@ -208,31 +208,31 @@ svc_ls() all) ( ls_rcscripts - echo ${_special_svcs} | tr "[:blank:]" "\n" + print ${_special_svcs} | tr "[:blank:]" "\n" ) | sort ;; failed) for _svc in $(svc_ls on); do ! svc_is_special ${_svc} && \ ! /etc/rc.d/${_svc} check >/dev/null && \ - echo ${_svc} && _ret=1 + print ${_svc} && _ret=1 done ;; off|on) for _svc in $(svc_ls all); do svc_get ${_svc} status && _on=1 - [ "${_lsarg}" = "on" -a -n "${_on}" ] || \ - [ "${_lsarg}" = "off" -a -z "${_on}" ] && \ - echo ${_svc} + [[ ${_lsarg} = on && -n ${_on} ]] || \ + [[ ${_lsarg} = off && -z ${_on} ]] && \ + print ${_svc} unset _on done ;; started|stopped) for _svc in $(ls_rcscripts); do /etc/rc.d/${_svc} check >/dev/null && _started=1 - [ "${_lsarg}" = "started" -a -n "${_started}" ] || \ - [ "${_lsarg}" = "stopped" -a -z "${_started}" ] && \ - echo ${_svc} + [[ ${_lsarg} = started && -n ${_started} ]] || \ + [[ ${_lsarg} = stopped && -z ${_started} ]] && \ + print ${_svc} unset _started done ;; @@ -246,72 +246,72 @@ svc_ls() svc_get() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return local _status=0 _val _var=$2 local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user if svc_is_special ${_svc}; then - daemon_flags="$(eval echo \${${_svc}})" + daemon_flags="$(eval print \${${_svc}})" else # set pkg daemon_flags to "NO" to match base svc if ! svc_is_base ${_svc}; then - if ! echo ${pkg_scripts} | grep -qw -- ${_svc}; then + if ! print ${pkg_scripts} | grep -qw -- ${_svc}; then daemon_flags="NO" fi fi if ! svc_is_meta ${_svc}; then # these are expensive, make sure they are explicitely requested - if [ -z "${_var}" -o "${_var}" = "class" ]; then + if [[ -z ${_var} || ${_var} = class ]]; then getcap -f /etc/login.conf ${_svc} 1>/dev/null 2>&1 && \ daemon_class=${_svc} - [ -z "${daemon_class}" ] && \ + [[ -z ${daemon_class} ]] && \ daemon_class="$(svc_getdef ${_svc} class)" fi if [[ -z ${_var} || ${_var} == @(flags|status) ]]; then - [ -z "${daemon_flags}" ] && \ - daemon_flags="$(eval echo \"\${${_svc}_flags}\")" - [ -z "${daemon_flags}" ] && \ + [[ -z ${daemon_flags} ]] && \ + daemon_flags="$(eval print \"\${${_svc}_flags}\")" + [[ -z ${daemon_flags} ]] && \ daemon_flags="$(svc_getdef ${_svc} flags)" fi - if [ -z "${_var}" -o "${_var}" = "rtable" ]; then - [ -z "${daemon_rtable}" ] && \ - daemon_rtable="$(eval echo \"\${${_svc}_rtable}\")" - [ -z "${daemon_rtable}" ] && \ + if [[ -z ${_var} || ${_var} = rtable ]]; then + [[ -z ${daemon_rtable} ]] && \ + daemon_rtable="$(eval print \"\${${_svc}_rtable}\")" + [[ -z ${daemon_rtable} ]] && \ daemon_rtable="$(svc_getdef ${_svc} rtable)" fi - if [ -z "${_var}" -o "${_var}" = "timeout" ]; then - [ -z "${daemon_timeout}" ] && \ - daemon_timeout="$(eval echo \"\${${_svc}_timeout}\")" - [ -z "${daemon_timeout}" ] && \ + if [[ -z ${_var} || ${_var} = timeout ]]; then + [[ -z ${daemon_timeout} ]] && \ + daemon_timeout="$(eval print \"\${${_svc}_timeout}\")" + [[ -z ${daemon_timeout} ]] && \ daemon_timeout="$(svc_getdef ${_svc} timeout)" fi - if [ -z "${_var}" -o "${_var}" = "user" ]; then - [ -z "${daemon_user}" ] && \ - daemon_user="$(eval echo \"\${${_svc}_user}\")" - [ -z "${daemon_user}" ] && \ + if [[ -z ${_var} || ${_var} = user ]]; then + [[ -z ${daemon_user} ]] && \ + daemon_user="$(eval print \"\${${_svc}_user}\")" + [[ -z ${daemon_user} ]] && \ daemon_user="$(svc_getdef ${_svc} user)" fi fi fi - [ "${daemon_flags}" = "NO" ] && _status=1 + [[ ${daemon_flags} = NO ]] && _status=1 - if [ -n "${_var}" ]; then - [ "${_var}" = "status" ] && return ${_status} + if [[ -n ${_var} ]]; then + [[ ${_var} = status ]] && return ${_status} eval _val=\${daemon_${_var}} - [ -z "${_val}" ] || print -r -- "${_val}" + [[ -z ${_val} ]] || print -r -- "${_val}" else svc_is_meta ${_svc} && return ${_status} if svc_is_special ${_svc}; then - echo "${_svc}=${daemon_flags}" + print "${_svc}=${daemon_flags}" else - echo "${_svc}_class=${daemon_class}" - echo "${_svc}_flags=${daemon_flags}" - echo "${_svc}_rtable=${daemon_rtable}" - echo "${_svc}_timeout=${daemon_timeout}" - echo "${_svc}_user=${daemon_user}" + print "${_svc}_class=${daemon_class}" + print "${_svc}_flags=${daemon_flags}" + print "${_svc}_rtable=${daemon_rtable}" + print "${_svc}_timeout=${daemon_timeout}" + print "${_svc}_user=${daemon_user}" fi return ${_status} fi @@ -321,7 +321,7 @@ svc_get() svc_getdef() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return local _status=0 _val _var=$2 local daemon_class daemon_flags daemon_rtable daemon_timeout daemon_user @@ -329,8 +329,8 @@ svc_getdef() if svc_is_special ${_svc}; then # unconditionally parse: we always output flags and/or status _rc_parse_conf /etc/rc.conf - daemon_flags="$(eval echo \${${_svc}})" - [ "${daemon_flags}" = "NO" ] && _status=1 + daemon_flags="$(eval print \${${_svc}})" + [[ ${daemon_flags} = NO ]] && _status=1 else if ! svc_is_base ${_svc}; then _status=1 # all pkg_scripts are off by default @@ -340,7 +340,8 @@ svc_getdef() # we'll get our default flags from the rc.d script [[ -z ${_var} || ${_var} == status ]] && \ _rc_parse_conf /etc/rc.conf - [ "$(eval echo \${${_svc}_flags})" = "NO" ] && _status=1 + [[ "$(eval print \${${_svc}_flags})" = NO ]] && \ + _status=1 fi if ! svc_is_meta ${_svc}; then @@ -348,26 +349,26 @@ svc_getdef() . /etc/rc.d/${_svc} >/dev/null 2>&1 daemon_class=daemon - [ -z "${daemon_rtable}" ] && daemon_rtable=0 - [ -z "${daemon_timeout}" ] && daemon_timeout=30 - [ -z "${daemon_user}" ] && daemon_user=root + [[ -z ${daemon_rtable} ]] && daemon_rtable=0 + [[ -z ${daemon_timeout} ]] && daemon_timeout=30 + [[ -z ${daemon_user} ]] && daemon_user=root fi fi - if [ -n "${_var}" ]; then - [ "${_var}" = "status" ] && return ${_status} + if [[ -n ${_var} ]]; then + [[ ${_var} = status ]] && return ${_status} eval _val=\${daemon_${_var}} - [ -z "${_val}" ] || print -r -- "${_val}" + [[ -z ${_val} ]] || print -r -- "${_val}" else svc_is_meta ${_svc} && return ${_status} if svc_is_special ${_svc}; then - echo "${_svc}=${daemon_flags}" + print "${_svc}=${daemon_flags}" else - echo "${_svc}_class=${daemon_class}" - echo "${_svc}_flags=${daemon_flags}" - echo "${_svc}_rtable=${daemon_rtable}" - echo "${_svc}_timeout=${daemon_timeout}" - echo "${_svc}_user=${daemon_user}" + print "${_svc}_class=${daemon_class}" + print "${_svc}_flags=${daemon_flags}" + print "${_svc}_rtable=${daemon_rtable}" + print "${_svc}_timeout=${daemon_timeout}" + print "${_svc}_user=${daemon_user}" fi return ${_status} fi @@ -376,18 +377,18 @@ svc_getdef() svc_rm() { local _svc=$1 - [ -n "${_svc}" ] || return + [[ -n ${_svc} ]] || return rcconf_edit_begin if svc_is_special ${_svc}; then grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF} ( svc_getdef ${_svc} status ) && \ - echo "${_svc}=NO" >>${_TMP_RCCONF} + print "${_svc}=NO" >>${_TMP_RCCONF} else grep -Ev "^${_svc}_(flags|rtable|timeout|user).*=" \ /etc/rc.conf.local >${_TMP_RCCONF} ( svc_getdef ${_svc} status ) && \ - echo "${_svc}_flags=NO" >>${_TMP_RCCONF} + print "${_svc}_flags=NO" >>${_TMP_RCCONF} fi rcconf_edit_end } @@ -395,7 +396,7 @@ svc_rm() svc_set() { local _svc=$1 _var=$2 - [ -n "${_svc}" -a -n "${_var}" ] || return + [[ -n ${_svc} && -n ${_var} ]] || return shift 2 local _args="$*" @@ -403,16 +404,16 @@ svc_set() # don't check if we are already enabled or disabled because rc.conf(8) # defaults may have changed in which case we may have a matching # redundant entry in rc.conf.local that we can drop - if [ "${_var}" = "status" ]; then - if [ "${_args}" = "on" ]; then + if [[ ${_var} = status ]]; then + if [[ ${_args} = on ]]; then _var="flags" # keep our flags if we're already enabled eval "_args=\"\${${_svc}_${_var}}\"" - [ "${_args}" = "NO" ] && unset _args + [[ ${_args} = NO ]] && unset _args if ! svc_is_base ${_svc} && ! svc_is_special ${_svc}; then pkg_scripts_append ${_svc} fi - elif [ "${_args}" = "off" ]; then + elif [[ ${_args} = off ]]; then if ! svc_is_base ${_svc} && ! svc_is_special ${_svc}; then pkg_scripts_rm ${_svc} fi @@ -427,44 +428,44 @@ svc_set() fi if svc_is_special ${_svc}; then - [ "${_var}" = "flags" ] || return + [[ ${_var} = flags ]] || return rcconf_edit_begin grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF} ( svc_getdef ${_svc} status ) || \ - echo "${_svc}=YES" >>${_TMP_RCCONF} + print "${_svc}=YES" >>${_TMP_RCCONF} rcconf_edit_end return fi - if [ -n "${_args}" ]; then - if [ "${_var}" = "rtable" ]; then + if [[ -n ${_args} ]]; then + if [[ ${_var} = rtable ]]; then [[ ${_args} != +([[:digit:]]) || ${_args} -lt 0 ]] && \ rcctl_err "\"${_args}\" is not an integer" fi - if [ "${_var}" = "timeout" ]; then + if [[ ${_var} = timeout ]]; then [[ ${_args} != +([[:digit:]]) || ${_args} -le 0 ]] && \ rcctl_err "\"${_args}\" is not a positive integer" fi - if [ "${_var}" = "user" ]; then + if [[ ${_var} = user ]]; then getent passwd "${_args}" >/dev/null || \ rcctl_err "user \"${_args}\" does not exist" fi # unset flags if they match the default enabled ones - [ "${_args}" = "$(svc_getdef ${_svc} ${_var})" ] && \ + [[ ${_args} = "$(svc_getdef ${_svc} ${_var})" ]] && \ unset _args fi # protect leading whitespace - [ "${_args}" = "${_args# }" ] || _args="\"${_args}\"" + [[ ${_args} = "${_args# }" ]] || _args="\"${_args}\"" # reset: value may have changed unset ${_svc}_${_var} rcconf_edit_begin grep -v "^${_svc}_${_var}.*=" /etc/rc.conf.local >${_TMP_RCCONF} - if [ -n "${_args}" ] || \ - ( svc_is_base ${_svc} && ! svc_getdef ${_svc} status && [ "${_var}" == "flags" ] ); then - echo "${_svc}_${_var}=${_args}" >>${_TMP_RCCONF} + if [[ -n ${_args} ]] || \ + ( svc_is_base ${_svc} && ! svc_getdef ${_svc} status && [[ ${_var} == flags ]] ); then + print "${_svc}_${_var}=${_args}" >>${_TMP_RCCONF} fi rcconf_edit_end } @@ -478,7 +479,7 @@ while getopts "df" c; do esac done shift $((OPTIND-1)) -[ $# -gt 0 ] || usage +[[ $# > 0 ]] || usage action=$1 ret=0 @@ -499,9 +500,9 @@ case ${action} in disable|enable|start|stop|restart|reload|check) shift 1 svcs="$*" - [ -z "${svcs}" ] && usage + [[ -z ${svcs} ]] && usage # it's ok to disable a non-existing daemon - if [ "${action}" != "disable" ]; then + if [[ ${action} != disable ]]; then for svc in ${svcs}; do svc_is_avail ${svc} || \ rcctl_err "service ${svc} does not exist" 2 @@ -511,14 +512,14 @@ case ${action} in get|getdef) svc=$2 var=$3 - [ -z "${svc}" ] && usage - [ "${svc}" = "all" ] || svc_is_avail ${svc} || \ + [[ -z ${svc} ]] && usage + [[ ${svc} = all ]] || svc_is_avail ${svc} || \ rcctl_err "service ${svc} does not exist" 2 - if [ -n "${var}" ]; then - [ "${svc}" = "all" ] && usage + if [[ -n ${var} ]]; then + [[ ${svc} = all ]] && usage [[ ${var} != @(class|flags|status|rtable|timeout|user) ]] && usage if svc_is_meta ${svc}; then - [ "${var}" != "status" ] && \ + [[ ${var} != status ]] && \ rcctl_err "/etc/rc.d/${svc} is a meta script, cannot \"${action} ${var}\"" fi if svc_is_special ${svc}; then @@ -530,16 +531,16 @@ case ${action} in set) svc=$2 var=$3 - [ $# -ge 3 ] && shift 3 || shift $# + [[ $# > 3 ]] && shift 3 || shift $# args="$*" - [ -z "${svc}" ] && usage + [[ -z ${svc} ]] && usage # it's ok to disable a non-existing daemon - if [ "${action} ${var} ${args}" != "set status off" ]; then + if [[ "${action} ${var} ${args}" != "set status off" ]]; then svc_is_avail ${svc} || \ rcctl_err "service ${svc} does not exist" 2 fi [[ ${var} != @(class|flags|rtable|status|timeout|user) ]] && usage - svc_is_meta ${svc} && [ "${var}" != "status" ] && \ + svc_is_meta ${svc} && [[ ${var} != status ]] && \ rcctl_err "/etc/rc.d/${svc} is a meta script, cannot \"${action} ${var}\"" [[ ${var} = flags && ${args} = NO ]] && \ rcctl_err "\"flags NO\" contradicts \"${action}\"" @@ -571,7 +572,7 @@ case ${action} in exit ${ret} ;; get|getdef) - if [ "${svc}" = "all" ]; then + if [[ ${svc} = all ]]; then for svc in $(svc_ls all); do ( svc_${action} ${svc} "${var}" ) done @@ -586,11 +587,11 @@ case ${action} in svc_ls ${lsarg} ;; order) - if [ -n "${svcs}" ]; then + if [[ -n ${svcs} ]]; then needs_root ${action} pkg_scripts_order ${svcs} else - [[ -z ${pkg_scripts} ]] || echo ${pkg_scripts} + [[ -z ${pkg_scripts} ]] || print ${pkg_scripts} fi ;; set)