From: Roy Marples Date: Mon, 20 Apr 2009 09:38:08 +0000 (+0000) Subject: Remove old NetworkManager script - it's useless these days. X-Git-Tag: v5.0.0~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f06fdc0f91d4a1a5dcc16853bad22501bb3ce70;p=thirdparty%2Fdhcpcd.git Remove old NetworkManager script - it's useless these days. Remove gratuitous usage of {} in variables. --- diff --git a/dhcpcd-hooks/01-test b/dhcpcd-hooks/01-test index ef7896da..b46d4005 100644 --- a/dhcpcd-hooks/01-test +++ b/dhcpcd-hooks/01-test @@ -1,6 +1,6 @@ # Just echo our DHCP options we have -if [ "${reason}" = "TEST" ]; then +if [ "$reason" = "TEST" ]; then set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort set | grep "^\(new_\|old_\)" | sort fi diff --git a/dhcpcd-hooks/10-mtu b/dhcpcd-hooks/10-mtu index 4265b482..167d6467 100644 --- a/dhcpcd-hooks/10-mtu +++ b/dhcpcd-hooks/10-mtu @@ -1,5 +1,5 @@ # Configure the MTU for the interface -if [ -n "${new_interface_mtu}" ]; then - ifconfig "${interface}" mtu "${new_interface_mtu}" +if [ -n "$new_interface_mtu" ]; then + ifconfig "$interface" mtu "$new_interface_mtu" fi diff --git a/dhcpcd-hooks/20-resolv.conf b/dhcpcd-hooks/20-resolv.conf index 7f69d4c2..385f850a 100644 --- a/dhcpcd-hooks/20-resolv.conf +++ b/dhcpcd-hooks/20-resolv.conf @@ -6,121 +6,121 @@ # Also, resolvconf can configure local nameservers such as bind # or dnsmasq. This is important as the libc resolver isn't that powerful. -resolv_conf_dir="${state_dir}/resolv.conf" +resolv_conf_dir="$state_dir/resolv.conf" build_resolv_conf() { - local cf="${state_dir}/resolv.conf.${interface}" + local cf="$state_dir/resolv.conf.$interface" local interfaces= header= search= srvs= servers= x= # Build a list of interfaces - interfaces=$(list_interfaces "${resolv_conf_dir}") + interfaces=$(list_interfaces "$resolv_conf_dir") # Build the resolv.conf - if [ -n "${interfaces}" ]; then + if [ -n "$interfaces" ]; then # Build the header for x in ${interfaces}; do - header="${header}${header:+, }${x}" + header="$header${header:+, }$x" done # Build the search list - domain=$(cd "${resolv_conf_dir}"; \ + domain=$(cd "$resolv_conf_dir"; \ key_get_value "domain " ${interfaces}) - search=$(cd "${resolv_conf_dir}"; \ + search=$(cd "$resolv_conf_dir"; \ key_get_value "search " ${interfaces}) set -- ${domain} unset domain if [ -n "$2" ]; then - search="${search} $@" + search="$search $@" elif [ -n "$1" ]; then domain="domain $1\n" fi - [ -n "${search}" ] && search="search $(uniqify ${search})\n" + [ -n "$search" ] && search="search $(uniqify $search)\n" # Build the nameserver list - srvs=$(cd "${resolv_conf_dir}"; \ + srvs=$(cd "$resolv_conf_dir"; \ key_get_value "nameserver " ${interfaces}) for x in $(uniqify ${srvs}); do - servers="${servers}nameserver ${x}\n" + servers="${servers}nameserver $x\n" done fi - header="${signature_base}${header:+ ${from} }${header}" + header="$signature_base${header:+ $from }$header" # Assemble resolv.conf using our head and tail files - [ -f "${cf}" ] && rm -f "${cf}" - echo "${header}" > "${cf}" + [ -f "$cf" ] && rm -f "$cf" + echo "$header" > "$cf" if [ -f /etc/resolv.conf.head ]; then - cat /etc/resolv.conf.head >> "${cf}" + cat /etc/resolv.conf.head >> "$cf" else - echo "# /etc/resolv.conf.head can replace this line" >> "${cf}" + echo "# /etc/resolv.conf.head can replace this line" >> "$cf" fi - printf "${domain}${search}${servers}" >> "${cf}" + printf "$domain$search$servers" >> "$cf" if [ -f /etc/resolv.conf.tail ]; then - cat /etc/resolv.conf.tail >> "${cf}" + cat /etc/resolv.conf.tail >> "$cf" else - echo "# /etc/resolv.conf.tail can replace this line" >> "${cf}" + echo "# /etc/resolv.conf.tail can replace this line" >> "$cf" fi - cat "${cf}" > /etc/resolv.conf + cat "$cf" > /etc/resolv.conf chmod 644 /etc/resolv.conf - rm -f "${cf}" + rm -f "$cf" } add_resolv_conf() { - local x= conf="${signature}\n" + local x= conf="$signature\n" # If we don't have any configuration, remove it - if [ -z "${new_domain_name_servers}" -a \ - -z "${new_domain_name}" -a \ - -z "${new_domain_search}" ]; then + if [ -z "$new_domain_name_servers" -a \ + -z "$new_domain_name" -a \ + -z "$new_domain_search" ]; then remove_resolv_conf return $? fi - if [ -n "${new_domain_name}" ]; then - set -- ${new_domain_name} + if [ -n "$new_domain_name" ]; then + set -- $new_domain_name new_domain_name="$1" - conf="${conf}domain ${new_domain_name}\n" + conf="${conf}domain $new_domain_name\n" # Support RFC violating search in domain - if [ -z "${new_domain_search}" -a -n "$2" ]; then + if [ -z "$new_domain_search" -a -n "$2" ]; then new_domain_search="$@" fi fi - if [ -n "${new_domain_search}" ]; then - conf="${conf}search ${new_domain_search}\n" + if [ -n "$new_domain_search" ]; then + conf="${conf}search $new_domain_search\n" fi for x in ${new_domain_name_servers}; do - conf="${conf}nameserver ${x}\n" + conf="${conf}nameserver $x\n" done if type resolvconf >/dev/null 2>&1; then - [ -n "${metric}" ] && export IF_METRIC="${metric}" - printf "${conf}" | resolvconf -a "${interface}" + [ -n "$metric" ] && export IF_METRIC="$metric" + printf "$conf" | resolvconf -a "$interface" return $? fi - if [ -e "${resolv_conf_dir}/${interface}" ]; then - rm -f "${resolv_conf_dir}/${interface}" + if [ -e "$resolv_conf_dir/$interface" ]; then + rm -f "$resolv_conf_dir/$interface" fi - if [ ! -d "${resolv_conf_dir}" ]; then - mkdir -p "${resolv_conf_dir}" + if [ ! -d "$resolv_conf_dir" ]; then + mkdir -p "$resolv_conf_dir" fi - printf "${conf}" > "${resolv_conf_dir}/${interface}" + printf "$conf" > "$resolv_conf_dir/$interface" build_resolv_conf } remove_resolv_conf() { if type resolvconf >/dev/null 2>&1; then - resolvconf -d "${interface}" -f + resolvconf -d "$interface" -f else - if [ -e "${resolv_conf_dir}/${interface}" ]; then - rm -f "${resolv_conf_dir}/${interface}" + if [ -e "$resolv_conf_dir/$interface" ]; then + rm -f "$resolv_conf_dir/$interface" fi build_resolv_conf fi } -case "${reason}" in +case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) add_resolv_conf;; PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) remove_resolv_conf;; esac diff --git a/dhcpcd-hooks/29-lookup-hostname b/dhcpcd-hooks/29-lookup-hostname index 3214c50d..ce131225 100644 --- a/dhcpcd-hooks/29-lookup-hostname +++ b/dhcpcd-hooks/29-lookup-hostname @@ -2,19 +2,19 @@ lookup_hostname() { - [ -z "${new_ip_address}" ] && return 1 + [ -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}` + h=$(dig +short -x $new_ip_address) if [ $? = 0 ]; then - echo "${h}" | sed 's/\.$//' + echo "$h" | sed 's/\.$//' return 0 fi elif type host >/dev/null 2>&1; then - h=`host ${new_ip_address}` + h=$(host $new_ip_address) if [ $? = 0 ]; then - echo "${h}" \ + echo "$h" \ | sed 's/.* domain name pointer \(.*\)./\1/' return 0 fi @@ -24,11 +24,11 @@ lookup_hostname() set_hostname() { - if [ -z "${new_host_name}" -a -z "${new_fqdn_name}" ]; then + if [ -z "$new_host_name" -a -z "$new_fqdn_name" ]; then export new_host_name="$(lookup_hostname)" fi } -case "${reason}" in +case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) set_hostname;; esac diff --git a/dhcpcd-hooks/30-hostname b/dhcpcd-hooks/30-hostname index 1f73d1fd..0521f49d 100644 --- a/dhcpcd-hooks/30-hostname +++ b/dhcpcd-hooks/30-hostname @@ -4,8 +4,8 @@ need_hostname() { case "$(hostname)" in ""|"(none)"|localhost|localhost.localdomain) - [ -n "${new_host_name}" -o -n "${new_fqdn_name}" ];; - "${old_host_name}"|"${old_fqdn_name}") + [ -n "$new_host_name" -o -n "$new_fqdn_name" ];; + "$old_host_name"|"$old_fqdn_name") true;; *) false;; @@ -15,14 +15,14 @@ need_hostname() set_hostname() { if need_hostname; then - if [ -n "${new_host_name}" ]; then - hostname "${new_host_name}" + if [ -n "$new_host_name" ]; then + hostname "$new_host_name" else - hostname "${new_fqdn_name}" + hostname "$new_fqdn_name" fi fi } -case "${reason}" in +case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) set_hostname;; esac diff --git a/dhcpcd-hooks/50-dhcpcd-compat b/dhcpcd-hooks/50-dhcpcd-compat index bb31fd3b..651bc086 100644 --- a/dhcpcd-hooks/50-dhcpcd-compat +++ b/dhcpcd-hooks/50-dhcpcd-compat @@ -1,41 +1,41 @@ # Compat enter hook shim for older dhcpcd versions -IPADDR=${new_ip_address} -INTERFACE=${interface} -NETMASK=${new_subnet_mask} -BROADCAST=${new_broadcast_address} -NETWORK=${new_network_number} -DHCPSID=${new_dhcp_server_identifier} -GATEWAYS=${new_routers} -DNSSERVERS=${new_domain_name_servers} -DNSDOMAIN=${new_domain_name} -DNSSEARCH=${new_domain_search} -NISDOMAIN=${new_nis_domain} -NISSERVERS=${new_nis_servers} -NTPSERVERS=${new_ntp_servers} +IPADDR=$new_ip_address +INTERFACE=$interface +NETMASK=$new_subnet_mask +BROADCAST=$new_broadcast_address +NETWORK=$new_network_number +DHCPSID=$new_dhcp_server_identifier +GATEWAYS=$new_routers +DNSSERVERS=$new_domain_name_servers +DNSDOMAIN=$new_domain_name +DNSSEARCH=$new_domain_search +NISDOMAIN=$new_nis_domain +NISSERVERS=$new_nis_servers +NTPSERVERS=$new_ntp_servers GATEWAY= -for x in ${new_routers}; do - GATEWAY="${GATEWAY}${GATEWAY:+,}${x}" +for x in $new_routers; do + GATEWAY="$GATEWAY${GATEWAY:+,}$x" done DNS= -for x in ${new_domain_name_servers}; do - DNS="${DNS}${DNS:+,}${x}" +for x in $new_domain_name_servers; do + DNS="$DNS${DNS:+,}$x" done x="down" -case "${reason}" in +case "$reason" in RENEW) x="up";; BOUND|INFORM|REBIND|REBOOT|TEST|TIMEOUT|IPV4LL) x="new";; esac -if [ "${reason}" != "down" ]; then - rm -f /var/lib/dhcpcd-"${INTERFACE}".info +if [ "$reason" != "down" ]; then + rm -f /var/lib/dhcpcd-"$INTERFACE".info for x in IPADDR INTERFACE NETMASK BROADCAST NETWORK DHCPSID GATEWAYS \ DNSSERVERS DNSDOMAIN DNSSEARCH NISDOMAIN NISSERVERS \ NTPSERVERS GATEWAY DNS; do - eval echo "${x}=\'\$${x}\'" >> /var/lib/dhcpcd-"${INTERFACE}".info + eval echo "$x=\'\$$x\'" >> /var/lib/dhcpcd-"$INTERFACE".info done fi -set -- /var/lib/dhcpcd-"${INTERFACE}".info "${x}" +set -- /var/lib/dhcpcd-"$INTERFACE".info "$x" diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf index 2135dc7e..e569cf1e 100644 --- a/dhcpcd-hooks/50-ntp.conf +++ b/dhcpcd-hooks/50-ntp.conf @@ -18,58 +18,58 @@ elif [ -x /usr/local/etc/rc.d/ntpd ]; then ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd status && /usr/local/etc/rc.d/ntpd restart" fi -ntp_conf_dir="${state_dir}/ntp.conf" +ntp_conf_dir="$state_dir/ntp.conf" ntp_conf=${NTP_CONF:-/etc/ntp.conf} build_ntp_conf() { - local cf="${state_dir}/ntp.conf.${interface}" + local cf="$state_dir/ntp.conf.$interface" local interfaces= header= srvs= servers= x= # Build a list of interfaces - interfaces=$(list_interfaces "${ntp_conf_dir}") + interfaces=$(list_interfaces "$ntp_conf_dir") - if [ -n "${interfaces}" ]; then + if [ -n "$interfaces" ]; then # Build the header for x in ${interfaces}; do - header="${header}${header:+, }${x}" + header="$header${header:+, }$x" done # Build a server list - srvs=$(cd "${ntp_conf_dir}"; - key_get_value "server " ${interfaces}) - if [ -n "${srvs}" ]; then - for x in $(uniqify ${srvs}); do - servers="${servers}server ${x}\n" + srvs=$(cd "$ntp_conf_dir"; + key_get_value "server " $interfaces) + if [ -n "$srvs" ]; then + for x in $(uniqify $srvs); do + servers="${servers}server $x\n" done fi fi # Merge our config into ntp.conf - [ -e "${cf}" ] && rm -f "${cf}" - remove_markers "${signature_base}" "${signature_base_end}" \ - "${ntp_conf}" > "${cf}" - if [ -n "${servers}" ]; then - echo "${signature_base}${header:+ ${from} }${header}" >> "${cf}" - printf "${search}${servers}" >> "${cf}" - echo "${signature_base_end}${header:+ ${from} }${header}" >> "${cf}" + [ -e "$cf" ] && rm -f "$cf" + remove_markers "$signature_base" "$signature_base_end" \ + "$ntp_conf" > "$cf" + if [ -n "$servers" ]; then + echo "$signature_base${header:+ $from }$header" >> "$cf" + printf "$search$servers" >> "$cf" + echo "$signature_base_end${header:+ $from }$header" >> "$cf" fi # If we changed anything, restart ntpd - if change_file "${ntp_conf}" "${cf}"; then - [ -n "${ntpd_restart_cmd}" ] && eval ${ntpd_restart_cmd} + if change_file "$ntp_conf" "$cf"; then + [ -n "$ntpd_restart_cmd" ] && eval $ntpd_restart_cmd fi } add_ntp_conf() { - local cf="${ntp_conf_dir}/${interface}" x= + local cf="$ntp_conf_dir/$interface" x= - [ -e "${cf}" ] && rm "${cf}" - [ -d "${ntp_conf_dir}" ] || mkdir -p "${ntp_conf_dir}" - if [ -n "${new_ntp_servers}" ]; then - for x in ${new_ntp_servers}; do - echo "server ${x}" >> "${cf}" + [ -e "$cf" ] && rm "$cf" + [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir" + if [ -n "$new_ntp_servers" ]; then + for x in $new_ntp_servers; do + echo "server $x" >> "$cf" done fi build_ntp_conf @@ -77,13 +77,13 @@ add_ntp_conf() remove_ntp_conf() { - if [ -e "${ntp_conf_dir}/${interface}" ]; then - rm "${ntp_conf_dir}/${interface}" + if [ -e "$ntp_conf_dir/$interface" ]; then + rm "$ntp_conf_dir/$interface" fi build_ntp_conf } -case "${reason}" in +case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) add_ntp_conf add;; PREINIT|EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) remove_ntp_conf del;; esac diff --git a/dhcpcd-hooks/50-yp.conf b/dhcpcd-hooks/50-yp.conf index 1b83d61d..4bdd0623 100644 --- a/dhcpcd-hooks/50-yp.conf +++ b/dhcpcd-hooks/50-yp.conf @@ -8,43 +8,43 @@ ypbind_pid() make_yp_conf() { - [ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0 - local cf=/etc/yp.conf."${interface}" prefix= x= pid= - rm -f "${cf}" - echo "${signature}" > "${cf}" - if [ -n "${new_nis_domain}" ]; then - domainname "${new_nis_domain}" - if [ -n "${new_nis_servers}" ]; then - prefix="domain ${new_nis_domain} server " + [ -z "$new_nis_domain" -a -z "$new_nis_servers" ] && return 0 + local cf=/etc/yp.conf."$interface" prefix= x= pid= + rm -f "$cf" + echo "$signature" > "$cf" + if [ -n "$new_nis_domain" ]; then + domainname "$new_nis_domain" + if [ -n "$new_nis_servers" ]; then + prefix="domain $new_nis_domain server " else - echo "domain ${new_nis_domain} broadcast" >> "${cf}" + echo "domain $new_nis_domain broadcast" >> "$cf" fi else prefix="ypserver " fi - for x in ${new_nis_servers}; do - echo "${prefix}${x}" >> "${cf}" + for x in $new_nis_servers; do + echo "$prefix$x" >> "$cf" done save_conf /etc/yp.conf - cat "${cf}" > /etc/yp.conf - rm -f "${cf}" + cat "$cf" > /etc/yp.conf + rm -f "$cf" pid="$(ypbind_pid)" - if [ -n "${pid}" ]; then - kill -HUP "${pid}" + if [ -n "$pid" ]; then + kill -HUP "$pid" fi } restore_yp_conf() { - [ -n "${old_nis_domain}" ] && domainname "" + [ -n "$old_nis_domain" ] && domainname "" restore_conf /etc/yp.conf || return 0 local pid="$(ypbind_pid)" - if [ -n "${pid}" ]; then - kill -HUP "${pid}" + if [ -n "$pid" ]; then + kill -HUP "$pid" fi } -case "${reason}" in +case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) make_yp_conf;; EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP) restore_yp_conf;; esac diff --git a/dhcpcd-hooks/90-NetworkManager b/dhcpcd-hooks/90-NetworkManager deleted file mode 100644 index c4d69fec..00000000 --- a/dhcpcd-hooks/90-NetworkManager +++ /dev/null @@ -1,8 +0,0 @@ -# Hook for NetworkManager-0.7.0 -# NOTE: NetworkManager will override the script dhcpcd calls, so this hook -# only makes sense if NetworkManager is patched NOT to override the -# script dhcpcd would call. - -if [ -x /usr/libexec/nm-dhcp-client.action ]; then - /usr/libexec/nm-dhcp-client.action -fi diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index ca8fe94a..35ce93fb 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -2,26 +2,24 @@ # dhcpcd client configuration script # Handy variables and functions for our hooks to use -from="from" +from=from signature_base="# Generated by dhcpcd" -signature="${signature_base} ${from} ${interface}" +signature="$signature_base $from $interface" signature_base_end="# End of dhcpcd" -signature_end="${signature_base_end} ${from} ${interface}" -state_dir="/var/run/dhcpcd" +signature_end="$signature_base_end $from $interface" +state_dir=/var/run/dhcpcd # Ensure that all arguments are unique uniqify() { - local result= - - while [ -n "$1" ]; do - case " ${result} " in - *" $1 "*);; - *) result="${result}${result:+ }$1";; + local result= i= + for i; do + case " $result " in + *" $i "*);; + *) result="$result $i";; esac - shift done - echo "${result}" + echo "${result# *}" } # List interface config files in a dir @@ -31,20 +29,20 @@ uniqify() list_interfaces() { local i= x= ifaces= - for i in ${interface_order}; do - [ -e "$1"/${i} ] && ifaces="${ifaces}${ifaces:+ }${i}" + for i in $iforder; do + [ -e "$1/$i" ] && ifaces="$ifaces${ifaces:+ }$i" done for x in "$1"/*; do - [ -e "${x}" ] || continue - for i in ${interface_order}; do - if [ ${i} = "${x##*/}" ]; then + [ -e "$x" ] || continue + for i in $iforder; do + if [ $i = "${x##*/}" ]; then unset x break fi done - [ -n "${x}" ] && ifaces="${ifaces}${ifaces:+ }${x##*/}" + [ -n "$x" ] && ifaces="$ifaces${ifaces:+ }${x##*/}" done - echo "${ifaces}" + echo "$ifaces" } # We normally use sed to extract values using a key from a list of files @@ -59,10 +57,10 @@ key_get_value() else for x; do while read line; do - case "${line}" in - "${key}"*) echo "${line##${key}}";; + case "$line" in + "$key"*) echo "${line##$key}";; esac - done < "${x}" + done < "$x" done fi } @@ -75,16 +73,16 @@ remove_markers() shift; shift if type sed >/dev/null 2>&1; then - sed "/^${m1}/,/^${m2}/d" $@ + sed "/^$m1/,/^$m2/d" $@ else for x; do while read line; do - case "${line}" in - "${m1}"*) in_marker=1;; - "${m2}"*) in_marker=0;; - *) [ ${in_marker} = 0 ] && echo "${line}";; + case "$line" in + "$m1"*) in_marker=1;; + "$m2"*) in_marker=0;; + *) [ $in_marker = 0 ] && echo "$line";; esac - done < "${x}" + done < "$x" done fi } @@ -114,17 +112,17 @@ change_file() save_conf() { if [ -f "$1" ]; then - rm -f "${1}-pre.${interface}" - cat "$1" > "${1}-pre.${interface}" + rm -f "$1-pre.$interface" + cat "$1" > "$1-pre.$interface" fi } # Restore a config file restore_conf() { - [ -f "${1}-pre.${interface}" ] || return 1 - cat "${1}-pre.${interface}" > "$1" - rm -f "${1}-pre.${interface}" + [ -f "$1-pre.$interface" ] || return 1 + cat "$1-pre.$interface" > "$1" + rm -f "$1-pre.$interface" } @@ -137,14 +135,14 @@ for hook in \ @HOOKDIR@/* \ @SYSCONFDIR@/dhcpcd.exit-hook do - for skip in ${skip_hooks}; do - case "${hook}" in - */"${skip}") continue 2;; - */[0-9][0-9]"-${skip}") continue 2;; - */[0-9][0-9]"-${skip}.sh") continue 2;; + for skip in $skip_hooks; do + case "$hook" in + */"$skip") continue 2;; + */[0-9][0-9]"-$skip") continue 2;; + */[0-9][0-9]"-$skip.sh") continue 2;; esac done - if [ -f "${hook}" ]; then - . "${hook}" + if [ -f "$hook" ]; then + . "$hook" fi done