Skip to content

Instantly share code, notes, and snippets.

@ehsansh84
Created July 23, 2020 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehsansh84/6ebb9508533e7f6595ab9cc6333bd3b5 to your computer and use it in GitHub Desktop.
Save ehsansh84/6ebb9508533e7f6595ab9cc6333bd3b5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# A menu driven shell script sample template
## ----------------------------------
# Step #1: Define variables
# ----------------------------------
EDITOR=vim
PASSWD=/etc/passwd
RED='\033[0;41;30m'
STD='\033[0;0;39m'
# ----------------------------------
# Step #2: User defined function
# ----------------------------------
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
install_packages(){
apt install -y screenfetch;
apt-get install -y software-properties-common;
apt install -y curl;
apt install htop;
apt install iotop;
apt install nload;
apt install -y git;
apt install -y python-pip;
apt-get install -y python-setuptools;
apt-get install -y net-tools;
apt install -y supervisor;
apt install -y apache2;
apt install -y vim;
apt install -y dirmngr;
pause
}
install_python3(){
apt install -y python3-pip
pause
}
install_python2_libraries(){
pip install -U wheel;
pip install tornado;
pip install pymongo;
pip install openpyxl;
pip install pyjwt;
pip install requests;
pip install pyfcm;
pip install psutil;
pause
}
install_python3_libraries(){
pip3 install -U wheel;
pip3 install tornado;
pip3 install pymongo;
pip3 install openpyxl;
pip3 install pyjwt;
pip3 install requests;
pip3 install pyfcm;
pip3 install psutil;
pause
}
install_mongodb_debian_10(){
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list
apt-get update
apt-get install -y mongodb-org
service mongod restart
pause
}
shecan_dns(){
echo 'nameserver 185.51.200.2' > /etc/resolv.conf;
pause
}
unshecan_dns(){
echo 'nameserver 8.8.8.8' > /etc/resolv.conf;
pause
}
java(){
apt install -y default-jdk
pause
}
elasticsearch(){
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list
apt-get update && apt-get install elasticsearch
pause
}
sshkey(){
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""
cat /tmp/sshkey.pub
pause
}
# function to display menus
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Install packages"
echo "2. Install Python3"
echo "3. Install Python2 libraries"
echo "4. Install Python3 libraries"
echo "5. Install MongoDB for Debian 10"
echo "6. Shecan DNS"
echo "7. Unshecan DNS"
echo "8. Java"
echo "9. Elasticsearch"
echo "10. sshkey"
echo "0. Exit"
}
# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# invoke the two() when the user select 2 from the menu option.
# Exit when user the user select 3 form the menu option.
read_options(){
local choice
read -p "Enter choice [ 0 - 9] " choice
case $choice in
1) install_packages ;;
2) install_python3 ;;
3) install_python2_libraries ;;
4) install_python3_libraries ;;
5) install_mongodb_debian_10 ;;
6) shecan_dns ;;
7) unshecan_dns ;;
8) java ;;
9) elasticsearch ;;
10) sshkey ;;
0) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# Step #4: Main logic - infinite loop
# ------------------------------------
while true
do
show_menus
read_options
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment