myshellconfig/bin/publishpvp

123 lines
4.7 KiB
Bash
Executable file

#!/bin/bash
RESTART=true
CONFDIR="${HOME}/.local/$(basename $0)"
TIMESTAMP=$(date "+%x-%X")
set -- $(getopt -u -o ng: --long no-restart,gvapplid: -- "$@" )
while [ $# -gt 0 ];
do
case $1 in
-n|--no-restart)
RESTART=false
shift
continue
;;
-g|--gvapplid)
GVAPPLID=$2
shift; shift;
;;
--)
shift
DESTS=($@)
break
;;
*)
usage
esac
done
for DEST in ${DESTS[*]}
do
file="$(find ${CONFDIR%/}/ -name ${DEST})"
gvapplid=$(awk -v hostname="$(ssh ${DEST} hostname)" '$0 ~ hostname {print $1}' ${CONFDIR%/}/gvapplid)
case ${DEST} in
*cnf*|*conf*)
[ -z "${file-x}" ] && file="${CONFDIR%/}/confluence"
homedir=/var/atlassian/application-data/confluence
installdir=/opt/atlassian/confluence
libdir=${installdir%/}${installdir:+/}confluence/WEB-INF/lib
classesdir=${installdir%/}${installdir:+/}confluence/WEB-INF/classes
app=confluence
appuser=confluence
;;
*jra*|*jira*)
[ -z "${file-x}" ] && file="${CONFDIR%/}/jira"
homedir=/var/atlassian/application-data/jira
installdir=/opt/atlassian/jira
libdir=${installdir%/}${installdir:+/}atlassian-jira/WEB-INF/lib
classesdir=${installdir%/}${installdir:+/}atlassian-jira/WEB-INF/classes
app=jira
appuser=jira
;;
*)
echo "host ${DEST} not found -> exit"
exit
;;
esac
echo "Using configfile $file"
UNINSTALLDIR="\${HOME}/UNINSTALL/${TIMESTAMP}/"
if stat "${file}" >/dev/null 2>/dev/null ; then
echo "Stop $app on ${DEST}"
ssh ${DEST} systemctl stop ${app}.service
cat ${file}|sort -r |grep -v " *#"|while read cmd pkg version ; do
case $cmd in
install)
if [ -z "${version}" ]; then
dir=$( find ~/.m2 -type d -name "*${pkg}*"|grep -v '\$' )
loginfo "dir: $dir"
pkgdir=$(find ${dir} -maxdepth 1 -mindepth 1 -type d -exec basename '{}' \; |sort -n -t"." -k 1,1 -k 2,2 -k 3,3|tail -n1)
loginfo "pkgdir: $pkgdir"
loginfo "${dir}/${pkgdir}"
package=$(find ${dir}/${pkgdir} -name "*${pkg}*.jar")
loginfo "package: $package"
else
package=$(find ~/.m2 -name "*${pkg}-${version}.jar")
fi
if [ -n "${package-x}" ]; then
loginfo "$cmd $pkg $version"
logdebug "install $package"
scp ${package} ${DEST}:${libdir}
ssh ${DEST} chown $appuser:${appusergrp-root} "${libdir}/$(basename ${package})" </dev/null
ssh ${DEST} chmod ${fileperm-0644} "${libdir}/$(basename ${package})" </dev/null
else
echo "$pkg in version $version not found"
fi
;;
remove)
if [ -n "${pkg}" ]; then
if [ -n "${version}" ]; then
echo remove $pkg in version ${version} from ${DEST}
ssh -T ${DEST} /bin/bash <<EOF
mkdir -p "${UNINSTALLDIR}" </dev/null
[ \$(find ${libdir} -name "*${pkg}-${version}.jar" </dev/null |wc -l) -gt 0 ] && \
mv \$(find ${libdir} -name "*${pkg}-${version}.jar") "${UNINSTALLDIR}". </dev/null
EOF
else
echo remove $pkg in all versions from ${DEST}
ssh -T ${DEST} /bin/bash <<EOF
mkdir -p "${UNINSTALLDIR}" </dev/null
[ \$(find ${libdir} -name "*${pkg}-*.jar" </dev/null |wc -l) -gt 0 ] && \
mv \$(find ${libdir} -name "*${pkg}-*.jar") "${UNINSTALLDIR}"/. </dev/null
EOF
fi
else
echo pkg not set ignore line »${cmd} ${pkg} ${version}« from configfile
fi
;;
*)
echo "line not correct: $cmd $pkg $version"
;;
esac
unset cmd pkg version
done
$RESTART && echo "Start ${app} on ${DEST}" || echo "Do not restart ${app} on ${DEST}"
$RESTART && ssh ${DEST} systemctl start ${app}.service </dev/null
else
echo "Configfile ${file} not found"
fi
done