You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
smartgears-distribution/distro/contents/install

189 lines
4.6 KiB
Plaintext

#set distro to script's parent directory
distro=$(cd ${0%/*} && echo $PWD/${0##*/})
distro=$(dirname $distro)
echo "distro:$distro"
distrolibs=$distro/libs
distroapps=$distro/apps
distroscripts=$distro/scripts
liblist=smartgears.list
function showhelp {
echo -e "\nusage: install [-d <distro directory>] -s tomcat|<lib directory> -a [app directory] [-g gHN directory] [-x|-h] \n"
echo " <distro directory> = the directory with the distribution of SmartGears ${project.version}."
echo " By default, this is the parent directory of this script."
echo " <lib directory> = the directory with libraries shared by all applications in the target container."
echo " <app directory> = the directory with all the applications in the target container."
echo " <gHN directory> = the directory with logs and files related to the gCube Hosting Node."
echo " By default, this is value of the GHN_HOME env var."
echo " tomcat = Sets <lib directory> and <app directory> for a target Tomcat container."
echo " x = dry run."
echo -e " h = shows this help.\n"
}
while getopts ":d:s:g:a:xh" opt; do
case $opt in
d) distro=$OPTARG;;
s) shared=$OPTARG;;
g) ghnhome=$OPTARG;;
a) apps=$OPTARG;;
x) dryrun="true";;
h) showhelp
exit 0 ;;
:) echo -e "\nERROR:option -$OPTARG requires an argument." >&2 ;
showhelp;
echo -e "\naborting.\n"
exit 1;;
\?) echo -e "\nERROR:invalid option: -$OPTARG";
showhelp;
echo -e "\naborting.\n"
exit 1 >&2 ;;
esac
done
if [ -z "$ghnhome" ]; then
if [ -z "$GHN_HOME" ]; then
echo -e "\nERROR:please specify the gHN directory (-g) or define the GHN_HOME env var." >&2
showhelp
echo -e "\naborting.\n"
exit 1
else
ghnhome=$GHN_HOME
fi
fi
if [ ! -d "$ghnhome" ]; then
if [ -z "$dryrun" ]; then
mkdir $ghnhome
fi
fi
#tomcat target
if [ "$shared" = "tomcat" ]; then
if [ -z "$CATALINA_HOME" ]; then
echo -e "\nERROR: env var CATALINA_HOME is undefined." >&2
showhelp
echo -e "\naborting.\n"
exit 1
fi
shared=$CATALINA_HOME/lib
apps=$CATALINA_HOME/webapps
fi
#shared is set
if [ -z "$shared" ]; then
echo -e "\nERROR: shared directory is undefined (-s)." >&2
showhelp
echo -e "\naborting.\n"
exit 1
fi
#shared exists and is a directory
if [ ! -d "$shared" ]; then
echo -e "\nERROR: $shared does not exist or is not a directory, aborting." >&2
exit 1;
fi
#shared exists and is a directory
if [ ! -d "$apps" ]; then
echo -e "\nERROR: $apps does not exist or is not a directory, aborting." >&2
exit 1;
fi
#distrolibs exists and is a directory
if [ ! -d "$distrolibs" ]; then
echo -e "\nERROR: $distrolibs does not exist or is not a directory, aborting."
exit 1;
fi
#distroapps exists and is a directory
if [ ! -d "$distroapps" ]; then
echo -e "\nERROR: $distroapps does not exist or is not a directory, aborting."
exit 1;
fi
echo -e "\nInstalling SmartGears ${project.version}\n"
echo -e " target gHN directory = $(cd $(dirname $ghnhome); pwd)/$(basename $ghnhome)"
echo -e " target shared directory = $(cd $(dirname $shared); pwd)/$(basename $shared)"
echo -e " target app directory = $(cd $(dirname $apps); pwd)/$(basename $apps)"
shopt -s nullglob
#uninstall libraries
if [ -f $shared/$liblist ]; then
echo -e "\nuninstalling existing components \c"
while read line; do
if [ -z "$dryrun" ]; then
rm $shared/$line
fi
echo -n "."
sleep .01
done < $shared/$liblist
if [ -z "$dryrun" ]; then
rm $shared/$liblist
fi
fi
#install libraries
echo -e "\ninstalling components \c"
for f in $distrolibs/*.*;
do
if [ -z "$dryrun" ]; then
cp $f $shared/
basename $f >> $shared/$liblist
fi
echo -n "."
sleep .01
done
#install apps
echo -e "\ninstalling applications \c"
for f in $distroapps/*;
do
if [ -z "$dryrun" ]; then
cp $f $apps/
fi
echo -n "."
sleep .01
done
#install scripts
echo -e "\ninstalling scripts \c"
if [ ! -d "$ghnhome/scripts" ]; then
if [ -z "$dryrun" ]; then
mkdir $ghnhome/scripts
fi
fi
for f in $distroscripts/*;
do
if [ -z "$dryrun" ]; then
cp $f $ghnhome/scripts/
fi
echo -n "."
sleep .01
done
#install config
echo -e "\ninstalling configuration \c"
if [ ! -d "$ghnhome/container.xml" ]; then
if [ -z "$dryrun" ]; then
cp $distro/container.xml $ghnhome/
fi
echo -n "."
sleep .01
fi
if [ -z "$dryrun" ]; then
cat $distro/logback.xml | sed "s|\${LOGFILE}|$ghnhome|" > $shared/logback.xml
echo -n "."
sleep .01
fi
echo -e "\ndone.\n"