mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
Fixing a lot of stuff
This commit is contained in:
parent
4b33a1209f
commit
2f77fb4b1a
3 changed files with 22 additions and 13 deletions
|
@ -49,6 +49,16 @@ is_running() {
|
||||||
&& is_hostapd_running && is_radvd_running && is_dhcpd_running
|
&& is_hostapd_running && is_radvd_running && is_dhcpd_running
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internet_device=$(ip r | awk '/default via/ { print $NF; }')
|
||||||
|
internet_device_vpn=tun0
|
||||||
|
internet_device_default=${internet_device}
|
||||||
|
|
||||||
|
# Apply NAT on tun0 if IPv6 address if VPN is used
|
||||||
|
ip l sh dev tun0 &> /dev/null
|
||||||
|
if [ "$?" -eq 0 ]; then
|
||||||
|
internet_device_default=${internet_device_vpn}
|
||||||
|
fi
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
if is_running; then
|
if is_running; then
|
||||||
|
@ -61,7 +71,7 @@ case "$1" in
|
||||||
|
|
||||||
if ! is_nat_set; then
|
if ! is_nat_set; then
|
||||||
echo "Set NAT"
|
echo "Set NAT"
|
||||||
iptables -t nat -A POSTROUTING -o <TPL:WIRED_DEVICE> -j MASQUERADE
|
iptables -t nat -A POSTROUTING -o ${internet_device_default} -j MASQUERADE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! is_ip4nataddr_set; then
|
if ! is_ip4nataddr_set; then
|
||||||
|
@ -107,7 +117,9 @@ case "$1" in
|
||||||
|
|
||||||
if is_nat_set; then
|
if is_nat_set; then
|
||||||
echo "Unset NAT"
|
echo "Unset NAT"
|
||||||
iptables -t nat -D POSTROUTING -o <TPL:WIRED_DEVICE> -j MASQUERADE
|
# Depending on the presence or not of a VPN at the last startup, one of these 2 lines is unnecessary
|
||||||
|
iptables -t nat -D POSTROUTING -o ${internet_device} -j MASQUERADE 2> /dev/null
|
||||||
|
iptables -t nat -D POSTROUTING -o ${internet_device_vpn} -j MASQUERADE 2> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_ip4nataddr_set; then
|
if is_ip4nataddr_set; then
|
||||||
|
|
|
@ -22,10 +22,9 @@ sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server ipta
|
||||||
sudo apt-get --assume-yes --force-yes install sipcalc
|
sudo apt-get --assume-yes --force-yes install sipcalc
|
||||||
|
|
||||||
# Compute extra arguments
|
# Compute extra arguments
|
||||||
wired_device=$(ip r | awk '/default via/ { print $NF; }')
|
|
||||||
ip6_expanded_net=$(sipcalc ${ip6_net} | grep Expanded | awk '{ print $NF; }')
|
ip6_expanded_net=$(sipcalc ${ip6_net} | grep Expanded | awk '{ print $NF; }')
|
||||||
ip6_net=$(sipcalc ${ip6_net} | grep Compressed | 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=$(echo "$(echo ${ip6_expanded_net} | cut -d: -f1-7):1")
|
||||||
ip6_addr=$(sipcalc ${ip6_addr} | grep Compressed | awk '{ print $NF; }')
|
ip6_addr=$(sipcalc ${ip6_addr} | grep Compressed | awk '{ print $NF; }')
|
||||||
ip4_nat_prefix=10.0.242
|
ip4_nat_prefix=10.0.242
|
||||||
|
|
||||||
|
@ -33,7 +32,6 @@ ip4_nat_prefix=10.0.242
|
||||||
sudo yunohost app setting hotspot wifi_ssid -v ${wifi_ssid}
|
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_passphrase -v ${wifi_passphrase}
|
||||||
sudo yunohost app setting hotspot wifi_device -v ${wifi_device}
|
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_addr -v ${ip6_addr}
|
||||||
sudo yunohost app setting hotspot ip6_net -v ${ip6_net}
|
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_dns0 -v ${ip6_dns0}
|
||||||
|
@ -73,17 +71,10 @@ sudo install -b -o root -g root -m 0755 ../conf/ynh-hotspot /etc/init.d/
|
||||||
sudo sed "s|<TPL:IP6_ADDR>|${ip6_addr}|g" -i /etc/init.d/ynh-hotspot
|
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: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: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
|
## hostapd
|
||||||
sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
|
sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Set default inits
|
# Set default inits
|
||||||
# The boot order of these services are important, so they are disabled by default
|
# The boot order of these services are important, so they are disabled by default
|
||||||
# and the ynh-hotspot service handles them.
|
# and the ynh-hotspot service handles them.
|
||||||
|
@ -98,6 +89,12 @@ sudo yunohost service add hostapd
|
||||||
sudo yunohost service stop hostapd
|
sudo yunohost service stop hostapd
|
||||||
sudo yunohost service disable hostapd
|
sudo yunohost service disable hostapd
|
||||||
|
|
||||||
|
# Remove IPv6 address if vpnclient is installed because from now this one is handle by this app
|
||||||
|
sudo 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
|
||||||
|
|
||||||
# Gooo
|
# Gooo
|
||||||
sudo yunohost service add ynh-hotspot
|
sudo yunohost service add ynh-hotspot
|
||||||
sudo yunohost service enable ynh-hotspot
|
sudo yunohost service enable ynh-hotspot
|
||||||
|
|
|
@ -6,7 +6,7 @@ sudo yunohost service remove ynh-hotspot
|
||||||
sudo rm -f /etc/init.d/ynh-hotspot
|
sudo rm -f /etc/init.d/ynh-hotspot
|
||||||
|
|
||||||
# Remove confs
|
# Remove confs
|
||||||
sudo rm -rf /etc/hostapd/ /etc/radvd.conf /etc/dhcp/dhcpd.conf
|
sudo rm -f /etc/hostapd/hostapd.conf /etc/radvd.conf /etc/dhcp/dhcpd.conf
|
||||||
|
|
||||||
# Remove packets
|
# Remove packets
|
||||||
# The yunohost policy is currently to not uninstall packets (dependency problems)
|
# The yunohost policy is currently to not uninstall packets (dependency problems)
|
||||||
|
|
Loading…
Add table
Reference in a new issue