2022-11-24 20:14:59 +00:00
#!/usr/bin/env bash
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
set -ex
script_path = $( dirname " $( realpath " $0 " ) " )
2018-10-01 16:45:57 +00:00
OS_REQUIREMENTS_FILENAME = " $script_path /requirements.apt "
2017-06-23 21:00:42 +00:00
# Handle call with wrong command
2022-11-24 20:14:59 +00:00
function wrong_command( ) {
2017-06-23 21:00:42 +00:00
echo " ${ 0 ##*/ } - unknown command: ' ${ 1 } ' "
usage_message
}
# Print help / script usage
2022-11-24 20:14:59 +00:00
function usage_message( ) {
2017-06-23 21:00:42 +00:00
echo " usage: ./ ${ 0 ##*/ } <command> "
echo "available commands are:"
echo -e " \tlist\t\tPrint a list of all packages defined on ${ OS_REQUIREMENTS_FILENAME } file "
echo -e "\thelp\t\tPrint this help"
echo -e "\n\tCommands that require superuser permission:"
echo -e " \tinstall\t\tInstall packages defined on ${ OS_REQUIREMENTS_FILENAME } file. Note: This\n\t\t\t does not upgrade the packages already installed for new\n\t\t\t versions, even if new version is available in the repository. "
2022-11-24 00:32:57 +00:00
echo -e "\tupgrade\t\tSame that install, but upgrade the already installed packages,\n\t\t\t if new version is available."
2017-06-23 21:00:42 +00:00
}
# Read the requirements.apt file, and remove comments and blank lines
2022-11-24 20:14:59 +00:00
function list_packages( ) {
grep -v "#" " ${ OS_REQUIREMENTS_FILENAME } " | grep -v " ^ $"
2017-06-23 21:00:42 +00:00
}
2022-11-24 20:14:59 +00:00
function install( ) {
list_packages | xargs apt-get --no-upgrade install -y
2017-06-23 21:00:42 +00:00
}
2022-11-24 20:14:59 +00:00
function upgrade( ) {
list_packages | xargs apt-get install -y
2017-06-23 21:00:42 +00:00
}
2022-11-24 20:14:59 +00:00
function install_or_upgrade( ) {
P = ${ 1 }
PARAN = ${ P :- "install" }
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
if [ [ $EUID -ne 0 ] ] ; then
echo -e "\nYou must run this with root privilege" 2>& 1
echo -e "Please do:\n" 2>& 1
echo " sudo ./ ${ 0 ##*/ } $PARAN " 2>& 1
echo -e "\n" 2>& 1
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
exit 1
else
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
apt-get update
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
# Install the basic compilation dependencies and other required libraries of this project
if [ " $PARAN " = = "install" ] ; then
install
else
upgrade
2017-06-23 21:00:42 +00:00
fi
2022-11-24 20:14:59 +00:00
# cleaning downloaded packages from apt-get cache
apt-get clean
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
exit 0
fi
2017-06-23 21:00:42 +00:00
2022-11-24 20:14:59 +00:00
}
2017-06-23 21:00:42 +00:00
# Handle command argument
case " $1 " in
2022-11-24 20:14:59 +00:00
install) install_or_upgrade ; ;
upgrade) install_or_upgrade "upgrade" ; ;
list) list_packages ; ;
help ) usage_message ; ;
*) wrong_command " $1 " ; ;
2017-06-23 21:00:42 +00:00
esac