Jump to content
Not connected, Your IP: 3.149.242.16
Sign in to follow this  
dawnrazor

Linux server selection script

Recommended Posts

Since the Network manager failed on me I came across a nice menu script which I adapted to run my openvpn commands and included a disconnect too so it is easier to change to other servers.  I've tested this script and it works perfectly, just save it into  the same directory as your .ovpn files.

 

 

 

#!/bin/bash

show_menu(){

    NORMAL=`echo "\033[m"`

    MENU=`echo "\033[36m"` #Blue

    NUMBER=`echo "\033[33m"` #yellow

    FGRED=`echo "\033[41m"`

    RED_TEXT=`echo "\033[31m"`

    ENTER_LINE=`echo "\033[33m"`

    echo -e "${MENU}*********************************************${NORMAL}"

    echo -e "${MENU}${NORMAL}"

    echo -e "${MENU}${NORMAL}"

    echo -e "${MENU}******${NUMBER} 1)${MENU} VPN-name ${NORMAL}"  #change VPN-name to your server name

    echo -e ""

    echo -e "${MENU}******${NUMBER} 2)${MENU} VPN-name ${NORMAL}"   #change VPN-name to your server name

    echo -e ""

    echo -e "${MENU}******${NUMBER} 3)${MENU} VPN-name ${NORMAL}"   #change VPN-name to your server name

    echo -e ""

    echo -e "${MENU}******${NUMBER} 4)${MENU} VPN-name ${NORMAL}"   #change VPN-name to your server name

    echo -e ""

    echo -e "${MENU}******${NUMBER} 5)${MENU} Disconnect VPN ${NORMAL}"  #kill openvpn restoring connection to normal

    echo -e "${MENU}${NORMAL}"

    echo -e "${MENU}*********************************************${NORMAL}"

    echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"

    read opt

}

function option_picked() {

    COLOR='\033[01;31m' # bold red

    RESET='\033[00;00m' # normal white

    MESSAGE=${@:-"${RESET}Error: No message passed"}

    echo -e "${COLOR}${MESSAGE}${RESET}"

}

 

clear

show_menu

while [ opt != '' ]

    do

    if [[ $opt = "" ]]; then 

            exit;

    else

        case $opt in

        1) clear;

        option_picked "Option 1 Picked";

   sudo openvpn --config /path/to/file/yourfile.ovpn; #change to the path for your downloaded config file

        menu;

        ;;

 

        2) clear;

            option_picked "Option 2 Picked";

            sudo openvpn --config /path/to/file/yourfile.ovpn; #change to the path for your downloaded config file

        menu;

            ;;

 

        3) clear;

            option_picked "Option 3 Picked";

   sudo openvpn --config /path/to/file/yourfile.ovpn; #change to the path for your downloaded config file

            show_menu;

            ;;

 

        4) clear;

            option_picked "Option 4 Picked";

   ssudo openvpn --config /path/to/file/yourfile.ovpn; #change to the path for your downloaded config file

            show_menu;

            ;;

        5) clear;

   option_picked "Option 5 picked";

   sudo killall -SIGINT openvpn

   show_menu;

            ;;

 

        x)exit;

        ;;

 

        \n)exit;

        ;;

 

        *)clear;

        option_picked "Pick an option from the menu";

        show_menu;

        ;;

    esac

fi

done

 

 

------------------------------

Remember to change the locations and names of your ovpn files in the script.

 

the script can be run with a single click in KDE by adding this desktop launcher..

 

#!/usr/bin/env xdg-open

[Desktop Entry]

Comment[en_GB]=menu script

Comment=menu script

#    put name of your script here

Exec=./nameofscript      

GenericName[en_GB]=

GenericName=

Icon[en_GB]=browser

Icon=browser

MimeType=

Name[en_GB]=AirVPN.script

Name=AirVPN.script

#   put path to your script here

Path=/path/to/your/script

StartupNotify=true

Terminal=true

TerminalOptions=

Type=Application

Version=1.0

X-DBUS-ServiceName=

X-DBUS-StartupType=

X-KDE-SubstituteUID=false

X-KDE-Username=

 

save it on the desktop with an extension .desktop  eg.  AirVPN.desktop.  and you are good to go !

Share this post


Link to post

Thanks, modified this run from within a FreeBSD-jail - works 

 

My scripting skills are very limited, but I wonder if theres a way to improve this, for example

 

1 check if torrent-tracker NNN is available (ping, telnet..?)

2 if not, pick up option 2

3 wait 5 mins 

4 recheck, if tracker not availeble, pick up option 3 

... etc

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Security Check
    Play CAPTCHA Audio
    Refresh Image
Sign in to follow this  

×
×
  • Create New...