2022-04-12 14:04:55 -04:00
#!/bin/bash
2018-02-15 12:12:00 -07:00
# about: AWIPS install manager
# devorg: Unidata Program Center
2021-04-01 14:08:24 -04:00
# author: Michael James
# maintainer: <tiffanym@ucar.edu>
2018-09-20 11:06:00 -06:00
# use: ./awips_install.sh (--cave|--edex|--database|--ingest|--help)
2018-02-15 12:12:00 -07:00
dir = " $( cd " $( dirname " $0 " ) " ; pwd -P ) "
2018-08-06 14:13:33 -06:00
usage = " $( basename " $0 " ) [-h] (--cave|--edex|--database|--ingest) #script to install Unidata AWIPS components.\n
2018-02-15 12:12:00 -07:00
-h, --help show this help text\n
--cave install CAVE for x86_64 Linux\n
2018-08-06 14:13:33 -06:00
--edex, --server install EDEX Standaone Server x86_64 Linux\n
--database install EDEX Request/Database x86_64 Linux\n
--ingest install EDEX Ingest Node Server x86_64 Linux\n "
2018-02-15 12:12:00 -07:00
function stop_edex_services {
for srvc in edex_ldm edex_camel qpidd httpd-pypies edex_postgres ; do
if [ -f /etc/init.d/$srvc ] ; then
service $srvc stop
fi
done
}
function check_yumfile {
2021-06-08 10:07:16 -04:00
if [ [ $( grep "release 7" /etc/redhat-release) ] ] ; then
2021-12-09 12:47:06 -05:00
repofile = awips2.repo
2021-06-08 10:07:16 -04:00
else
echo "You need to be running CentOS7 or RedHat7"
exit
fi
2021-06-11 17:18:21 -04:00
if [ -f /etc/yum.repos.d/awips2.repo ] ; then
2021-07-13 09:40:08 -04:00
date = $( date +%Y%m%d-%H:%M:%S)
2021-06-08 10:07:16 -04:00
cp /etc/yum.repos.d/awips2.repo /etc/yum.repos.d/awips2.repo-${ date }
2018-02-15 12:12:00 -07:00
fi
2021-06-08 10:07:16 -04:00
2021-12-09 12:47:06 -05:00
wget_url = " https://downloads.unidata.ucar.edu/awips2/current/linux/ ${ repofile } "
2021-06-08 10:07:16 -04:00
echo " wget -O /etc/yum.repos.d/awips2.repo ${ wget_url } "
wget -O /etc/yum.repos.d/awips2.repo ${ wget_url }
2018-02-15 12:12:00 -07:00
yum clean all --enablerepo= awips2repo --disablerepo= "*" 1>> /dev/null 2>& 1
2022-01-11 11:12:05 -05:00
yum --enablerepo= awips2repo clean metadata
2018-02-15 12:12:00 -07:00
}
function check_limits {
if [ [ ! $( grep awips /etc/security/limits.conf) ] ] ; then
echo "Checking /etc/security/limits.conf for awips: Not found. Adding..."
printf "awips soft nproc 65536\nawips soft nofile 65536\n" >> /etc/security/limits.conf
fi
}
2018-03-23 12:29:49 -06:00
function check_epel {
if [ [ ! $( rpm -qa | grep epel-release) ] ] ; then
yum install epel-release -y
yum clean all
fi
}
2022-01-11 11:12:05 -05:00
function check_wget {
if ! [ [ $( rpm -qa | grep ^wget) ] ] ; then
# install wget if not installed
yum install wget -y
fi
}
function check_rsync {
if ! [ [ $( rpm -qa | grep ^rsync) ] ] ; then
# install rsync if not installed
yum install rsync -y
fi
}
2018-02-15 12:12:00 -07:00
function check_netcdf {
if [ [ $( rpm -qa | grep netcdf-AWIPS) ] ] ; then
# replaced by epel netcdf(-devel) pkgs in 17.1.1-5 so force remove
yum remove netcdf-AWIPS netcdf netcdf-devel -y
fi
}
2021-12-07 13:15:17 -05:00
function check_git {
if ! [ [ $( rpm -qa | grep ^git-[ 12] ) ] ] ; then
# install git if not installed
yum install git -y
fi
}
2021-06-02 15:37:13 -04:00
function check_cave {
if [ [ $( rpm -qa | grep awips2-cave) ] ] ; then
echo $'\n' CAVE is currently installed and needs to be removed before installing.
pkill cave.sh
pkill -f 'cave/run.sh'
remove_cave
fi
}
function remove_cave {
yum groupremove awips2-cave -y
if [ [ $( rpm -qa | grep awips2-cave) ] ] ; then
echo "
= = = = = = = = = = = = = = = = = = = FAILED = = = = = = = = = = = = = = = = = = = = = = = = = = =
Something went wrong with the un-install of CAVE
and packages are still installed. Once the CAVE
group has been successfully uninstalled, you can try
running this script again.
Try running a \" yum grouplist\" to see if the AWIPS
CAVE group is still installed and then do a
\" yum groupremove [ GROUP NAME] \" .
ex. yum groupremove 'AWIPS EDEX Server'
You may also need to run \" yum groups mark
remove [ GROUP NAME] \"
ex. yum groups mark remove 'AWIPS CAVE' "
exit
else
dir = cave
echo " Removing /awips2/ $dir "
rm -rf /awips2/$dir
rm -rf /home/awips/caveData
fi
}
2018-02-15 12:12:00 -07:00
function check_edex {
if [ [ $( rpm -qa | grep awips2-edex) ] ] ; then
2021-06-02 15:37:13 -04:00
echo "found EDEX RPMs installed. The current EDEX needs to be removed before installing."
check_remove_edex
2018-02-15 12:12:00 -07:00
else
2018-07-05 11:49:57 -06:00
if [ -d /awips2/database/data/ ] ; then
echo "cleaning up /awips2/database/data/ for new install..."
rm -rf /awips2/database/data/
2018-02-15 12:12:00 -07:00
fi
fi
2021-06-02 15:37:13 -04:00
for dir in /awips2/tmp /awips2/data_store ; do
2018-02-15 12:12:00 -07:00
if [ ! -d $dir ] ; then
echo " creating $dir "
mkdir -p $dir
chown awips:fxalpha $dir
fi
done
if getent passwd awips & >/dev/null; then
echo -n ''
else
echo
echo "--- user awips does not exist"
echo "--- installation will continue but EDEX services may not run as intended"
fi
}
2021-06-02 15:37:13 -04:00
function check_remove_edex {
while true; do
read -p " Do you wish to remove EDEX? (Please type yes or no) `echo $'\n> '` " yn
case $yn in
[ Yy] * ) remove_edex; break; ;
[ Nn] * ) echo "Exiting..." ; exit; ;
* ) echo "Please answer yes or no"
esac
done
}
2022-04-12 14:04:55 -04:00
function calcLogSpace {
a = ( " $@ " )
logDiskspace = 0
for path in " ${ a [@] } " ; do
if [ -d $path ] || [ -f $path ] ; then
out = ` du -sk $path | cut -f1`
logDiskspace = $(( logDiskspace + $out ))
fi
done
logDiskspace = $( echo " scale=8; $logDiskspace *.000000953674316 " | bc)
}
function calcConfigSpace {
a = ( " $@ " )
configDiskspace = 0
for path in " ${ a [@] } " ; do
if [ -d $path ] || [ -f $path ] ; then
out = ` du -sk $path | cut -f1`
configDiskspace = $(( configDiskspace + $out ))
fi
done
configDiskspace = $( echo " scale=8; $configDiskspace *.000000953674316 " | bc)
}
function backupLogs {
a = ( " $@ " )
log_backup_dir = ${ backup_dir } /awips2_backup_${ ver } _${ date } /logs
if [ [ ! -d ${ log_backup_dir } ] ] ; then
mkdir -p ${ log_backup_dir }
fi
echo " Backing up to $log_backup_dir "
for path in " ${ a [@] } " ; do
if [ -d $path ] || [ -f $path ] ; then
rsync -apR $path $log_backup_dir
fi
done
}
function backupConfigs {
a = ( " $@ " )
config_backup_dir = ${ backup_dir } /awips2_backup_${ ver } _${ date } /configs
if [ [ ! -d $config_backup_dir ] ] ; then
mkdir -p $config_backup_dir
fi
echo " Backing up to $config_backup_dir "
for path in " ${ a [@] } " ; do
if [ -d $path ] || [ -f $path ] ; then
rsync -apR $path $config_backup_dir
fi
done
}
2021-06-02 15:37:13 -04:00
function remove_edex {
2022-04-12 14:04:55 -04:00
logPaths = ( "/awips2/edex/logs" "/awips2/httpd_pypies/var/log/httpd/" "/awips2/database/data/pg_log/" "/awips2/qpid/log/" "/awips2/ldm/logs/" )
configPaths = ( "/awips2/database/data/pg_hba*conf" "/awips2/edex/data/utility" "/awips2/edex/bin" "/awips2/ldm/etc" "/awips2/ldm/dev" "/awips2/edex/conf" "/awips2/edex/etc" "/usr/bin/edex" "/etc/init*d/edexServiceList" "/var/spool/cron/awips" )
2021-06-02 15:37:13 -04:00
while true; do
2022-04-12 14:04:55 -04:00
read -p " `echo $'\n'`Please make a selction for what you would like backed up. If you choose not to back up files you will lose all your configurations:
1. logs
2. configs
3. both logs and configs
4. none
` echo $'\n> ' ` " backup_ans
#User chooses to back of files
if [ [ $backup_ans = ~ [ 1-3] ] ] ; then
echo " ANSWER: $backup_ans "
while true; do
read -p " `echo $'\n'`What location do you want your files backed up to? `echo $'\n> '` " backup_dir
2022-01-11 11:12:05 -05:00
2022-04-12 14:04:55 -04:00
if [ ! -d $backup_dir ] ; then
echo " $backup_dir does not exist, enter a path that exists "
else
#Check to see if user has enough space to backup
backupspace = ` df -k --output= avail " $backup_dir " | tail -n1`
backupspace = $( echo " scale=8; $backupspace *.000000953674316 " | bc)
date = $( date +'%Y%m%d-%H:%M:%S' )
echo "Checking to see which version of AWIPS is installed..."
rpm = ` rpm -qa | grep awips2-[ 12] `
IFS = '-' str = ( ${ rpm } )
IFS = . str2 = ( ${ str [2] } )
vers = " ${ str [1] } - ${ str2 [0] } "
ver = " ${ vers //[.]/- } "
if [ $backup_ans = 1 ] ; then
calcLogSpace " ${ logPaths [@] } "
#Don't let user backup data if there isn't enough space
if ( ( $( echo " $logDiskspace > $backupspace " | bc ) ) ) ; then
printf " You do not have enough disk space to backup this data to $backup_dir . You only have %.2f GB free and need %.2f GB.\n " $backupspace $logDiskspace
#Backup logs
else
backupLogs " ${ logPaths [@] } "
printf " %.2f GB of logs were backed up to $backup_dir \n " " $logDiskspace "
fi
elif [ $backup_ans = 2 ] ; then
calcConfigSpace " ${ configPaths [@] } "
#Don't let user backup data if there isn't enough space
if ( ( $( echo " $configDiskspace > $backupspace " | bc ) ) ) ; then
printf " You do not have enough disk space to backup this data to $backup_dir . You only have %.2f GB free and need %.2f GB.\n " $backupspace $configDiskspace
#Backup logs
else
backupConfigs " ${ configPaths [@] } "
printf " %.2f GB of configs were backed up to $backup_dir \n " " $configDiskspace "
fi
elif [ $backup_ans = 3 ] ; then
calcLogSpace " ${ logPaths [@] } "
calcConfigSpace " ${ configPaths [@] } "
configLogDiskspace = $( echo " $logDiskspace + $configDiskspace " | bc)
#Don't let user backup data if there isn't enough space
if ( ( $( echo " $configLogDiskspace > $backupspace " | bc ) ) ) ; then
printf " You do not have enough disk space to backup this data to $backup_dir . You only have %.2f GB free and need %.2f GB.\n " $backupspace $configLogDiskspace
#Backup logs
else
backupLogs " ${ logPaths [@] } "
backupConfigs " ${ configPaths [@] } "
printf " %.2f GB of logs and configs were backed up to $backup_dir \n " " $configLogDiskspace "
fi
fi
break
fi
done
break
#User chooses not to back up any files
elif [ $backup_ans = 4 ] ; then
2022-01-11 11:12:05 -05:00
while true; do
2022-04-12 14:04:55 -04:00
read -p " `echo $'\n'`Are you sure you don't want to back up any AWIPS configuration or log files? Type \"yes\" to confirm, \"no\" to select a different backup option, or \"quit\" to exit` echo $'\n> '` " answer
2022-01-11 11:12:05 -05:00
answer = $( echo $answer | tr '[:upper:]' '[:lower:]' )
if [ $answer = yes ] || [ $answer = y ] ; then
break 2 ;
2022-01-11 12:58:04 -05:00
elif [ $answer = quit ] || [ $answer = q ] ; then
exit;
2022-04-12 14:04:55 -04:00
elif [ $answer = no ] || [ $answer = n ] ; then
break
2022-01-11 11:12:05 -05:00
fi
done
2022-04-12 14:04:55 -04:00
#User did not make a valid selection
else
echo "Please make a valid selection (1, 2, 3, or 4)"
2021-06-02 15:37:13 -04:00
fi
done
2022-04-12 14:04:55 -04:00
FILE = "/opt/bin/logarchival/edex_upgrade.pl"
if test -f " $FILE " ; then
echo "Running /opt/bin/logarchival/edex_upgrade.pl and logging to /home/awips/crons/logarchival/general"
/opt/bin/logarchival/edex_upgrade.pl >> /home/awips/crons/logarchival/general
fi
2021-06-02 15:37:13 -04:00
if [ [ $( rpm -qa | grep awips2-cave) ] ] ; then
echo "CAVE is also installed, now removing EDEX and CAVE"
2021-06-08 10:07:16 -04:00
pkill cave.sh
pkill -f 'cave/run.sh'
rm -rf /home/awips/caveData
2021-06-02 15:37:13 -04:00
else
echo "Now removing EDEX"
fi
2021-12-07 13:15:17 -05:00
yum groupremove awips2-server awips2-database awips2-ingest awips2-cave awips2-qpid-lib -y
2021-06-02 15:37:13 -04:00
if [ [ $( rpm -qa | grep awips2 | grep -v cave) ] ] ; then
echo "
= = = = = = = = = = = = = = = = = = = FAILED = = = = = = = = = = = = = = = = = = = = = = = = = = =
Something went wrong with the un-install of EDEX
and packages are still installed. Once the EDEX
groups have been successfully uninstalled, you can try
running this script again.
Try running a \" yum grouplist\" to see which AWIPS
group is still installed and then do a
\" yum groupremove [ GROUP NAME] \" .
ex. yum groupremove 'AWIPS EDEX Server'
You may also need to run \" yum groups mark
remove [ GROUP NAME] \"
ex. yum groups mark remove 'AWIPS EDEX Server' "
exit
else
2022-04-12 14:04:55 -04:00
awips2_dirs = ( "data" "database" "data_store" "edex" "hdf5" "httpd_pypies" "java" "ldm" "postgres" "psql" "pypies" "python" "qpid" "tmp" "tools" "yajsw" )
for dir in ${ awips2_dirs [@] } ; do
2021-12-09 12:47:06 -05:00
if [ $dir != dev ] && [ $dir != cave ] ; then
2021-06-02 15:37:13 -04:00
echo " Removing /awips2/ $dir "
rm -rf /awips2/$dir
fi
done
fi
}
2018-03-23 12:29:49 -06:00
function check_users {
if ! id "awips" >/dev/null 2>& 1; then
groupadd fxalpha && useradd -G fxalpha awips
fi
}
2018-02-15 12:12:00 -07:00
function server_prep {
2018-03-23 12:29:49 -06:00
check_users
2018-02-15 12:12:00 -07:00
check_yumfile
stop_edex_services
check_limits
check_netcdf
2022-01-11 11:12:05 -05:00
check_wget
check_rsync
2018-02-15 12:12:00 -07:00
check_edex
2021-12-07 13:15:17 -05:00
check_git
2019-06-24 11:12:13 -06:00
check_epel
2018-02-15 12:12:00 -07:00
}
2021-12-14 11:08:58 -05:00
function disable_ndm_update {
crontab -u awips -l >cron_backup
crontab -u awips -r
sed -i -e 's/30 3 \* \* \* \/bin\/perl \/awips2\/dev\/updateNDM.pl/#30 3 \* \* \* \/bin\/perl \/awips2\/dev\/updateNDM.pl/' cron_backup
crontab -u awips cron_backup
rm cron_backup
}
2018-03-23 12:29:49 -06:00
function cave_prep {
2021-06-02 15:37:13 -04:00
check_cave
2018-03-23 12:29:49 -06:00
check_users
check_yumfile
check_netcdf
2022-01-11 11:12:05 -05:00
check_wget
2018-03-23 12:29:49 -06:00
check_epel
2022-01-11 11:12:05 -05:00
rm -rf /home/awips/caveData
2018-03-23 12:29:49 -06:00
}
2018-02-15 12:12:00 -07:00
2022-05-09 17:13:13 -04:00
function cleanup {
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/awips2.repo
2022-05-09 17:41:45 -04:00
if $alterReg ; then
2022-05-09 17:13:13 -04:00
sed -i 's/@LDM_PORT@/388/' /awips2/ldm/etc/registry.xml
fi
2022-05-09 17:41:45 -04:00
if $disableNDM ; then
2022-05-09 17:13:13 -04:00
disable_ndm_update
fi
2022-05-09 17:41:45 -04:00
echo " $k has finished installing, the install log can be found in /tmp/awips-install.log "
2022-05-09 17:13:13 -04:00
}
2018-02-15 12:12:00 -07:00
if [ $# -eq 0 ] ; then
key = "-h"
else
key = " $1 "
fi
2022-05-09 17:41:45 -04:00
disableNDM = true
alterReg = true
2018-02-15 12:12:00 -07:00
case $key in
--cave)
2018-03-23 12:29:49 -06:00
cave_prep
2018-02-15 12:12:00 -07:00
yum groupinstall awips2-cave -y 2>& 1 | tee -a /tmp/awips-install.log
2022-05-09 17:13:13 -04:00
alterReg = false
disableNDM = false
k = "CAVE"
2018-02-15 12:12:00 -07:00
; ;
--server| --edex)
server_prep
yum groupinstall awips2-server -y 2>& 1 | tee -a /tmp/awips-install.log
2022-05-09 17:13:13 -04:00
disableNDM = false
k = "EDEX server"
2018-02-15 12:12:00 -07:00
; ;
2018-08-06 14:13:33 -06:00
--database)
server_prep
yum groupinstall awips2-database -y 2>& 1 | tee -a /tmp/awips-install.log
2022-05-09 17:13:13 -04:00
k = "EDEX database"
2018-08-06 14:13:33 -06:00
; ;
2018-02-15 12:12:00 -07:00
--ingest)
server_prep
yum groupinstall awips2-ingest -y 2>& 1 | tee -a /tmp/awips-install.log
2022-05-09 17:13:13 -04:00
k = "EDEX ingest"
2018-02-15 12:12:00 -07:00
; ;
-h| --help)
echo -e $usage
exit
; ;
esac
2022-05-10 08:08:51 -04:00
cleanup
2018-02-15 12:12:00 -07:00
PATH = $PATH :/awips2/edex/bin/
exit
2021-06-02 15:37:13 -04:00