periodic: set _localbase for periodic scripts from within periodic.conf

Set _localbase variable from within /etc/defaults/periodic.conf
for use by periodic scripts.

This fixes e5d7100c09, no other functional changes intended.

Reported by:		gahr, otis
Reviewed by:		markj, gahr
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D47486

(cherry picked from commit c8b89c11a1181e900acb638cfde7a55e92553175)
This commit is contained in:
Juraj Lutter 2024-11-08 14:38:19 +01:00
parent cba91bf59c
commit 860d98fc6d
2 changed files with 13 additions and 8 deletions

View file

@ -15,6 +15,15 @@
#
#
_set_localbase() {
_localbase=`/sbin/sysctl -n user.localbase 2> /dev/null`
# Set default value of _localbase if not previously set
: ${_localbase:="/usr/local"}
}
# Set _localbase with fallback to /usr/local
_set_localbase
# What files override these defaults ?
periodic_conf_files="/etc/periodic.conf /etc/periodic.conf.local ${_localbase}/etc/periodic.conf"

View file

@ -29,14 +29,6 @@ if [ $# -lt 1 ] ; then
usage
fi
_localbase=`/sbin/sysctl -n user.localbase 2> /dev/null`
# Set default value of _localbase if not previously set
: ${_localbase:="/usr/local"}
# Use a deterministic path to match the preset from /etc/crontab in case
# periodic is run interactively.
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${_localbase}/sbin:${_localbase}/bin
# If possible, check the global system configuration file,
# to see if there are additional dirs to check
if [ -r /etc/defaults/periodic.conf ]; then
@ -44,6 +36,10 @@ if [ -r /etc/defaults/periodic.conf ]; then
source_periodic_confs
fi
# Use a deterministic path to match the preset from /etc/crontab in case
# periodic is run interactively.
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${_localbase}/sbin:${_localbase}/bin
host=`hostname`
export host