summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2008-06-25 06:47:26 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2008-06-25 06:47:26 +0000
commit296e9fa1cf971cdf8ee5b3ee212abf6947f182f3 (patch)
tree663e79b28fcaf1e7ff527badf12af9423dce5fdc
parentf1b3b2d2f6e3e1dd7ccf97b200a605e62f08b9cf (diff)
downloadalpine-conf-296e9fa1cf971cdf8ee5b3ee212abf6947f182f3.tar.bz2
alpine-conf-296e9fa1cf971cdf8ee5b3ee212abf6947f182f3.tar.xz
added feature to revert the setup-alpine-web
-rw-r--r--setup-alpine-web140
1 files 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 <<EOF >/var/www/redirect/index.html
+<html>
+ <head>
+ <meta HTTP-EQUIV="REFRESH" content="0; url=https://$(hostname)">
+ </head>
+ <body></body>
+</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 <<EOF
+subnet $CNET.0 netmask 255.255.255.0 {
+ range $CNET.3 $CNET.14;
+ option routers $CNET.1;
+}
+EOF
+
+ # shut down all interfaces
+ for i in $(get_interfaces); do
+ ip addr flush dev $i
+ [ "$i" = "$iface" ] && continue
+ ip link set dev $i down
+ done
+
+ # bring interface up again and flush iptables
+ ip addr add $oldip dev $iface
+ ip addr add $CNET.1/24 dev $iface
+ iptables -t nat -F PREROUTING
+
+ /etc/init.d/dhcpd restart
+}
+
+usage() {
+ cat <<EOF
+usage: $PROGRAM [-c X.Y.Z] [-H HOSTNAME] [-R IFACE]
+options:
+ -c Use X.Y.Z as network prefix rather than $CNET
+ -H set hostname
+ -R reset previously configured initerfaces and configure IFACE
+
+EOF
+ exit 0
+}
+
# parse args
-while getopts "b:" opts; do
+while getopts "b:c:d:H:hR:" opts; do
case "$opts" in
b) BRNUM="$OPTARG";;
+ c) CNET="$OPTARG";;
+ d) DOMAIN="$OPTARG";;
+ H) HNAME="$OPTARG";;
h) usage;;
+ R) KEEP_IFACE="$OPTARG";;
esac
done
shift $(( $OPTIND - 1 ))
-hostname alpine
-
-# install needed packages
-apk_add dhcp iptables tinydns acf-apk "$@"
-
-# 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 <<EOF >/var/www/redirect/index.html
-<html>
-<head>
-<meta HTTP-EQUIV="REFRESH" content="0; url=https://$(hostname)">
-</head>
-<body>
-</body>
-</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