#!/bin/bash

function install_node () {

# check the installation method (yum or apt) and proceed accordingly
if [ $REPOSITORY_TYPE == 'apt' ] ; then 

    run config_apt_prefs || ( yaimlog ERROR "Error during setting apt preferences. Exiting."  ; exit 1 )
    run config_apt ||  (yaimlog ERROR "Error during configuring apt repository. Exiting." ; exit 1 )

    # This has to be run before and after config_apt!!
    # Updates to apt itself can overwrite the prefs file
    run config_apt_prefs || ( yaimlog ERROR "Error during setting apt preferences. Exiting."  ; exit 1 )

elif [ $REPOSITORY_TYPE == 'yum' ] ; then
    run config_yum || ( yaimlog ERROR "Error during configuring yum repository. Exiting."  ; exit 1 )
else 
    yaimlog ERROR "Installer method must be 'apt' or 'yum'! Set REPOSITORY_TYPE in your site-info.def file. Exiting..."
    exit 1
fi

# Lose the site-info.def from the command line
shift
# Get the right names
unset packages
for i in $@; do
    packages="${packages} ${i}"
done
packages="${packages} lcg-CA"

# Install all the software

if [ $REPOSITORY_TYPE == 'apt' ] ; then 
    apt-get --assume-yes install $packages || exit 1
elif [ $REPOSITORY_TYPE == 'yum' ] ; then
    yum -y install $packages || exit 1
fi

}
