From 9f3afeaff75731d16fb2b6e1cfec7098dd48c591 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 26 Oct 2024 01:14:17 +0200 Subject: [PATCH] Add pi/wifi --- pi/wifi | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 pi/wifi diff --git a/pi/wifi b/pi/wifi new file mode 100644 index 0000000..7c4c791 --- /dev/null +++ b/pi/wifi @@ -0,0 +1,124 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: wificonn +# Required-Start: wpa_supplicant dhclient +# Required-Stop: wpa_supplicant dhclient +# Default-Start: 0 1 2 3 4 5 6 +# Default-Stop: +# Short-Description: Start wificonn +# Description: Start wificonn +### END INIT INFO + +# -> /etc/init.d/wifi +# to be replaced by architecture similar to pi-purple + + +# wificonn STARTER + +case "$1" in + "start") + # Ensure junk from previous instances is gone! + sleep 10 + killall revpfw3 ssh + kill -0 $(cat /etc/serverpid) && sleep 60 && exit 20 + echo -n "$$" > /etc/serverpid + + # Start a thread to make sure the internet connectivity is NEVER lost! + ( + OFF=0 + while true; do + # Wait 0.5 minutes + sleep 300 + if killall -0 revpfw3 > /dev/null 2>&1 ; then + OFF=0 + else + if [[ $OFF = 1 ]] ; then + reboot + fi + #OFF=1 + fi + done + ) & + echo -n " $!" >> /etc/serverpid + ( + OFF=0 + while true; do + # Wait 0.5 minutes + sleep 300 + if ping -c 1 tudbut.de > /dev/null 2>&1 ; then + OFF=0 + else + if [[ $OFF = 1 ]] ; then + reboot + fi + OFF=1 + fi + done + ) & + echo -n " $!" >> /etc/serverpid + + # no dont do that + ## # Start wificonn service + ## /bin/wificonn + # start dhclient instead + #(cd $(cat /etc/server_dir); while true; do java -jar $(cat /etc/server_jar); done) & + # Wait 5 seconds + sleep 5 + # Start a thread to make sure the important portfws are running + ( + while true ; do + echo Starting remote revpfw + echo "echo STARTING; killall revpfw3 && echo KILLED; sleep 2" | ssh -o StrictHostKeyChecking=no root@tudbut.de + #echo "cd server ; revpfw3 server 25565 _____ & echo STARTED MCS" | ssh -o StrictHostKeyChecking=no root@tudbut.de & + echo "cd server ; revpfw3 server 23 _____ & echo STARTED SSH" | ssh -o StrictHostKeyChecking=no root@tudbut.de & + echo "cd server ; revpfw3 server 81 _____ & echo STARTED WEB" | ssh -o StrictHostKeyChecking=no root@tudbut.de & + echo "cd server ; revpfw3 server 6667 _____ & echo STARTED IRC" | ssh -o StrictHostKeyChecking=no root@tudbut.de & + echo Wait 5 seconds for the portfw servers to start up + sleep 5 + + echo Connect to portfw servers + #revpfw3 client tudbut.de 25565 localhost 25565 _____ & + #PID1="$!" + PID1=1 + revpfw3 client tudbut.de 23 localhost 22 _____ & + PID2="$!" + revpfw3 client tudbut.de 81 localhost 80 _____ & + PID3="$!" + revpfw3 client tudbut.de 6667 localhost 6667 _____ & + PID4="$!" + echo Wait 3 seconds for the connections to form + sleep 3 + + echo Start the IRC bots + ircbots + echo Wait 0.5 seconds for the IRC bots to start up + sleep 0.5 + + # Ensure all services are running + while kill -0 $PID1 && kill -0 $PID2 && kill -0 $PID3 && kill -0 $PID4 ; do + # Wait 1 second to not stress CPU too much + sleep 1 + done + # Wait 1 second + sleep 1 + kill $PID2 $PID3 $PID4 # $PID1 + done + ) & + echo -n " $!" >> /etc/serverpid + # bash -c 'cd ~www/cooking && python3 -m http.server 6003' & + # while true; do revpfw3 client 8b8t.xyz 6003 localhost 6003 _____ ; sleep 3 ; done & + #sleep 30 + #discordirc + while true; do sleep 10; done + ;; + "stop") + killall revpfw3 + # Wait 2 seconds + sleep 1 + kill $(cat /etc/serverpid) + sleep 5 + killall -9 revpfw3 + kill -9 $(cat /etc/serverpid) + killall /etc/init.d/wifi + ;; +esac & disown