summaryrefslogtreecommitdiffstats
path: root/setup-alpine-web
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2008-05-21 14:01:23 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2008-05-21 14:01:23 +0000
commit4ade8ccfc6cb761adec205285f1866c8265e57e2 (patch)
tree859f9c96dfb088202b51bc57cdc0b6936486c3e7 /setup-alpine-web
parent70faa4b15c9fd02fc4f4c1595b53bf5adf34e4a4 (diff)
downloadalpine-conf-4ade8ccfc6cb761adec205285f1866c8265e57e2.tar.bz2
alpine-conf-4ade8ccfc6cb761adec205285f1866c8265e57e2.tar.xz
release 1.5. added setup-alpine-web
Diffstat (limited to 'setup-alpine-web')
-rw-r--r--setup-alpine-web83
1 files changed, 83 insertions, 0 deletions
diff --git a/setup-alpine-web b/setup-alpine-web
new file mode 100644
index 0000000..a24ca12
--- /dev/null
+++ b/setup-alpine-web
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+BRNUM=0
+CNET="10.$BRNUM.0"
+IFACE_LIST=/tmp/interfaces
+
+get_interfaces() {
+ [ -f "$IFACE_LIST" ] || tail -n +3 /proc/net/dev \
+ | awk -F: '$1 !~ /lo/ { print $1 }' > "$IFACE_LIST"
+ cat "$IFACE_LIST"
+}
+
+make_dhcp_subnet() {
+ local num=$1
+ local iface=$2
+ local network="$CNET.$num"
+ local netmask=255.255.255.240
+ local router="$CNET.$(( $num + 1 ))"
+ local poolstart="$CNET.$(( $num + 2 ))"
+ local poolend="$CNET.$(( $num + 14 ))"
+ echo "subnet $network netmask $netmask {"
+ echo " range $poolstart $poolend;"
+ echo " option routers $router;"
+ echo "}"
+ echo ""
+ ip addr add $router/28 dev $iface || echo "Failed to set address $router/28 on $iface" >&2
+ ip link set dev $iface up
+ iptables -t nat -A PREROUTING -i $iface -j DNAT --to-destination $router
+}
+
+make_dhcp_global() {
+ echo "option domain-name \"bootstrap.invalid\";"
+ echo "option domain-name-servers $CNET.1;"
+ echo "ddns-update-style none;"
+ echo ""
+}
+
+# parse args
+while getopts "b:" opts; do
+ case "$opts" in
+ b) BRNUM="$OPTARG";;
+ h) usage;;
+ 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
+httpd -h /var/www/redirect
+
+# dummy dns
+echo "* $CNET.1" > /etc/dnsd.conf
+/etc/init.d/dnsd start
+
+exit 0