Skip to content

Commit

Permalink
Merge pull request #111 from tomeshnet/radvd-fix
Browse files Browse the repository at this point in the history
Radvd fix
  • Loading branch information
benhylau authored Nov 1, 2017
2 parents 4d1453f + cb4869c commit b015f97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
27 changes: 18 additions & 9 deletions scripts/hostapd/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ set -e

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Create radvd.conf before installing radvd, installation fails without it
if ! [ -f /etc/radvd.conf ]; then
sudo cp "$BASE_DIR/radvd.conf" /etc/radvd.conf
fi

# Install packages to run IEEE 802.11 Access Point
sudo apt-get install hostapd radvd dnsmasq iptables -y

# Configure wlan0 interface
sudo cp /etc/network/interfaces /etc/network/interfaces.backup
START=$(grep -n "allow-hotplug wlan0" /etc/network/interfaces | awk '{ print $1 }' FS=':')
if [ ! -z $START ]; then
END=$(expr $START + 3)
sudo sed -i "${START},${END}d" /etc/network/interfaces
fi
sudo mv /etc/network/interfaces /etc/network/interfaces.bak
sudo touch /etc/network/interfaces

echo "source-directory /etc/network/interfaces.d" | sudo tee --append /etc/network/interfaces > /dev/null
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "auto lo" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface lo inet loopback" | sudo tee --append /etc/network/interfaces > /dev/nul
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "allow-hotplug wlan0" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface wlan0 inet static" | sudo tee --append /etc/network/interfaces > /dev/null
Expand All @@ -25,11 +30,12 @@ echo " broadcast 10.0.0.255" | sudo tee --append /etc/network/interfaces > /d
echo "iface wlan0 inet6 static" | sudo tee --append /etc/network/interfaces > /dev/null
echo " address fdfc::2" | sudo tee --append /etc/network/interfaces > /dev/null
echo " netmask 64" | sudo tee --append /etc/network/interfaces > /dev/null
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "allow-hotplug eth0" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface eth0 inet dhcp" | sudo tee --append /etc/network/interfaces > /dev/null

# Enable packet forwarding
sudo cp /etc/sysctl.conf /etc/sysctl.conf.backup
sudo cp /etc/sysctl.conf /etc/sysctl.conf.bak
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sed -i 's/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=1/' /etc/sysctl.conf

Expand Down Expand Up @@ -75,18 +81,21 @@ fi

# Configure DHCP with dnsmasq
if [ -f /etc/dnsmasq.conf ]; then
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
fi
sudo cp "$BASE_DIR/dnsmasq.conf" /etc/dnsmasq.conf

if [ -f /etc/dhcpcd.conf ]; then
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
sudo echo "" | sudo tee --append /etc/dhcpcd.conf > /dev/null
sudo echo "denyinterfaces wlan0" | sudo tee --append /etc/dhcpcd.conf > /dev/null
fi

# Configure IPv6 router advertisement with radvd
sudo cp "$BASE_DIR/radvd.conf" /etc/radvd.conf
sudo systemctl daemon-reload
sudo systemctl enable radvd.service
sudo systemctl start radvd.service

# Enable hostapd service
if [ -f /etc/default/hostapd ]; then
Expand Down
16 changes: 8 additions & 8 deletions scripts/hostapd/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ set -e
sudo systemctl disable hostapd.service 2>/dev/null || true
sudo systemctl stop hostapd.service 2>/dev/null || true
sudo systemctl daemon-reload
if [ -f "/etc/network/interfaces.backup" ]; then
sudo mv /etc/network/interfaces.backup /etc/network/interfaces
if [ -f "/etc/network/interfaces.bak" ]; then
sudo mv /etc/network/interfaces.bak /etc/network/interfaces
fi
if [ -f "/etc/sysctl.conf.backup" ]; then
sudo mv /etc/sysctl.conf.backup /etc/sysctl.conf
if [ -f "/etc/sysctl.conf.bak" ]; then
sudo mv /etc/sysctl.conf.bak /etc/sysctl.conf
fi
if [ -f "/etc/dnsmasq.conf.backup" ]; then
sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf
if [ -f "/etc/dnsmasq.conf.bak" ]; then
sudo mv /etc/dnsmasq.conf.bak /etc/dnsmasq.conf
fi
if [ -f "/etc/dhcpcd.conf.backup" ]; then
sudo mv /etc/dhcpcd.conf.backup /etc/dhcpcd.conf
if [ -f "/etc/dhcpcd.conf.bak" ]; then
sudo mv /etc/dhcpcd.conf.bak /etc/dhcpcd.conf
fi
sudo rm -f /etc/radvd.conf
sudo rm -f /etc/hostapd/hostapd.conf
Expand Down

0 comments on commit b015f97

Please sign in to comment.