I am not an expert in shell scripting,
I need help optimizing the shell script I wrote, This shell script I wrote is run by users on the client side who connect to our vpn server from the setting passed in the config.tar.
I check if pip or or tar or other packaches are installed if not isntalled than install it, I am doing it in separate if condition, what I want to achieve is I put the packages to check in a listand then iterate if not installed than install it for all apt, pip or pip3 packages.
#!/usr/bin/env bash set - command=`which pip` if [ "$command" = "" ] then echo "The pip program not exist on this system." sudo apt-get install python-pip -y sudo apt install python3-pip -y else echo "Pip is intalled." fi sudo apt install speedtest-cli pip install -U pip pip3 install mysql-connector-python pip3 install pymysql pip3 install sqlalchemy TAR=`which tar` if [ "$TAR" = "" ] then echo "Tar is not installed, installing now." sudo apt-get install tar -y else echo "Tar is installed." fi # lets install requests pip install requests cd $HOME echo "Iniating download..." curl -sL "http://my.domain.com/config" -o "config.tar" tar xvf config.tar sudo chmod 604 ucc.py if [ -e ucc.py ] then echo "ucc.py installed." else echo "ucc.py failed to download." fi if [ -e ucc.service ] then echo "ucc.service installed." else echo "ucc.service failed to download." fi sudo mv ucc.service "/lib/systemd/system/" if [ -e client.conf ] then sudo mv client.conf /etc/openvpn/ echo "client.conf downloaded." else echo "client.conf failed to download." fi sudo mv -f client.conf /etc/openvpn/ cd /etc/openvpn/ if [ -e client.conf ] then echo "client.conf installed." else echo "client.conf failed to download." fi sudo systemctl restart openvpn@client sudo systemctl status openvpn@client
any help will be greatly appreciated.