From 296e9fa1cf971cdf8ee5b3ee212abf6947f182f3 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 25 Jun 2008 06:47:26 +0000 Subject: added feature to revert the setup-alpine-web --- setup-alpine-web | 140 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 40 deletions(-) diff --git a/setup-alpine-web b/setup-alpine-web index 7fdfad8..1573c85 100644 --- a/setup-alpine-web +++ b/setup-alpine-web @@ -1,7 +1,11 @@ #!/bin/sh +PROGRAM=${0##*/} + BRNUM=0 CNET="10.$BRNUM.0" +HNAME=alpine +DOMAIN="bootstrap.invalid" IFACE_LIST=/tmp/interfaces get_interfaces() { @@ -16,7 +20,7 @@ make_dhcp_subnet() { local network="$CNET.$num" local netmask=255.255.255.240 local router="$CNET.$(( $num + 1 ))" - local poolstart="$CNET.$(( $num + 2 ))" + local poolstart="$CNET.$(( $num + 3 ))" local poolend="$CNET.$(( $num + 14 ))" echo "subnet $network netmask $netmask {" echo " range $poolstart $poolend;" @@ -29,57 +33,113 @@ make_dhcp_subnet() { } make_dhcp_global() { - echo "option domain-name \"bootstrap.invalid\";" + echo "option domain-name \"$DOMAIN\";" echo "option domain-name-servers $CNET.1;" echo "ddns-update-style none;" echo "" } +do_setup() { + local i + local count + hostname $HNAME + + # install needed packages + apk_add dhcp iptables "$@" + + # config dhcp server + make_dhcp_global > /etc/dhcp/dhcpd.conf + count=0 + for i in $(get_interfaces); do + # maximum 16 network interfaces + [ $count -ge 16 ] && break + make_dhcp_subnet $(( $count * 16 )) $i >> /etc/dhcp/dhcpd.conf + count=$(( $count + 1 )) + done + + /etc/init.d/syslog start + /etc/init.d/dhcpd start + FORCE_SETUP_WEBCONF=yes setup-webconf apk "$@" + + # set up http listener/forwarder + mkdir -p /var/www/redirect + cat </var/www/redirect/index.html + + + + + + +EOF + echo "E404:/var/www/redirect/index.html" > /etc/httpd.conf + echo "HTTPD_OPTS=\"-h /var/www/redirect\"" > /etc/conf.d/httpd + + /etc/init.d/httpd start + + # dummy dns + echo "* $CNET.1" > /etc/dnsd.conf + /etc/init.d/dnsd start +} + +# reconf dhcp and kill all interfaces but $1 +do_reset() { + local iface=$1 + local i + local oldip=$(ip addr show dev $iface | awk '/inet / { print $2 } ' | head -n 1) + + # setup new dhcpd.conf + make_dhcp_global > /etc/dhcp/dhcpd.conf + cat >> /etc/dhcp/dhcpd.conf < /etc/dhcp/dhcpd.conf -count=0 -for i in $(get_interfaces); do - # maximum 16 network interfaces - [ $count -ge 16 ] && break - make_dhcp_subnet $(( $count * 16 )) $i >> /etc/dhcp/dhcpd.conf - count=$(( $count + 1 )) -done - -/etc/init.d/syslog start -/etc/init.d/dhcpd start -FORCE_SETUP_WEBCONF=yes setup-webconf apk "$@" - -# set up http listener/forwarder -mkdir -p /var/www/redirect -cat </var/www/redirect/index.html - - - - - - - -EOF -echo "E404:/var/www/redirect/index.html" > /etc/httpd.conf -echo "HTTPD_OPTS=\"-h /var/www/redirect\"" > /etc/conf.d/httpd -/etc/init.d/httpd start +if [ -z "$KEEP_IFACE" ]; then + do_setup "$@" + exit 0 +fi -# dummy dns -echo "* $CNET.1" > /etc/dnsd.conf -/etc/init.d/dnsd start +do_reset "$KEEP_IFACE" -exit 0 -- cgit v1.2.3