Last active
November 2, 2017 18:55
-
-
Save imolein/9909b477487d4288330802f3f6c4118b to your computer and use it in GitHub Desktop.
PleromaFE update script
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 | |
# Make changes here BEGIN | |
# url where you can download the newest pipeline zip file | |
URL="https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/develop/download?job=build" | |
# folder where postActiv/GNUsocial is installed | |
DESTDIR="/var/www/postActiv" | |
# owner of the postActiv/GNUsocial folder | |
DESTDIR_OWNER="www-data" | |
DESTDIR_GROUP="www-data" | |
# name of pleroma-fe index.html (e.g. you open pleroma-fe via example.com/pleroma.html it's pleroma.html) | |
PINDEX_NAME="pleroma.html" | |
# filepath to file with md5 of pipeline zip file from the last update | |
OLD_PFE_MD5_PATH="${DESTDIR}/pfeupdate.md5" | |
# files you don't want to be overwritten during the update, sperate them with space | |
EXCLUDE="config.json" | |
# END | |
TMP=$(mktemp -d) | |
[ ! -z ${1} ] && [ "${1}" == "-v" ] && QUIET=false || QUIET=true | |
function printer() { | |
if ${QUIET}; then | |
return | |
fi | |
echo "${@}" | |
} | |
trap 'printer "Cleanup and done..."; rm -r ${TMP}' 0 1 2 15 | |
printer "Looking for MD5 sum of previous downloaded artifact to compare with the new one..." | |
if [ -e ${OLD_PFE_MD5_PATH} ]; then | |
printer "Found one..." | |
OLD_PFE_MD5=$(< ${OLD_PFE_MD5_PATH}) | |
else | |
printer "MD5 sum of previous artifact don't exist, but we continue..." | |
OLD_PFE_MD5="" | |
fi | |
printer "Download new aritfact..." | |
wget -q -O ${TMP}/pleroma.zip ${URL} | |
if [ $? -ne 0 ] || [ ! -f ${TMP}/pleroma.zip ]; then | |
printer "Something went wrong, because can't find the zip file..." | |
exit 1 | |
elif ! file -ib ${TMP}/pleroma.zip | grep "application/zip" >/dev/null 2>&1; then | |
printer "Something went wrong, because it isn't a zip file..." | |
exit 1 | |
fi | |
NEW_PFE_MD5=$(md5sum ${TMP}/pleroma.zip | cut -d' ' -f1) | |
if [ "x${NEW_PFE_MD5}" == "x${OLD_PFE_MD5}" ]; then | |
printer "File isn't newer, so no update needed..." | |
exit 0 | |
fi | |
printer "Extract..." | |
unzip -q -d ${TMP} ${TMP}/pleroma.zip | |
printer "Move files..." | |
echo ${EXCLUDE} | tr ' ' '\n' > ${TMP}/excluded | |
rsync -aqP --exclude-from="${TMP}/excluded" ${TMP}/dist/static/* ${DESTDIR}/static/ | |
mv ${TMP}/dist/index.html ${DESTDIR}/${PINDEX_NAME} | |
printer "Apply rights..." | |
chown -R ${DESTDIR_OWNER}:${DESTDIR_GROUP} ${DESTDIR}/static/ | |
chown ${DESTDIR_OWNER}:${DESTDIR_GROUP} ${DESTDIR}/${PINDEX_NAME} | |
echo "${NEW_PFE_MD5}" > ${OLD_PFE_MD5_PATH} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Look for up to date versions of this script in https://git.pleroma.social/imo/update_pleroma-fe/tree/master and installation guide in https://git.pleroma.social/pleroma/pleroma-fe/wikis/update-script-for-pleroma-fe