Skip to content

Instantly share code, notes, and snippets.

@LordShedy
Created August 7, 2019 22:35
Show Gist options
  • Select an option

  • Save LordShedy/c03bc7a20e563fa195bbf93c3c312b79 to your computer and use it in GitHub Desktop.

Select an option

Save LordShedy/c03bc7a20e563fa195bbf93c3c312b79 to your computer and use it in GitHub Desktop.
#!/bin/bash
DPKGS=(python3 python3-pip)
PIPS=(requests datetime)
# check if user running script is root
if [[ "$EUID" != 0 ]]
then
echo "Please, run this script with superuser privileges."
exit 1
fi
# check whether dpkg dependencies are installed
for i in "${DPKGS[@]}"
do
ISINSTALLED=`dpkg-query -W -f='${Status};${Version}\n' "$i" 2>/dev/null | cut -d ';' -f1`
if [[ "$ISINSTALLED" != "install ok installed" ]]
then
sudo apt install -y $i 2>/dev/null 1>&2
if [[ "$?" -eq 0 ]]
then
echo "$i was succesfully installed"
else
echo "there was some error when installing $i"
exit 1
fi
fi
done
for i in "${PIPS[@]}"
do
sudo pip3 install $i 2>/dev/null 1>&2
if [[ "$?" -eq 0 ]]
then
echo "$i was succesfully installed or was already installed"
else
echo "there was some error when installing $i"
exit 1
fi
done
echo "all dependencies were met, you may run the script"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment