#!/bin/bash
# Gettext internationalization
#
# Copyright 2019  Dimitris Tzemos, GR
#!/bin/bash
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###################################################################
####                      happy-sailing                        ####
###################################################################
# script to install/uninstall packages need for sailors boats 	  #
# Fair winds													  #
# This script created for slackel                                 #
#                                                                 #
###################################################################

AUTHOR='Dimitris Tzemos - dijemos@gmail.com'
LICENCE='GPL v3+'
SCRIPT=$(basename "$0")
SCRIPT=$(readlink -f "$SCRIPT")
VER=1.0.0

init(){
		
		if [ "$UID" != "0" ]; then
			echo "You need to be root to run this"
			exit 1
		fi

        # Translations only work with utf8 locales
        if [ ! `echo $LANG | grep -i utf` ]; then
                LANG=C
        fi

        # Gettext internationalization
        export TEXTDOMAIN="happy-sailing"
        export TEXTDOMAINDIR="/usr/share/locale"
        . gettext.sh
        
        # Path needs to be extended in case you're only half a root :)
        export PATH="/usr/sbin:/sbin:${PATH}"
}

usage(){
        echo "`eval_gettext 'USAGE: happy-sailing [install|uninstall]'`"
        echo
        echo "`eval_gettext '   OPTIONS:'`"
        echo "`eval_gettext '   install  Install packages'`"
        echo "`eval_gettext '   uninstall Uninstall packages'`"
        exit 1
}

# Check which options are used from the command line
checkoptions(){
        flag=$1
        
		if [ $# -gt 2 ] ; then
				echo "`eval_gettext 'ERROR: Too many arguments'`"
				usage
		fi
		
        if [[ $flag = "install" ]]; then
			export flag="install"
        elif [[ $flag = "uninstall" ]]; then
			export flag="uninstall"
		else
		   usage
        fi
}
execute_script(){
if [ -z "$startdir" ]; then
	startdir="$(pwd)"
	export startdir
fi

packagelist="TLP fldigi freeimage gpsbabel gpsd imgkap libminizip libmspack libnova log4cpp kplex opencpn opencpn-plugin-oesenc proj python-cheetah qwt qwt5 rtl-ais rtl-sdr mpir gqrx valgrind wvdial wvstreams xygrib volk gnuradio libosmo-dsp gr-osmosdr gr-iqbal"
#clear
if [ "$flag" == "install" ]; then
	#sudo slapt-get --clean
	sudo slapt-get -u
	slapt-get -i --reinstall $packagelist
elif [ "$flag" == "uninstall" ]; then
	spkg -d $packagelist 
fi

}

init
checkoptions $@
execute_script
