you.chen | f54b2ba | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | if [ "$1" == "start" ]; then |
| 4 | ifconfig wlan0 up |
| 5 | if [ $? != 0 ]; then |
| 6 | exit 1 |
| 7 | fi |
you.chen | 1457214 | 2023-04-26 10:00:06 +0800 | [diff] [blame] | 8 | ps -eo "%p %a" | grep "dhcpcd wlan0" | grep -v grep |
you.chen | f54b2ba | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 9 | if [ $? != 0 ]; then |
you.chen | fff9aac | 2023-05-18 14:19:46 +0800 | [diff] [blame^] | 10 | echo "" > /tmp/wlan0_dhcpcd_router |
| 11 | echo "#!/bin/sh" > /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 12 | echo "if [ \"\$reason\" == \"BOUND\" -o \"\$reason\" == \"RENEW\" -o \"\$reason\" == \"REBIND\" ]; then" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 13 | echo " if [ \"\$new_routers\" != \"\" ]; then" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 14 | echo " for x in \$new_routers; do" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 15 | echo " echo \"new_router \$x\" > /tmp/wlan0_dhcpcd_router" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 16 | echo " ping -c2 \$x &" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 17 | echo " done" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 18 | echo " fi" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 19 | echo "fi" >> /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 20 | chmod +x /run/wg870/wlan0_dhcpcd_run_hooks.sh |
| 21 | dhcpcd wlan0 -t 0 -o domain_name_servers --noipv4ll -4 -B -G -c /run/wg870/wlan0_dhcpcd_run_hooks.sh & |
you.chen | f54b2ba | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 22 | fi |
| 23 | elif [ "$1" == "stop" ]; then |
you.chen | 1457214 | 2023-04-26 10:00:06 +0800 | [diff] [blame] | 24 | ps -eo "%p %a" | grep "dhcpcd wlan0" | grep -v grep | awk '{print "kill "$1}' | sh |
you.chen | f54b2ba | 2023-04-24 15:39:37 +0800 | [diff] [blame] | 25 | ifconfig wlan0 0.0.0.0 |
| 26 | if [ $? != 0 ]; then |
| 27 | exit 1 |
| 28 | fi |
| 29 | else |
| 30 | exit 2 |
| 31 | fi |
| 32 | |
you.chen | 1457214 | 2023-04-26 10:00:06 +0800 | [diff] [blame] | 33 | exit 0 |