Some notes to demo the diff below:
# -=-=-=-=-=-=-= Assignment:
me$ _STATIC_RCCONF='/etc/rc.conf'
me$ _RCCONF="${_STATIC_RCCONF}.local"
# -=-=-=-=-=-=-= Test 1:
me$ print ${_STATIC_RCCONF} ${_RCCONF}
/etc/rc.conf /etc/rc.conf.local
me$ print ${_RCCONF%/*} ${_RCCONF##*/}
/etc rc.conf.local
# -=-=-=-=-=-=-= Test 2:
me$ _TMP_RCCONF=$(mktemp -p ${_RCCONF%/*} -t ${_RCCONF##*/}.XXXXXXXXXX) ||
print $?
mktemp: cannot make temp file /etc/rc.conf.local.luzxGjy18I: Permission denied
1
# -=-=-=-=-=-=-= Reassignment:
me$ _STATIC_RCCONF='/tmp/rc.conf'
me$ _RCCONF="${_STATIC_RCCONF}.local"
# -=-=-=-=-=-=-= Test 3:
me$ _TMP_RCCONF=$(mktemp -p ${_RCCONF%/*} -t ${_RCCONF##*/}.XXXXXXXXXX) ||
print $?
me$ ls ${_TMP_RCCONF}
/tmp/rc.conf.local.ZLyVBCNMtk
Index: rcctl.sh
===================================================================
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.41
diff -u -p -r1.41 rcctl.sh
--- rcctl.sh 10 Oct 2014 15:59:36 -0000 1.41
+++ rcctl.sh 11 Oct 2014 12:41:22 -0000
@@ -18,7 +18,9 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
_special_services="accounting check_quotas ipsec multicast_host
multicast_router pf spamd_black"
-readonly _special_services
+_STATIC_RCCONF='/etc/rc.conf'
+_RCCONF="${_STATIC_RCCONF}.local"
+readonly _special_services _STATIC_RCCONF _RCCONF
# get local functions from rc.subr(8)
FUNCS_ONLY=1
@@ -38,21 +40,21 @@ needs_root()
rcconf_edit_begin()
{
- _TMP_RCCONF=$(mktemp -p /etc -t rc.conf.local.XXXXXXXXXX) || exit 1
- if [ -f /etc/rc.conf.local ]; then
+ _TMP_RCCONF=$(mktemp -p ${_RCCONF%/*} -t ${_RCCONF##*/}.XXXXXXXXXX) ||
exit
+ if [ -f ${_RCCONF} ]; then
# only to keep permissions (file content is not needed)
- cp -p /etc/rc.conf.local ${_TMP_RCCONF} || exit 1
+ cp -p ${_RCCONF} ${_TMP_RCCONF} || exit 1
else
- touch /etc/rc.conf.local || exit 1
+ touch ${_RCCONF} || exit 1
fi
}
rcconf_edit_end()
{
sort -u -o ${_TMP_RCCONF} ${_TMP_RCCONF} || exit 1
- mv ${_TMP_RCCONF} /etc/rc.conf.local || exit 1
- if [ ! -s /etc/rc.conf.local ]; then
- rm /etc/rc.conf.local || exit 1
+ mv ${_TMP_RCCONF} ${_RCCONF} || exit 1
+ if [ ! -s ${_RCCONF} ]; then
+ rm ${_RCCONF} || exit 1
fi
}
@@ -62,7 +64,7 @@ svc_default_enabled()
[ -n "${_svc}" ] || return
local _ret=1
- _rc_parse_conf /etc/rc.conf
+ _rc_parse_conf ${_STATIC_RCCONF}
svc_is_enabled ${_svc} && _ret=0
_rc_parse_conf
@@ -166,7 +168,7 @@ append_to_pkg_scripts()
if [ -z "${pkg_scripts}" ]; then
echo pkg_scripts="${_svc}" >>${_TMP_RCCONF}
elif ! echo ${pkg_scripts} | grep -qw ${_svc}; then
- grep -v "^pkg_scripts.*=" /etc/rc.conf.local >${_TMP_RCCONF}
+ grep -v "^pkg_scripts.*=" ${_RCCONF} >${_TMP_RCCONF}
echo pkg_scripts="${pkg_scripts} ${_svc}" >>${_TMP_RCCONF}
fi
rcconf_edit_end
@@ -182,7 +184,7 @@ rm_from_pkg_scripts()
rcconf_edit_begin
sed "/^pkg_scripts[[:>:]]/{s/[[:<:]]${_svc}[[:>:]]//g
s/['\"]//g;s/ *= */=/;s/ */ /g;s/ $//;/=$/d;}" \
- /etc/rc.conf.local >${_TMP_RCCONF}
+ ${_RCCONF} >${_TMP_RCCONF}
rcconf_edit_end
}
@@ -193,7 +195,7 @@ add_flags()
if svc_is_special ${_svc}; then
rcconf_edit_begin
- grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF}
+ grep -v "^${_svc}.*=" ${_RCCONF} >${_TMP_RCCONF}
if ! svc_default_enabled ${_svc}; then
echo "${_svc}=YES" >>${_TMP_RCCONF}
fi
@@ -219,7 +221,7 @@ add_flags()
fi
rcconf_edit_begin
- grep -v "^${_svc}_flags.*=" /etc/rc.conf.local >${_TMP_RCCONF}
+ grep -v "^${_svc}_flags.*=" ${_RCCONF} >${_TMP_RCCONF}
if [ -n "${_flags}" ] || \
( svc_is_base ${_svc} && ! svc_default_enabled ${_svc} ); then
echo ${_svc}_flags=${_flags} >>${_TMP_RCCONF}
@@ -234,12 +236,12 @@ rm_flags()
rcconf_edit_begin
if svc_is_special ${_svc}; then
- grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF}
+ grep -v "^${_svc}.*=" ${_RCCONF} >${_TMP_RCCONF}
if svc_default_enabled ${_svc}; then
echo "${_svc}=NO" >>${_TMP_RCCONF}
fi
else
- grep -v "^${_svc}_flags.*=" /etc/rc.conf.local >${_TMP_RCCONF}
+ grep -v "^${_svc}_flags.*=" ${_RCCONF} >${_TMP_RCCONF}
if svc_default_enabled ${_svc}; then
echo "${_svc}_flags=NO" >>${_TMP_RCCONF}
fi