add getopts loop for multiple hosts
This commit is contained in:
parent
a1315411e6
commit
4755049a76
1 changed files with 105 additions and 72 deletions
|
@ -1,7 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
file="$(find ${HOME}/.local/$(basename $0)/ -name $1)"
|
||||
case $1 in
|
||||
RESTART=true
|
||||
|
||||
set -- $(getopt -u -o n --long no-restart -- "$@" )
|
||||
|
||||
while [ $# -gt 0 ];
|
||||
do
|
||||
|
||||
case $1 in
|
||||
-n|--no-restart)
|
||||
RESTART=false
|
||||
shift
|
||||
continue
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
DESTS=($@)
|
||||
break
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
esac
|
||||
done
|
||||
|
||||
for DEST in ${DESTS[*]}
|
||||
do
|
||||
file="$(find ${HOME}/.local/$(basename $0)/ -name ${DEST})"
|
||||
case ${DEST} in
|
||||
*cnf*|*conf*)
|
||||
[ -z "${file-x}" ] && file="${HOME}/.local/$(basename $0)/confluence"
|
||||
libdir=/opt/atlassian/confluence/confluence/WEB-INF/lib
|
||||
|
@ -15,31 +40,38 @@ case $1 in
|
|||
appuser=jira
|
||||
;;
|
||||
*)
|
||||
echo "host ${1} not found -> exit"
|
||||
echo "host ${DEST} not found -> exit"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
echo "Using configfile $file"
|
||||
runtime=$(date "+%x-%X")
|
||||
UNINSTALLDIR="${HOME}/UNINSTALL/${runtime}/"
|
||||
echo "Using configfile $file"
|
||||
runtime=$(date "+%x-%X")
|
||||
UNINSTALLDIR="${HOME}/UNINSTALL/${runtime}/"
|
||||
|
||||
if stat "${file}" >/dev/null 2>/dev/null ; then
|
||||
echo "Stop $app on ${1}"
|
||||
ssh ${1} systemctl stop ${app}.service
|
||||
if stat "${file}" >/dev/null 2>/dev/null ; then
|
||||
echo "Stop $app on ${DEST}"
|
||||
ssh ${DEST} systemctl stop ${app}.service
|
||||
cat ${file}|sort -r |while read cmd pkg version ; do
|
||||
case $cmd in
|
||||
install)
|
||||
echo install $cmd $pkg $version
|
||||
if [ -z "${version}" ]; then
|
||||
package=$(find ~/.m2 -name "*${pkg}*.jar"|sort -t"." -k 1,1 -k 2,2 -k 3,3|tail -n1)
|
||||
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
|
||||
scp ${package} ${1}:${libdir}
|
||||
ssh ${1} chown $appuser:${appusergrp-root} "${libdir}/$(basename ${package})" </dev/null
|
||||
ssh ${1} chmod ${fileperm-0755} "${libdir}/$(basename ${package})" </dev/null
|
||||
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
|
||||
|
@ -47,15 +79,15 @@ if stat "${file}" >/dev/null 2>/dev/null ; then
|
|||
remove)
|
||||
if [ -n "${pkg}" ]; then
|
||||
if [ -n "${version}" ]; then
|
||||
echo remove $pkg in version ${version} from ${1}
|
||||
ssh -T ${1} /bin/bash <<EOF
|
||||
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 ${1}
|
||||
ssh -T ${1} /bin/bash <<EOF
|
||||
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
|
||||
|
@ -71,8 +103,9 @@ EOF
|
|||
esac
|
||||
unset cmd pkg version
|
||||
done
|
||||
echo "Start $app on ${1}"
|
||||
ssh ${1} systemctl start ${app}.service </dev/null
|
||||
else
|
||||
echo "Start $app on ${DEST}"
|
||||
ssh ${DEST} systemctl start ${app}.service </dev/null
|
||||
else
|
||||
echo "Configfile ${file} not found"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue