Created
June 3, 2019 08:22
-
-
Save oioiben/228ba6f86afed3d40d15896bf848636f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function notify(){ | |
printf "$@\n" | |
exit 1 | |
} | |
[ "$UID" -eq 0 ] || notify "Must run as root!" | |
function prep(){ | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get update &>/dev/null | |
dpkg --configure -a | |
echo > "$logFile" | |
} | |
function checkIfPkgInstalled(){ | |
dpkg -l | grep "$1" >/dev/null || return 1 | |
} | |
function installpkg(){ | |
printf "Installing $1 -- " | |
if [ -z "$2" ]; then | |
apt-get -yq install "$1" >/dev/null | |
else | |
apt-get -yq install "$1=$2" >/dev/null | |
fi | |
if [ "$?" -ne 0 ];then | |
printf "**Failed installation**\n" | |
return 500 | |
else | |
printf "Installed.\n" | |
fi | |
} | |
function check_java(){ | |
checkIfPkgInstalled oracle-java8-installer | |
if [ "$?" -eq 0 ]; then | |
printf "Installing Java..." | |
installpkg fk-ops-pg-java | |
# need this to update latest java versions | |
apt-get update; installpkg oracle-java8-installer | |
fi | |
} | |
updateList="/tmp/updatelist" | |
logFile="/tmp/${HOSTNAME}-update.log" | |
createPkgList="" | |
wget -q http://ops-jbuild-2.nm.payzippy.com/updatelist -O "$updateList" || notify "not able to get update list\n" | |
prep | |
while read -r line; do | |
PKGNAME="$(echo $line | awk -F= '{print $1}')" | |
VERSION="$(echo $line | awk -F= '{print $2}')" | |
checkIfPkgInstalled $PKGNAME | |
[ "$?" -eq 1 ] || installpkg $PKGNAME $VERSION &>>"$logFile" | |
done < "$updateList" | |
check_java >> "$logFile" | |
cat "$logFile" | |
rsync -rq "$logFile" pzy-storage.nm.payzippy.com::fk-pg-ezpatch/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment