summaryrefslogtreecommitdiffstats
path: root/dhcpcd-run-hooks.in
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-08-15 09:07:56 +0000
committerRoy Marples <roy@marples.name>2008-08-15 09:07:56 +0000
commit7bcaeef3a2cba652e43d4c3459240fb333875637 (patch)
tree571a200e9b7cce502111fa892c9d07d4a4047bbb /dhcpcd-run-hooks.in
parenta01c3091db8e36d11547f327e7e46330edc94cbf (diff)
downloaddhcpcd-7bcaeef3a2cba652e43d4c3459240fb333875637.tar.xz
sed may not always be available, so use shell loops to replicate behaviour in this case
Diffstat (limited to 'dhcpcd-run-hooks.in')
-rw-r--r--dhcpcd-run-hooks.in42
1 files changed, 42 insertions, 0 deletions
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in
index 47e6316d..2bb84bab 100644
--- a/dhcpcd-run-hooks.in
+++ b/dhcpcd-run-hooks.in
@@ -36,6 +36,48 @@ list_interfaces()
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()