0

I want to create a script (script.sh) to change the contents of /etc/proxychains.conf. I would like to do it in the form of a menu though, so something like this:

After runing ./script.sh

[1] Add Proxychain

[2] Start Proxychains

[3] Exit

Please select an option:

If the user selects [1] I would like to to ask for these inputs:

Type of Proxy:

Proxy IP Address:

Proxy Port:

And use these inputs in this form: (socks5 127.0.0.1 9050) at the bottom of the file /etc/proxychains.conf where you would normally add your proxy info. I was thinking of maybe assigning each input like $type $ip $port (so you can display each field next to each other). But how can I make it so it automatically finds that spot in the file proxychains.conf and adds those fields to it under any other ones priviously added.

And After I would like to return back to the option menu where if the user presses [2] then it would run:

proxychains firefox

And of course after firefox closes I would like to bring back the menu where if the user selects [3] the it would echo "Goodbye" sleep 1s and exit.

  • 1
    You're looking for bash 'select'. Google it for examples, the purpose of such forums is in general to help with existing code, not to write the whole solution out. The select would when matched trigger a function or logic block that would then ask the next set of questions, which would use 'read' to get the answer to each. Between select and read you have the interactive component.. Since the same questions are asked for each option, you'd want to use a function there probably. – Lizardx Jul 13 '17 at 0:24
1

This script should have solved your problem. And Next Time try to write a script and ask if you have any problem instead of asking for whole solutions.

#! /bin/bash
function menu {
    echo ""
    echo "++++++++++++++++++++++++++++++++++++++++++++"
    echo "+++++proxychain applications version1.0+++++"
    echo "++++++++++++++++++++++++++++++++++++++++++++"
    echo "[1] Add Proxychain"
    echo "[2] Start Proxychains" 
    echo "[3] Exit"
    echo "[4] Cat specified file"
    read -p "Please select an option : " option
}

function input {
    read -p "Input Type of Proxy : " type
        read -p "Input Proxy IP Address : " ip_addr
        read -p "Inport Proxy Port : " port
        if [ ! -z "${type}" ]&&[ ! -z "${ip_addr}" ]&&[ ! -z "${port}" ]
    then
        echo -e "${type}\t${ip_addr}\t${port}" >>proxychains.conf
    else
        input   
    fi
}

function start {
    echo "proxychains firefox"
}

function terminate {
    if [ -z "$(pgrep firefox)" ]
    then
        echo -e "Goodbye\n"
        sleep 1
        end_script=1
        exit 0
    else
        echo -e "Terminating firefox!\n"
        pkill firefox
        echo "Goodbye"
        end_script=1
        exit 0
    fi
}

function catme {
    read -p "Input the file path : " file_path
    cat "${file_path}"
    exit 0
}

end_script=0
while [ "${end_script}" != 1 ];do
    menu
    current_stage=${option}
    case ${option} in
        1)
            input
        ;;

        2) 
            start
        ;;

        3) 
            terminate
            exit 0
        ;;

        4)  
            catme
        ;;

        *)
            echo "unknown usage!"
        ;;
    esac
  • I tried adding another menu option to show a readme text file. I set it up so it will "cat readme.txt" but it only shows the menu, and if I scroll up then it will show the txt file. So it displays the txt file and it automatically redirects back to the menu. How can I prevent this? – iamr00t Jul 13 '17 at 16:46
  • See the updated content.It exits now when you cat out a specific file – FrontENG Jul 14 '17 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.