#!/bin/sh
#
# turn a
#   - G3
#   - pcmcia-pci adapter
#   - wireless pcmcia card
#   - ubuntu-breezy live cd-r
# into a
#   - wireless gateway to the open hotspot
#     on the other side of the street
#
# j
#

#Configure Internet Access
interent_dev=eth1
iwconfig $interent_dev essid NETGEAR-1 
ifconfig $interent_dev up
dhclient $interent_dev

#Configure Shared Network
dns_server=192.168.1.1
share_dev=eth0
share_network=192.168.42
share_netmask=255.255.255.0
ifconfig $share_dev $share_network.1 netmask $share_netmask up

#Install Services
apt-get install dhcp3-server ssh-server

#NAT
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/ip_dynaddr
iptables -t nat -F
iptables -t nat -A POSTROUTING -o $interent_dev -j MASQUERADE

#DHCP
cat << EOF > /tmp/dhcpd.conf
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet $share_network.0 netmask $share_netmask {
	range $share_network.10 $share_network.250;
    option routers $share_network.1;
	option domain-name-servers $dns_server;
}
EOF
mkdir -p /var/run/dhcp3-server
chown dhcpd:dhcpd /var/run/dhcp3-server
/usr/sbin/dhcpd3 -q $share_dev -pf /tmp/dhcp.pid -cf /tmp/dhcpd.conf &
