This commit is contained in:
Aleritty 2016-09-02 21:45:08 +00:00 committed by GitHub
commit 0ab3235a0e

View file

@ -67,6 +67,10 @@ REDHAT_INSTALL="yum -y install"
DEBIAN_INSTALL="dpkg -i" DEBIAN_INSTALL="dpkg -i"
DISTRO_INSTALL="" DISTRO_INSTALL=""
# Don't change or override or you may break the autoupdates
VERSION=0.04
SCRIPT_REPO_URL="https://raw.githubusercontent.com/aleritty/plexupdate/master/plexupdate.sh"
# Sanity, make sure wget is in our path... # Sanity, make sure wget is in our path...
if ! hash wget 2>/dev/null; then if ! hash wget 2>/dev/null; then
echo "ERROR: This script requires wget in the path. It could also signify that you don't have the tool installed." >&2 echo "ERROR: This script requires wget in the path. It could also signify that you don't have the tool installed." >&2
@ -218,6 +222,11 @@ done
if [ "${IGNOREAUTOUPDATE}" = "yes" ]; then if [ "${IGNOREAUTOUPDATE}" = "yes" ]; then
AUTOUPDATE=no AUTOUPDATE=no
gitversion=$(wget $SCRIPT_REPO_URL -O - 2>/dev/null | grep "^VERSION=")
echo
if [[ ${gitversion:8} > $VERSION ]];then
echo "INFO: The new version "${gitversion:8}" is available but you asked to skip the update"
fi
fi fi
if [ "${KEEP}" = "yes" ]; then if [ "${KEEP}" = "yes" ]; then
@ -247,40 +256,54 @@ elif [ "${QUIET}" = "yes" ]; then
fi fi
if [ "${AUTOUPDATE}" = "yes" ]; then if [ "${AUTOUPDATE}" = "yes" ]; then
if ! hash git 2>/dev/null; then gitversion=$(wget $SCRIPT_REPO_URL -O - 2>/dev/null | grep "^VERSION=")
echo "ERROR: You need to have git installed for this to work" >&2 echo
cronexit 1 if [[ ${gitversion:8} > $VERSION ]];then
fi echo "The new version "${gitversion:8}" is available"
pushd "$(dirname "$0")" >/dev/null if $(wget $SCRIPT_REPO_URL -O "/tmp/plexupdatescripttemp" 2>/dev/null);then
if [ ! -d .git ]; then # Write the user modified values to the new file (but please use only configuration file)
echo "ERROR: This is not a git repository, auto update only works if you've done a git clone" >&2 sed -i '-s/EMAIL=/EMAIL='$EMAIL'/' "/tmp/plexupdatescripttemp"
cronexit 1 sed -i '-s/PASS=/PASS='$PASS'/' "/tmp/plexupdatescripttemp"
fi sed -i '-s^DOWNLOADDIR="."^DOWNLOADDIR='$DOWNLOADDIR'^' "/tmp/plexupdatescripttemp"
git status | grep "git commit -a" >/dev/null 2>/dev/null sed -i '-s^PLEXSERVER=^PLEXSERVER='$PLEXSERVER'^' "/tmp/plexupdatescripttemp"
if [ $? -eq 0 ]; then sed -i '-s/FORCE=no/FORCE='$FORCE'/' "/tmp/plexupdatescripttemp"
echo "ERROR: You have made changes to the script, cannot auto update" >&2 sed -i '-s/FORCEALL=no/FORCEALL='$FORCEALL'/' "/tmp/plexupdatescripttemp"
cronexit 1 sed -i '-s/PUBLIC=no/PUBLIC='$PUBLIC'/' "/tmp/plexupdatescripttemp"
fi sed -i '-s/AUTOINSTALL=no/AUTOINSTALL='$AUTOINSTALL'/' "/tmp/plexupdatescripttemp"
echo -n "Auto updating..." sed -i '-s/AUTODELETE=no/AUTODELETE='$AUTODELETE'/' "/tmp/plexupdatescripttemp"
git pull >/dev/null sed -i '-s/AUTOUPDATE=no/AUTOUPDATE='$AUTOUPDATE'/' "/tmp/plexupdatescripttemp"
if [ $? -ne 0 ]; then sed -i '-s/AUTOSTART=no/AUTOSTART='$AUTOSTART'/' "/tmp/plexupdatescripttemp"
echo 'ERROR: Unable to update git, try running "git pull" manually to see what is wrong' >&2 sed -i '-s/CRON=no/CRON='$CRON'/' "/tmp/plexupdatescripttemp"
cronexit 1 sed -i '-s/QUIET=no/QUIET='$QUIET'/' "/tmp/plexupdatescripttemp"
fi sed -i '-s/ARCH=$(uname -m)/ARCH='$ARCH'/' "/tmp/plexupdatescripttemp"
echo "OK" sed -i '-s/IGNOREAUTOUPDATE=no/IGNOREAUTOUPDATE='$IGNOREAUTOUPDATE'/' "/tmp/plexupdatescripttemp"
popd >/dev/null sed -i '-s/REDHAT_INSTALL="yum -y install"/REDHAT_INSTALL='$REDHAT_INSTALL'/' "/tmp/plexupdatescripttemp"
sed -i '-s/DEBIAN_INSTALL="dpkg -i"/DEBIAN_INSTALL='$DEBIAN_INSTALL'/' "/tmp/plexupdatescripttemp"
sed -i '-s/DISTRO_INSTALL=""/DISTRO_INSTALL='$DISTRO_INSTALL'/' "/tmp/plexupdatescripttemp"
cp "/tmp/plexupdatescripttemp" "$0"
if ! type "$0" 2>/dev/null >/dev/null ; then chmod +x "$0"
if [ -f "$0" ]; then echo "Script updated we need to relaunch it to apply the new version"
/bin/bash "$0" -U ${ALLARGS[@]} if ! type "$0" 2>/dev/null >/dev/null ; then
else if [ -f "$0" ]; then
echo "ERROR: Unable to relaunch, couldn't find $0" >&2 /bin/bash "$0" -U ${ALLARGS[@]}
cronexit 1 else
fi echo "ERROR: Unable to relaunch, couldn't find $0" >&2
else cronexit 1
"$0" -U ${ALLARGS[@]} fi
fi else
cronexit $? "$0" -U ${ALLARGS[@]}
fi
else
echo
echo "ERROR: Unable to download script $SCRIPT_REPO_URL"
echo
fi
else
echo "No update found, you have the latest version"
fi
echo
cronexit $?
fi fi
# Sanity check # Sanity check