diff options
| author | Roy Marples <roy@marples.name> | 2008-08-15 03:22:21 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-08-15 03:22:21 +0000 |
| commit | a5ea73e73f08db717425db8c2894d599f6faf603 (patch) | |
| tree | f6a21a824a112176e31936d2f9d1e34a95065283 /dhcpcd-run-hooks.in | |
| parent | 68e04b443823cfd04b747a8accd4bdea4f6f74f2 (diff) | |
| download | dhcpcd-a5ea73e73f08db717425db8c2894d599f6faf603.tar.xz | |
Remove the append/clean framework and prefer a store and merge
approach. It's more work, but the end result looks cleaner.
Diffstat (limited to 'dhcpcd-run-hooks.in')
| -rw-r--r-- | dhcpcd-run-hooks.in | 86 |
1 files changed, 30 insertions, 56 deletions
diff --git a/dhcpcd-run-hooks.in b/dhcpcd-run-hooks.in index 4a19af12..00a555b2 100644 --- a/dhcpcd-run-hooks.in +++ b/dhcpcd-run-hooks.in @@ -2,10 +2,11 @@ # dhcpcd client configuration script # Handy variables and functions for our hooks to use -signature_base="# Generated by dhcpcd from " -signature="${signature_base}${interface}" -signature_base_end="# End of dhcpcd from " -signature_end="${signature_base_end}${interface}" +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 @@ -23,62 +24,35 @@ uniqify() echo "${result}" } -# Clean a configuration file of our current signature and stale ones -clean_conf() +# List interface config files in a dir +# We may wish to control the order at some point rather than just lexical +list_interfaces() { - local cf=$1 cft="$1.tmp" x= m1= m2= - - if [ -f "${cf}" ]; then - # Remove our old entry - m1="^${signature}$" - m2="^${signature_end}$" - rm -f "${cft}" "${cft}.tmp" - sed "/${m1}/,/${m2}/d" "${cf}" > "${cft}" - # Remove stale entries - m1="^${siganture_base} " - for x in $(sed -n "s/${m1}//p" "${cft}"); do - if [ ! -s /var/run/dhcpcd-${x}.pid ]; then - m1="^${signtaure_base}${x}$" - m2="^${signature_base_end}${x}$" - sed "/${m1}/,/${m2}/d" "${cft}" >"${cft}".tmp - mv -f "${cft}".tmp "${cft}" - fi - done - # If files are identical then don't replace and return 1 - # to show that no cleaning took place - if type cmp >/dev/null 2>&1; then - cmp -s "${cf}" "${cft}" - elif type diff >/dev/null 2>&1; then - diff -q "${cf}" "${cft}" >/dev/null - else - false - fi - if [ $? -eq 0 ]; then - rm -f "${cft}" - return 1 - fi - mv -f "${cft}" "${cf}" - return 0 - fi -} - -# Append our config to the end of a file, surrouned by our signature -append_conf() -{ - echo "${signature}" >> "$1" - echo "$2" >> "$1" - echo "${signature_end}" >> "$1" + local x= interfaces= + for x in "$1"/*; do + [ -e "${x}" ] || continue + interfaces="${interfaces}${interfaces:+ }${x##*/}" + done + echo "${interfaces}" } -# Prepend our config to the start of a file, surrouned by our signature -prepend_conf() +# Compare two files +# It different, replace first with second otherwise remove second +change_file() { - rm -f "$1.${interface}" - echo "${signature}" > "$1.${interface}" - echo "$2" >> "$1.${interface}" - echo "${signature_end}" >> "$1.${interface}" - cat "$1" >> "$1.${interface}" - mv -f "$1.${interface}" "$1" + 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 + false + fi + if [ $? -eq 0 ]; then + rm -f "$2" + return 1 + fi + mv -f "$2" "$1" + return 0 } # Save a config file |
