summaryrefslogtreecommitdiffstats
path: root/main/busybox-initscripts/default.script
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-08-16 14:14:48 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-08-16 14:17:11 +0000
commit5b3174f206ce3e65e911086ac09cfd1e86c3e46f (patch)
tree3b7da23c566d41e54e632c010b721f0f25516ab2 /main/busybox-initscripts/default.script
parenta3c1fbe8ae00e4dc4cd24356113f09eba8771b40 (diff)
downloadaports-5b3174f206ce3e65e911086ac09cfd1e86c3e46f.tar.bz2
aports-5b3174f206ce3e65e911086ac09cfd1e86c3e46f.tar.xz
main/busybox-initscripts: move udhcpc script from alpine-baselayout
Does not belong in the baselayout package
Diffstat (limited to 'main/busybox-initscripts/default.script')
-rw-r--r--main/busybox-initscripts/default.script108
1 files changed, 108 insertions, 0 deletions
diff --git a/main/busybox-initscripts/default.script b/main/busybox-initscripts/default.script
new file mode 100644
index 000000000..c6cfbc5be
--- /dev/null
+++ b/main/busybox-initscripts/default.script
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+# script for udhcpc
+# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
+
+UDHCPC="/etc/udhcpc"
+UDHCPC_CONF="$UDHCPC/udhcpc.conf"
+
+RESOLV_CONF="/etc/resolv.conf"
+[ -f $UDHCPC_CONF ] && . $UDHCPC_CONF
+
+export broadcast
+export dns
+export domain
+export interface
+export ip
+export mask
+export metric
+export router
+export subnet
+
+export PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+run_scripts() {
+ local dir=$1
+ if [ -d $dir ]; then
+ for i in $dir/*; do
+ [ -f $i ] && $i
+ done
+ fi
+}
+
+deconfig() {
+ ip addr flush dev $interface
+}
+
+routes() {
+ [ -z "$router" ] && return
+ local gw metric
+ while ip route del default via dev $interface 2>/dev/null; do
+ :
+ done
+ metric=0
+ for gw in $router; do
+ route add default gw $gw dev $interface metric $metric
+ metric=$(( $metric + 1 ))
+ done
+}
+
+resolvconf() {
+ local i
+ if [ "$RESOLV_CONF" = "no" ] || [ "$RESOLV_CONF" = "NO" ] \
+ || [ -z "$RESOLV_CONF" ]; then
+ return
+ fi
+ echo -n > "$RESOLV_CONF"
+ [ -n "$domain" ] && echo "search $domain" >> "$RESOLV_CONF"
+ for i in $dns; do
+ echo "nameserver $i" >> "$RESOLV_CONF"
+ done
+}
+
+bound() {
+ ip addr add $ip/$mask dev $interface
+ ip link set dev $interface up
+ routes
+ resolvconf
+}
+
+renew() {
+ if ! ip addr show dev $interface | grep $ip/$mask; then
+ ip addr flush dev $interface
+ ip addr add $ip/$mask dev $interface
+ fi
+
+ local i
+ for i in $router; do
+ if ! ip route show | grep ^default | grep $i; then
+ routes
+ break
+ fi
+ done
+
+ if ! grep "^search $domain"; then
+ resolvconf
+ return
+ fi
+ for i in $dns; do
+ if ! grep "^nameserver $i"; then
+ resolvconf
+ return
+ fi
+ done
+}
+
+case "$1" in
+ deconfig|renew|bound)
+ run_scripts $UDHCPC/pre-$1
+ $1
+ run_scripts $UDHCPC/post-$1
+ ;;
+ *)
+ echo "Error: this script should be called from udhcpc" >&2
+ exit 1
+ ;;
+esac
+exit 0
+