2015-03-14 03:07:25 +03:00
#!/bin/bash
2016-05-01 08:26:33 +03:00
WORK_DIR = " $( dirname " $0 " ) "
2016-06-09 06:15:01 +03:00
DISTRO_NAME = $( lsb_release -sc)
2015-03-14 03:07:25 +03:00
2016-06-09 06:15:01 +03:00
OS_REQUIREMENTS_FILENAME = " $WORK_DIR /requirements- $DISTRO_NAME .apt "
if [ " $DISTRO_NAME " != "xenial" ] && [ " $DISTRO_NAME " != "trusty" ] ; then
echo "Only the Ubuntu 14.04 (Trusty) and 16.04 (Xenial) is supported by this script" ;
echo "You can see requirements-trusty.apt or requirements-xenial.apt file to help search the equivalent package in your system" ;
exit 1;
2016-04-04 10:58:22 +03:00
fi
2016-06-09 06:15:01 +03:00
2015-04-11 18:32:49 +03:00
# Handle call with wrong command
function wrong_command( )
{
echo " ${ 0 ##*/ } - unknown command: ' ${ 1 } ' "
usage_message
}
2015-03-14 03:07:25 +03:00
2015-04-11 18:32:49 +03:00
# Print help / script usage
function usage_message( )
{
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. "
echo -e "\tupgrade\t\tSame that install, but upgrate the already installed packages,\n\t\t\t if new version is available."
2015-03-14 03:07:25 +03:00
2015-04-11 18:32:49 +03:00
}
2015-03-14 03:07:25 +03:00
2015-04-11 18:32:49 +03:00
# Read the requirements.apt file, and remove comments and blank lines
function list_packages( ) {
2016-06-09 06:15:01 +03:00
grep -v "#" " ${ OS_REQUIREMENTS_FILENAME } " | grep -v " ^ $" ;
2015-04-11 18:32:49 +03:00
}
2016-06-09 06:15:01 +03:00
function install_packages( )
2015-04-11 18:32:49 +03:00
{
list_packages | xargs apt-get --no-upgrade install -y;
}
2016-06-09 06:15:01 +03:00
function upgrade_packages( )
2015-04-11 18:32:49 +03:00
{
list_packages | xargs apt-get install -y;
}
function install_or_upgrade( )
{
P = ${ 1 }
PARAN = ${ P :- "install" }
if [ [ $EUID -ne 0 ] ] ; then
echo -e "\nYou must run this with root privilege" 2>& 1
echo -e "Please do:\n" 2>& 1
2016-06-09 06:15:01 +03:00
echo " sudo ./ $WORK_DIR / ${ 0 ##*/ } $PARAN " 2>& 1
2015-04-11 18:32:49 +03:00
echo -e "\n" 2>& 1
exit 1
else
apt-get update
# Install the basic compilation dependencies and other required libraries of this project
if [ " $PARAN " = = "install" ] ; then
2016-06-09 06:15:01 +03:00
install_packages;
2015-04-11 18:32:49 +03:00
else
2016-06-09 06:15:01 +03:00
upgrade_packages;
2015-04-11 18:32:49 +03:00
fi
# cleaning downloaded packages from apt-get cache
apt-get clean
exit 0
fi
}
# Handle command argument
case " $1 " in
install) install_or_upgrade; ;
upgrade) install_or_upgrade "upgrade" ; ;
list) list_packages; ;
help ) usage_message; ;
2016-06-09 06:15:01 +03:00
*) wrong_command " $1 " ; ;
2015-04-11 18:32:49 +03:00
esac