And sadly some ksh variants don't support it.
As dhcpcd strives to be portable, stop using local.
wpa_supplicant_ctrldir()
{
- local dir
-
dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
"$wpa_supplicant_conf")
dir=$(trim "$dir")
wpa_supplicant_start()
{
- local dir err errn
-
# If the carrier is up, don't bother checking anything
[ "$ifcarrier" = "up" ] && return 0
wpa_supplicant_reconfigure()
{
- local dir err errn
-
dir=$(wpa_supplicant_ctrldir)
[ -z "$dir" ] && return 1
if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
wpa_supplicant_stop()
{
- local dir err errn
-
dir=$(wpa_supplicant_ctrldir)
[ -z "$dir" ] && return 1
wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0
set_zoneinfo()
{
- local zoneinfo_dir= zone_file=
-
[ -z "$new_tzdb_timezone" ] && return 0
+ zoneinfo_dir=
for d in \
/usr/share/zoneinfo \
/usr/lib/zoneinfo \
build_resolv_conf()
{
- local cf="$state_dir/resolv.conf.$ifname"
- local interfaces= header= search= srvs= servers= x=
+ cf="$state_dir/resolv.conf.$ifname"
# Build a list of interfaces
interfaces=$(list_interfaces "$resolv_conf_dir")
# regarding DNS option lifetime in ND messages.
eval_nd_dns()
{
-
eval ltime=\$nd${i}_rdnss${j}_lifetime
if [ -z "$ltime" -o "$ltime" = 0 ]; then
rdnss=
add_resolv_conf()
{
- local x= conf="$signature$NL" warn=true
- local i j ltime rdnss dnssl new_rdnss new_dnssl
+ conf="$signature$NL"
+ warn=true
# Loop to extract the ND DNS options using our indexed shell values
i=1
lookup_hostname()
{
[ -z "$new_ip_address" ] && return 1
- local h=
# Silly ISC programs love to send error text to stdout
if type dig >/dev/null 2>&1; then
h=$(dig +short -x $new_ip_address)
# Some systems don't have hostname(1)
_hostname()
{
- local name=
-
if [ -z "${1+x}" ]; then
if type hostname >/dev/null 2>&1; then
hostname
fi
}
-need_hostname()
+set_hostname_vars()
{
- local hfqdn=false hshort=false
+ hfqdn=false
+ hshort=false
+ case "$hostname_fqdn" in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
+ ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;;
+ *) hshort=true;;
+ esac
+}
+need_hostname()
+{
# Always load the hostname variable for future use
hostname="$(_hostname)"
case "$hostname" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
esac
- case "$hostname_fqdn" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
- ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;;
- *) hshort=true;;
- esac
+ set_hostname_vars
if [ -n "$old_fqdn" ]; then
if ${hfqdn} || ! ${hsort}; then
try_hostname()
{
-
[ "$hostname" = "$1" ] && return 0
if valid_domainname "$1"; then
syslog info "Setting hostname: $1"
set_hostname()
{
- local hfqdn=false hshort=false
-
need_hostname || return
- case "$hostname_fqdn" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
- ""|[Ss][Ee][Rr][Vv][Ee][Rr]) ;;
- *) hshort=true;;
- esac
+ set_hostname_vars
if [ -n "$new_fqdn" ]; then
if ${hfqdn} || ! ${hshort}; then
build_ntp_conf()
{
- local cf="$state_dir/ntp.conf.$ifname"
- local interfaces= header= srvs= servers= x=
+ cf="$state_dir/ntp.conf.$ifname"
# Build a list of interfaces
interfaces=$(list_interfaces "$ntp_conf_dir")
+ servers=
if [ -n "$interfaces" ]; then
# Build the header
for x in ${interfaces}; do
add_ntp_conf()
{
- local cf="$ntp_conf_dir/$ifname" x=
+ cf="$ntp_conf_dir/$ifname"
[ -e "$cf" ] && rm "$cf"
[ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
make_yp_conf()
{
[ -z "$new_nis_domain" -a -z "$new_nis_servers" ] && return 0
- local cf=/etc/yp.conf."$ifname" prefix= x= pid=
+ cf=/etc/yp.conf."$ifname"
rm -f "$cf"
echo "$signature" > "$cf"
+ prefix=
if [ -n "$new_nis_domain" ]; then
if ! valid_domainname "$new_nis_domain"; then
syslog err "Invalid NIS domain name: $new_nis_domain"
{
[ -n "$old_nis_domain" ] && domainname ""
restore_conf /etc/yp.conf || return 0
- local pid="$(ypbind_pid)"
+ pid="$(ypbind_pid)"
if [ -n "$pid" ]; then
kill -HUP "$pid"
fi
best_domain()
{
- local i=
-
for i in "$ypbind_dir/$interface_order".*; do
if [ -f "$i" ]; then
cat "$i"
if [ -z "$ypdomain_dir" ]; then
false
else
- local cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix"
+ cf="$ypdomain_dir/$new_nis_domain$ypdomain_suffix"
if [ -n "$new_nis_servers" ]; then
- local ncf="$cf.$ifname" x=
+ ncf="$cf.$ifname"
rm -f "$ncf"
for x in $new_nis_servers; do
echo "$x" >>"$ncf"
fi
fi
- local nd="$(best_domain)"
+ nd="$(best_domain)"
if [ $? = 0 -a "$nd" != "$(domainname)" ]; then
domainname "$nd"
if [ -n "$ypbind_restart_cmd" ]; then
restore_yp_binding()
{
-
rm -f "$ypbind_dir/$ifname"
- local nd="$(best_domain)"
+ nd="$(best_domain)"
# We need to stop ypbind if there is no best domain
# otherwise it will just stall as we cannot set domainname
# to blank :/
# Ensure that all arguments are unique
uniqify()
{
- local result= i=
for i do
case " $result " in
*" $i "*);;
# Otherwise we just use what we have.
list_interfaces()
{
- local i= x= ifaces=
for i in $interface_order; do
for x in "$1"/$i.*; do
[ -f "$x" ] && ifaces="$ifaces${ifaces:+ }${x##*/}"
# Trim function
trim()
{
- local var="$*"
-
+ var="$*"
var=${var#"${var%%[![:space:]]*}"}
var=${var%"${var##*[![:space:]]}"}
if [ -z "$var" ]; then
# but sed may not always be available at the time.
key_get_value()
{
- local key="$1" value= x= line=
-
+ key="$1"
shift
+
if type sed >/dev/null 2>&1; then
sed -n "s/^$key//p" $@
else
# but sed may not always be available at the time.
remove_markers()
{
- local m1="$1" m2="$2" x= line= in_marker=0
+ m1="$1"
+ m2="$2"
+ in_marker=0
shift; shift
if type sed >/dev/null 2>&1; then
# Compare two files.
comp_file()
{
-
[ -e "$1" -a -e "$2" ] || return 1
if type cmp >/dev/null 2>&1; then
# If different, replace first with second otherwise remove second.
change_file()
{
-
if [ -e "$1" ]; then
if comp_file "$1" "$2"; then
rm -f "$2"
# If different, copy or link depending on target type
copy_file()
{
-
if [ -h "$2" ]; then
[ "$(readlink "$2")" = "$1" ] && return 1
ln -sf "$1" "$2"
# Save a config file
save_conf()
{
-
if [ -f "$1" ]; then
rm -f "$1-pre.$interface"
cat "$1" > "$1-pre.$interface"
# Restore a config file
restore_conf()
{
-
[ -f "$1-pre.$interface" ] || return 1
cat "$1-pre.$interface" > "$1"
rm -f "$1-pre.$interface"
# Write a syslog entry
syslog()
{
- local lvl="$1"
+ lvl="$1"
if [ "$lvl" = debug ]; then
${syslog_debug} || return 0
# Check for a valid name as per RFC952 and RFC1123 section 2.1
valid_domainname()
{
- local name="$1" label
-
+ name="$1"
[ -z "$name" -o ${#name} -gt 255 ] && return 1
while [ -n "$name" ]; do
valid_domainname_list()
{
- local name
-
for name do
valid_domainname "$name" || return $?
done
[ -n "$_service_cmd" ] && return 0
- if ${_detected_init}; then
+ if $_detected_init; then
[ -n "$_service_cmd" ]
return $?
fi
# Detect the running init system.
# As systemd and OpenRC can be installed on top of legacy init
# systems we try to detect them first.
- local status="@STATUSARG@"
+ status="@STATUSARG@"
: ${status:=status}
if [ -x /bin/systemctl -a -S /run/systemd/private ]; then
_service_exists="/bin/systemctl --quiet is-enabled \$1.service"
# Check a system service exists
service_exists()
{
-
if [ -z "$_service_exists" ]; then
detect_init || return 1
fi
# Send a command to a system service
service_cmd()
{
-
if [ -z "$_service_cmd" ]; then
detect_init || return 1
fi
# Send a command to a system service if it is running
service_status()
{
-
if [ -z "$_service_cmd" ]; then
detect_init || return 1
fi
# Handy macros for our hooks
service_command()
{
-
service_exists $1 && service_cmd $1 $2
}
service_condcommand()
{
-
service_exists $1 && service_status $1 && service_cmd $1 $2
}