aboutsummaryrefslogtreecommitdiffstats
path: root/dhcpcd-run-hooks.in
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:11 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:11 -0800
commit4c5a5fb53bccceff331bae70f748bf9b4609fe0a (patch)
treed6ae69d0d3f4a4d760a3254ec326bca4a8afacfe /dhcpcd-run-hooks.in
parente95877ecfa1170d77b1ec1f66752725cdda01b64 (diff)
downloadexternal_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.zip
external_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.tar.gz
external_dhcpcd-4c5a5fb53bccceff331bae70f748bf9b4609fe0a.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'dhcpcd-run-hooks.in')
-rw-r--r--dhcpcd-run-hooks.in110
1 files changed, 105 insertions, 5 deletions
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in
index 7fd8b09..1e5d5b3 100644
--- a/dhcpcd-run-hooks.in
+++ b/dhcpcd-run-hooks.in
@@ -1,8 +1,104 @@
#!/bin/sh
# dhcpcd client configuration script
-# Handy functions for our hooks to use
-signature="# Generated by dhcpcd for ${interface}"
+# Handy variables and functions for our hooks to use
+from="from"
+signature_base="# Generated by dhcpcd"
+signature="${signature_base} ${from} ${interface}"
+signature_base_end="# End of 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";;
+ esac
+ shift
+ done
+ echo "${result}"
+}
+
+# List interface config files in a dir
+# We may wish to control the order at some point rather than just lexical
+list_interfaces()
+{
+ local x= interfaces=
+ for x in "$1"/*; do
+ [ -e "${x}" ] || continue
+ interfaces="${interfaces}${interfaces:+ }${x##*/}"
+ done
+ echo "${interfaces}"
+}
+
+# We normally use sed to extract values using a key from a list of files
+# but sed may not always be available at the time.
+key_get_value()
+{
+ local key="$1" value= x= line=
+
+ shift
+ if type sed >/dev/null 2>&1; then
+ sed -n "s/^${key}//p" $@
+ else
+ for x; do
+ while read line; do
+ case "${line}" in
+ "${key}"*) echo "${line##${key}}";;
+ esac
+ done < "${x}"
+ done
+ fi
+}
+
+# We normally use sed to remove markers from a configuration file
+# but sed may not always be available at the time.
+remove_markers()
+{
+ local m1="$1" m2="$2" x= line= in_marker=0
+
+ shift; shift
+ if type sed >/dev/null 2>&1; then
+ 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}";;
+ esac
+ done < "${x}"
+ done
+ fi
+}
+
+# Compare two files
+# It different, replace first with second otherwise remove second
+change_file()
+{
+ if type cmp >/dev/null 2>&1; then
+ cmp -s "$1" "$2"
+ elif type diff >/dev/null 2>&1; then
+ diff -q "$1" "$2" >/dev/null
+ else
+ # Hopefully we're only working on small text files ...
+ [ "$(cat "$1")" = "$(cat "$2")" ]
+ fi
+ if [ $? -eq 0 ]; then
+ rm -f "$2"
+ return 1
+ fi
+ mv -f "$2" "$1"
+ return 0
+}
+
+# Save a config file
save_conf()
{
if [ -f "$1" ]; then
@@ -10,6 +106,8 @@ save_conf()
mv -f "$1" "$1"-pre."${interface}"
fi
}
+
+# Restore a config file
restore_conf()
{
[ -f "$1"-pre."${interface}" ] || return 1
@@ -17,13 +115,15 @@ restore_conf()
mv -f "$1"-pre."${interface}" "$1"
}
+
# We source each script into this one so that scripts run earlier can
# remove variables from the environment so later scripts don't see them.
-# Thus, the user can create their dhcpcd.hook script to configure
+# Thus, the user can create their dhcpcd.enter/exit-hook script to configure
# /etc/resolv.conf how they want and stop the system scripts ever updating it.
for hook in \
- @SYSCONFDIR@/dhcpcd.hook \
- @HOOKDIR@/*
+ @SYSCONFDIR@/dhcpcd.enter-hook \
+ @HOOKDIR@/* \
+ @SYSCONFDIR@/dhcpcd.exit-hook
do
for skip in ${skip_hooks}; do
case "${hook}" in