1#!/bin/bash
2ZIP_OPTION=$1
3pushd `dirname ${BASH_SOURCE[0]}` >/dev/null
4OSSIMCI_SCRIPT_DIR=`pwd -P`
5pushd $OSSIMCI_SCRIPT_DIR/../.. >/dev/null
6export OSSIM_DEV_HOME=$PWD
7popd > /dev/null
8popd >/dev/null
9
10source $OSSIMCI_SCRIPT_DIR/ossim-env.sh
11
12# Establish CMAKE's install directory:
13if [ -z "$OSSIM_INSTALL_PREFIX" ]; then
14    export OSSIM_INSTALL_PREFIX=$OSSIM_DEV_HOME/install
15fi
16
17echo "STATUS: Checking presence of env var OSSIM_BUILD_DIR = <$OSSIM_BUILD_DIR>...";
18if [ -z $OSSIM_BUILD_DIR ]; then
19  export OSSIM_BUILD_DIR=$OSSIM_DEV_HOME/build;
20  if [ ! -d $OSSIM_BUILD_DIR ] ; then
21    echo "ERROR: OSSIM_BUILD_DIR = <$OSSIM_BUILD_DIR> does not exist at this location. Cannot install";
22    exit 1;
23  fi
24fi
25
26echo "STATUS: Performing make install to <$OSSIM_INSTALL_PREFIX>"
27pushd $OSSIM_DEV_HOME/ossim/scripts
28./install.sh
29if [ $? -ne 0 ]; then
30  echo; echo "ERROR: Error encountered ossim install. Check the console log and correct."
31  popd >/dev/null
32  exit 1
33fi
34popd >/dev/null
35
36mkdir -p $OSSIM_INSTALL_PREFIX/etc/profile.d
37mkdir -p $OSSIM_INSTALL_PREFIX/share/ossim/templates
38
39cp $OSSIM_DEV_HOME/ossim/support/linux/etc/profile.d/ossim.sh $OSSIM_INSTALL_PREFIX/etc/profile.d/ossim.sh
40cp $OSSIM_DEV_HOME/ossim/support/linux/etc/profile.d/ossim.csh $OSSIM_INSTALL_PREFIX/etc/profile.d/ossim.csh
41cp $OSSIM_DEV_HOME/ossim/support/linux/service-wrapper-initd-template $OSSIM_INSTALL_PREFIX/share/ossim/templates/service-wrapper-initd-template
42cp $OSSIM_DEV_HOME/ossim/support/linux/service-wrapper-systemd-template $OSSIM_INSTALL_PREFIX/share/ossim/templates/service-wrapper-systemd-template
43
44chmod -R 755 $OSSIM_INSTALL_PREFIX/etc/profile.d
45chmod 755 $OSSIM_INSTALL_PREFIX/share/ossim/templates/service-wrapper*
46
47#install -p -m755 -D $OSSIM_DEV_HOME/ossim/support/linux/etc/profile.d/ossim.sh $OSSIM_INSTALL_PREFIX/etc/profile.d/ossim.sh
48#install -p -m755 -D $OSSIM_DEV_HOME/ossim/support/linux/etc/profile.d/ossim.csh $OSSIM_INSTALL_PREFIX/etc/profile.d/ossim.csh
49#install -p -m755 -D $OSSIM_DEV_HOME/ossim/support/linux/service-wrapper-initd-template $OSSIM_INSTALL_PREFIX/share/ossim/templates/service-wrapper-initd-template
50#install -p -m755 -D $OSSIM_DEV_HOME/ossim/support/linux/service-wrapper-systemd-template $OSSIM_INSTALL_PREFIX/share/ossim/templates/service-wrapper-systemd-template
51
52echo; echo "STATUS: Install completed successfully. Install located in $OSSIM_INSTALL_PREFIX"
53
54if [ "$BUILD_KAKADU_PLUGIN" = "ON" ]; then
55   if [ -z $KAKADU_LIBRARY ]; then
56      echo "ERROR: KAKADU_LIBRARY env variable not set for install"
57      exit 1
58   fi
59
60   if [ -z $KAKADU_AUX_LIBRARY ]; then
61      echo "ERROR: KAKADU_AUX_LIBRARY env variable not set for install"
62      exit 1
63   fi
64
65   # Need Kakadu shared libs for jpip server. drb - 20160414
66   echo "STATUS: Performing install of $KAKADU_LIBRARY to <$OSSIM_INSTALL_PREFIX>"
67   cp $KAKADU_LIBRARY $OSSIM_INSTALL_PREFIX/lib64
68   echo "STATUS: Performing install of $KAKADU_AUX_LIBRARY to <$OSSIM_INSTALL_PREFIX>"
69   cp $KAKADU_AUX_LIBRARY $OSSIM_INSTALL_PREFIX/lib64
70fi
71
72if [ "$BUILD_OMS" == "ON" ] ; then
73   echo "STATUS: Performing joms install to <$OSSIM_INSTALL_PREFIX>"
74   pushd $OSSIM_DEV_HOME/ossim-oms/joms/build_scripts/linux
75   ./install.sh
76   if [ $? -ne 0 ]; then
77     echo; echo "ERROR: Error encountered during make install of joms. Check the console log and correct."
78     popd
79     exit 1
80   fi
81fi
82TIMESTAMP=`date +%Y-%m-%d-%H%M`
83
84#####
85# For binary install we will go ahead and define a service wrapper
86# for the JPIP server.
87#
88mkdir -p ${OSSIM_INSTALL_PREFIX}/etc/init.d ${OSSIM_INSTALL_PREFIX}/lib/systemd/system
89chmod 755 ${OSSIM_INSTALL_PREFIX}/etc/init.d
90chmod 755 ${OSSIM_INSTALL_PREFIX}/lib/systemd/system
91
92#install -d -m755 ${OSSIM_INSTALL_PREFIX}/etc/init.d
93#install -d -m755 ${OSSIM_INSTALL_PREFIX}/lib/systemd/system
94pushd $OSSIM_DEV_HOME/ossim/support/linux/
95app=jpip-server
96sed -e "s/{{program_name}}/${app}/g"  -e "s/{{program_user}}/omar/g" -e "s/{{program_group}}/omar/g" < service-wrapper-systemd-template >${OSSIM_INSTALL_PREFIX}/lib/systemd/system/${app}.service
97sed -e "s/{{program_name}}/${app}/g"  -e "s/{{program_user}}/omar/g" -e "s/{{program_group}}/omar/g" < service-wrapper-initd-template >${OSSIM_INSTALL_PREFIX}/etc/init.d/${app}
98popd
99
100echo; echo "STATUS: Writing install info file to: <$OSSIM_INSTALL_PREFIX/gocd_install.info>..."
101pushd $OSSIM_INSTALL_PREFIX
102INSTALL_DIRNAME=${PWD##*/}
103echo "
104Build timestamp: $TIMESTAMP
105Pipeline Name:   $GO_PIPELINE_NAME
106Job Name:        $GO_JOB_NAME
107" > gocd_install.info
108cd ..
109
110if [ "$ZIP_OPTION" == "-z" ]; then
111  echo; echo "STATUS: Zipping up install directory: <$INSTALL_DIRNAME>..."
112  FILENAME_TS="install_$GO_PIPELINE_NAME_$TIMESTAMP.tgz"
113  tar cvfz $FILENAME_TS $INSTALL_DIRNAME
114  if [ $? -ne 0 ]; then
115    echo; echo "ERROR: Error encountered while zipping the install dir. Check the console log and correct."
116    popd
117    exit 1
118  fi
119
120  # Create a link that can be used as artifact of latest build/install. This will
121  # overwrite previous sandbox's so only the latest is used for testing (standalone)
122  # or generating expected results
123  ln -s $FILENAME_TS "install.tgz"
124  echo "STATUS: Successfully zipped install dir to <$PWD/$FILENAME_TS> and created link <$PWD/install.tgz>."
125fi
126
127popd # Out of dir containing install subdir
128