1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00
hotspot_ynh/scripts/install

107 lines
4 KiB
Text
Raw Normal View History

2014-11-02 21:30:56 +01:00
#!/bin/bash
# Retrieve arguments
wifi_ssid=$1
wifi_passphrase=$2
wifi_device=$3
2014-11-04 23:00:04 +01:00
ip6_net=$4
ip6_dns0=$5
ip6_dns1=$6
ip4_dns0=$7
ip4_dns1=$8
2014-11-02 21:30:56 +01:00
# Check arguments
# TODO
# Install packages
2014-11-04 23:00:04 +01:00
# TODO: Replace isc-dhcp-server by dnsmasq (currently negotiating with the YunoHost team to
# also replace bind9 by dnsmasq)
sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables
2014-11-02 21:30:56 +01:00
# Install extra packages
sudo apt-get --assume-yes --force-yes install sipcalc
# Compute extra arguments
2014-11-04 23:00:04 +01:00
wired_device=$(ip r | awk '/default via/ { print $NF; }')
2014-11-02 21:30:56 +01:00
ip6_expanded_net=$(sipcalc ${ip6_net} | grep Expanded | awk '{ print $NF; }')
ip6_net=$(sipcalc ${ip6_net} | grep Compressed | awk '{ print $NF; }')
ip6_addr=$(echo "$(echo ${ip6_expanded_net} | cut -d: -f1-7):42")
ip6_addr=$(sipcalc ${ip6_addr} | grep Compressed | awk '{ print $NF; }')
ip4_nat_prefix=10.0.242
2014-11-04 23:00:04 +01:00
# Save arguments for future upgrades
sudo yunohost app setting hotspot wifi_ssid -v ${wifi_ssid}
sudo yunohost app setting hotspot wifi_passphrase -v ${wifi_passphrase}
sudo yunohost app setting hotspot wifi_device -v ${wifi_device}
sudo yunohost app setting hotspot wired_device -v ${wired_device}
sudo yunohost app setting hotspot ip6_addr -v ${ip6_addr}
sudo yunohost app setting hotspot ip6_net -v ${ip6_net}
sudo yunohost app setting hotspot ip6_dns0 -v ${ip6_dns0}
sudo yunohost app setting hotspot ip6_dns1 -v ${ip6_dns1}
sudo yunohost app setting hotspot ip4_dns0 -v ${ip4_dns0}
sudo yunohost app setting hotspot ip4_dns1 -v ${ip4_dns1}
sudo yunohost app setting hotspot ip4_nat_prefix -v ${ip4_nat_prefix}
2014-11-02 21:30:56 +01:00
# Copy confs
sudo install -b -o root -g root -m 0644 ../conf/hostapd.conf /etc/hostapd/
sudo install -b -o root -g root -m 0644 ../conf/radvd.conf /etc/
sudo install -b -o root -g root -m 0644 ../conf/dhcpd.conf /etc/dhcp/
# Fix confs
## hostapd
sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/hostapd/hostapd.conf
sudo sed "s|<TPL:WIFI_SSID>|${wifi_ssid}|g" -i /etc/hostapd/hostapd.conf
sudo sed "s|<TPL:WIFI_PASSPHRASE>|${wifi_passphrase}|g" -i /etc/hostapd/hostapd.conf
## radvd
sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/radvd.conf
sudo sed "s|<TPL:IP6_NET>|${ip6_net}|g" -i /etc/radvd.conf
sudo sed "s|<TPL:IP6_DNS0>|${ip6_dns0}|g" -i /etc/radvd.conf
sudo sed "s|<TPL:IP6_DNS1>|${ip6_dns1}|g" -i /etc/radvd.conf
## dhcpd
sudo sed "s|<TPL:IP4_DNS0>|${ip4_dns0}|g" -i /etc/dhcp/dhcpd.conf
sudo sed "s|<TPL:IP4_DNS1>|${ip4_dns1}|g" -i /etc/dhcp/dhcpd.conf
sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/dhcp/dhcpd.conf
sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/dhcp/dhcpd.conf
# Copy init script
sudo install -b -o root -g root -m 0755 ../conf/ynh-hotspot /etc/init.d/
# Fix init script
## ynh-hostspot
sudo sed "s|<TPL:IP6_ADDR>|${ip6_addr}|g" -i /etc/init.d/ynh-hotspot
sudo sed "s|<TPL:IP4_NAT_PREFIX>|${ip4_nat_prefix}|g" -i /etc/init.d/ynh-hotspot
sudo sed "s|<TPL:WIFI_DEVICE>|${wifi_device}|g" -i /etc/init.d/ynh-hotspot
sudo sed "s|<TPL:WIRED_DEVICE>|${wired_device}|g" -i /etc/init.d/ynh-hotspot
## hostapd
sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
2014-11-04 23:00:04 +01:00
# Remove IPv6 address if vpnclient is installed because from now this one is handle by this app
yunohost app list -f vpnclient --json | grep -q '"installed": true'
if [ "$?" -eq 0 ]; then
ip a d ${ip6_addr}/128 dev tun0 &> /dev/null
fi
2014-11-02 21:30:56 +01:00
# Set default inits
# The boot order of these services are important, so they are disabled by default
# and the ynh-hotspot service handles them.
# All services are registred by yunohost in order to prevent conflicts after the uninstall.
sudo yunohost service add isc-dhcp-server
sudo yunohost service stop isc-dhcp-server
sudo yunohost service disable isc-dhcp-server
sudo yunohost service add radvd
sudo yunohost service stop radvd
sudo yunohost service disable radvd
sudo yunohost service add hostapd
sudo yunohost service stop hostapd
sudo yunohost service disable hostapd
# Gooo
sudo yunohost service add ynh-hotspot
sudo yunohost service enable ynh-hotspot
sudo yunohost service start ynh-hotspot
exit 0