###IIB Install
#!/bin/bash
#FILE="${1}.0.0.${2}-IIB-LINUX64-DEVELOPER.tar.gz"
set -x
FILE="${1}.0.0-IIB-LINUXX64-FP00${2}.tar.gz"
FOLDER="/iib-${1}.0.0.${2}"
ACTION="${3}"
MAJORVERSION=${1}
INSTALLDIR="/apps"
MQSILIST="${INSTALLDIR}/iib/server/bin/mqsilist"
MQSISTOP="${INSTALLDIR}/iib/server/bin/mqsistop"
MQSISTART="${INSTALLDIR}/iib/server/bin/mqsistart"
MQSICHANGEBROKER="${INSTALLDIR}/iib/server/bin/mqsichangebroker"
# Test last command successful function
exitcode()
{
if [ $? != 0 ]
then
exit 1
fi
}
usage()
{
SCRIPTNAME=`basename $0`
echo "Usage:"
echo " $SCRIPTNAME [Major Version] [Minor Version] [Action]"
echo " Action:"
echo " install = Fresh install"
echo " upgrade = Upgrade to a newer version"
echo " remove = Remove older version"
echo " uninstall = Remove everything"
exit 1
}
# Test if current version is already installed
is_version_installed()
{
[ -d ${INSTALLDIR}${FOLDER} ] && echo "This version is already installed." && exit 1
}
# Test if the user mqm exists
id_mqm()
{
id mqm > /dev/null
[ $? != 0 ] && echo "The user mqm does not exist, install MQ first." && exit 1
}
# If /apps/iib is symlink then ACTION cannot be install
iib_sym_exists()
{
[ -L /apps/iib ] && echo "IIB is already installed. Use upgrade, remove or uninstall" && exit 1
}
# If /apps/iib does not exist, then ACTION cannot be upgrade, remove or uninstall
iib_sym_not_exists()
{
[ ! -L /apps/iib ] && echo "IIB is not installed. Use install" && exit 1
}
# Add config for the mqm user to the ~mqm/.bash_profile user
update_bash_profile()
{
if [ -f ~mqm/.bash_profile ]; then
grep '/apps/iib/server/bin/mqsiprofile' ~mqm/.bash_profile || echo "# Run the IIB v10 profile" >> ~mqm/.bash_profile
grep '/apps/iib/server/bin/mqsiprofile' ~mqm/.bash_profile || echo ". /apps/iib/server/bin/mqsiprofile" >> ~mqm/.bash_profile
grep 'export ODBCINI=/var/esb/odbc/odbc.ini' ~mqm/.bash_profile || echo "# Set Investec IIB variables" >> ~mqm/.bash_profile
grep 'export ODBCINI=/var/esb/odbc/odbc.ini' ~mqm/.bash_profile || echo "export ODBCINI=/var/esb/odbc/odbc.ini" >> ~mqm/.bash_profile
grep 'export ODBCSYSINI=/var/esb/odbc/' ~mqm/.bash_profile || echo "export ODBCSYSINI=/var/esb/odbc/" >> ~mqm/.bash_profile
grep 'export MQSI_FILENODES_ROOT_DIRECTORY=~' ~mqm/.bash_profile || echo "export MQSI_FILENODES_ROOT_DIRECTORY=~" >> ~mqm/.bash_profile
fi
}
# Download application
app_download()
{
wget -N http://invldnvlbas3/repo/investec/misc/mq/${MAJORVERSION}/${FILE}
exitcode
# Extract files
echo "Extracting files..."
tar -xvzf ${FILE} >/dev/null
exitcode
rm -f ${FILE}
}
stop_brokers()
{
# Get a list of Brokers
BROKERLIST=($(su - mqm -c ${MQSILIST} |awk '/Integration node/ {print $4}' | tr -d "\'"))
# Stop Brokers if running
su - mqm -c ${MQSILIST} | grep running > /dev/null
if [ $? = 0 ]; then
for i in ${BROKERLIST[@]}; do
echo "Stopping Broker ${i}"
su - mqm -c "${MQSISTOP} ${i}"
exitcode
# Set variable to confirm running brokers were stopped.
STOP_BROKERS=y
done
else
# Set variable to confirm running brokers were NOT stopped.
STOP_BROKERS=n
fi
}
remove_sym_link()
{
rm -f iib
exitcode
}
link_iib_existing()
{
ln -s .${FOLDER} iib
exitcode
}
create_sym_link_install()
{
# Create symbolic links for new installs
ln -s .${FOLDER} iib
exitcode
mkdir /opt/ibm
ln -s ${INSTALLDIR}/iib /opt/ibm/iib
exitcode
}
accept_license()
{
# Accept the license
echo "Accepting License"
${INSTALLDIR}/iib/iib make registry global accept license silently
exitcode
}
make_dirs()
{
echo "Making directories"
mkdir -p ${INSTALLDIR}/iib/common/profiles && chown mqm:mqm ${INSTALLDIR}/iib/common/profiles
exitcode
}
redefine_brokers()
{
# Undefine, define and start Brokers as a service if they were running.
if [ ${STOP_BROKERS} = y ]
then
su - mqm -c ${MQSILIST} | grep stopped > /dev/null
if [ $? = 0 ]; then
for i in ${BROKERLIST[@]}; do
echo "Undefining Broker ${i}"
su - mqm -c "${MQSICHANGEBROKER} ${i} -d undefined"
exitcode
echo "Defining Broker ${i}"
su - mqm -c "${MQSICHANGEBROKER} ${i} -d defined"
exitcode
done
# Start Brokers
for i in ${BROKERLIST[@]}; do
echo "Starting Broker ${i}"
su - mqm -c "${MQSISTART} ${i}"
exitcode
done
else
echo "No Brokers redefined"
fi
fi
}
remove_folder()
{
rm -rf ${FOLDER}
exitcode
}
remove_all_folders()
{
rm -rf /apps/iib-*
rm -rf /opt/ibm
}
# Test for number of parameters and content
[ $# != 3 ] && usage
[[ $1 =~ ^([0-9]){1,2}$ ]] || usage
[[ $2 =~ ^([0-9]){1,2}$ ]] || usage
[[ $3 =~ ^(install|upgrade|remove|uninstall)$ ]] || usage
cd ${INSTALLDIR}
case "$3" in
install)
is_version_installed
id_mqm
iib_sym_exists
update_bash_profile
app_download
create_sym_link_install
accept_license
make_dirs
;;
upgrade)
is_version_installed
id_mqm
iib_sym_not_exists
app_download
stop_brokers
remove_sym_link
link_iib_existing
accept_license
make_dirs
redefine_brokers
;;
remove)
stop_brokers
remove_sym_link
remove_folder
;;
uninstall)
iib_sym_not_exists
stop_brokers
remove_sym_link
remove_all_folders
;;
*)
usage
esac
###rescan_luns.sh
#!/bin/bash
echo
read -r -p "Rescan all LUNs? [y/N] " response
[[ $response =~ ^([nN])$ ]] && exit 1
echo -n "Detecting new devices..."
for i in $(ls -d /sys/class/scsi_host/*)
do
echo "- - -" > ${i}/scan
done
echo "done"
echo -n "Rescanning existing disks..."
for i in $(ls -d /sys/class/scsi_device/*)
do
echo "1" > ${i}/device/rescan
done
echo "done"
### Wrapper to delete files
#!/bin/bash
#
# rm wrapper for Calypso
#
# (c) Dmitri Ulyanov, 2015
#
#
WORK_PATH=$1
u_exit () {
trap - EXIT
exit $1
}
trap u_exit EXIT
REAL_WORK_PATH=$(readlink -f "$WORK_PATH")
[[ "$REAL_WORK_PATH" =~ ^/apps/calypso/.+ ]] || { echo "invalid path: $REAL_WORK_PATH"; u_exit 1; }
/bin/rm -rf "$REAL_WORK_PATH" && u_exit 0 || u_exit 1