Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #DEBUG= # uncomment/comment to enable/disable debug mode
- # name: merlin-ovpn-server-restart.sh
- # version: 1.1.0, 05-aug-2022, by eibgrad
- # purpose: restart openvpn server(s) on bootup
- # type(s): services-start
- # href: https://tinyurl.com/4bnrte9c
- # installation:
- # 1. enable jffs custom scripts and configs (administration->system)
- # 2. ssh to router and copy/paste the following command:
- # curl -kLs bit.ly/merlin-installer|tr -d '\r'|sh -s MkKb9tia
- # 3. reboot
- SCRIPTS_DIR='/jffs/scripts'
- SCRIPT1="$SCRIPTS_DIR/merlin-ovpn-server-restart.sh"
- SCRIPT2="$SCRIPTS_DIR/services-start"
- mkdir -p $SCRIPTS_DIR
- # --------------------- begin merlin-ovpn-server-restart --------------------- #
- cat << 'EOF' > $SCRIPT1
- #!/bin/sh
- #set -x # comment/uncomment to disable/enable debug mode
- {
- if [ ! "$1" ]; then
- # only autostart enabled openvpn servers need to be considered
- for i in $(nvram get vpn_serverx_start | tr ',' ' '); do
- nohup $0 $i &>/dev/null &
- done
- else
- # wait for successful openvpn server startup
- until pidof vpnserver${1} &>/dev/null && \
- [ "$(nvram get vpn_server${1}_state)" == '2' ]
- do sleep 10; done; sleep 10
- # restart the openvpn server
- service restart_vpnserver${1} >/dev/null
- echo "openvpn server #$1 restarted @ $(date)"
- fi
- exit 0
- } 2>&1 | logger -t $(basename $0 .sh)[$$]
- EOF
- [ ${DEBUG+x} ] && sed -ri '2 s/^#(set -x)/\1/' $SCRIPT1
- chmod +x $SCRIPT1
- echo "installed: $SCRIPT1"
- # ---------------------- end merlin-ovpn-server-restart ---------------------- #
- # --------------------------- begin services-start --------------------------- #
- create_script() {
- cat << 'EOF' > $SCRIPT2
- #!/bin/sh
- #set -x # comment/uncomment to disable/enable debug mode
- {
- $SCRIPT1
- } 2>&1 | logger -t $(basename $0)[$$]
- EOF
- [ ${DEBUG+x} ] && sed -ri '2 s/^#(set -x)/\1/' $SCRIPT2
- sed "s:\$SCRIPT1:$SCRIPT1:g" -i $SCRIPT2
- chmod +x $SCRIPT2
- }
- if [ -f $SCRIPT2 ]; then
- echo "error: $SCRIPT2 already exists; requires manual installation"
- else
- create_script
- echo "installed: $SCRIPT2"
- fi
- # ---------------------------- end services-start ---------------------------- #
Add Comment
Please, Sign In to add comment