myshellconfig/bin/publishpvp

124 lines
4.7 KiB
Text
Raw Normal View History

#!/bin/bash
2020-10-22 00:58:35 +02:00
RESTART=true
CONFDIR="${HOME}/.local/$(basename $0)"
TIMESTAMP=$(date "+%x-%X")
set -- $(getopt -u -o ng: --long no-restart,gvapplid: -- "$@" )
2020-10-22 00:58:35 +02:00
while [ $# -gt 0 ];
do
case $1 in
-n|--no-restart)
RESTART=false
shift
continue
;;
-g|--gvapplid)
GVAPPLID=$2
shift; shift;
;;
2020-10-22 00:58:35 +02:00
--)
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)
2020-10-22 00:58:35 +02:00
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
2020-10-22 00:58:35 +02:00
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
2020-10-22 00:58:35 +02:00
app=jira
appuser=jira
;;
*)
echo "host ${DEST} not found -> exit"
exit
;;
esac
echo "Using configfile $file"
UNINSTALLDIR="\${HOME}/UNINSTALL/${TIMESTAMP}/"
2020-10-22 00:58:35 +02:00
if stat "${file}" >/dev/null 2>/dev/null ; then
echo "Stop $app on ${DEST}"
ssh ${DEST} systemctl stop ${app}.service
2020-11-10 16:16:09 +01:00
cat ${file}|sort -r |grep -v " *#"|while read cmd pkg version ; do
2020-10-22 00:58:35 +02:00
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"
2020-10-19 21:59:01 +02:00
else
2020-10-22 00:58:35 +02:00
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
2020-10-19 21:59:01 +02:00
EOF
2020-10-22 00:58:35 +02:00
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
2020-10-19 21:59:01 +02:00
fi
2020-10-22 00:58:35 +02:00
;;
*)
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
2020-10-22 00:58:35 +02:00
else
echo "Configfile ${file} not found"
fi
done