2019-06-14 16:52:10 +00:00
|
|
|
#! /bin/bash
|
|
|
|
###############################################################################
|
2019-06-15 00:26:56 +00:00
|
|
|
## writefreely update script ##
|
|
|
|
## ##
|
|
|
|
## WARNING: running this script will overwrite any modifed assets or ##
|
|
|
|
## template files. If you have any custom changes to these files you ##
|
|
|
|
## should back them up FIRST. ##
|
|
|
|
## ##
|
|
|
|
## This must be run from the web application root directory ##
|
|
|
|
## i.e. /var/www/writefreely, and operates under the assumption that you##
|
|
|
|
## have not installed the binary `writefreely` in another location. ##
|
2019-06-14 16:52:10 +00:00
|
|
|
###############################################################################
|
|
|
|
#
|
2022-11-11 04:49:16 +00:00
|
|
|
# Copyright © 2019-2020 Musing Studio LLC.
|
2019-06-14 16:52:10 +00:00
|
|
|
#
|
2019-06-15 00:26:56 +00:00
|
|
|
# This file is part of WriteFreely.
|
2019-06-14 16:52:10 +00:00
|
|
|
#
|
2019-06-15 00:26:56 +00:00
|
|
|
# WriteFreely is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License, included
|
|
|
|
# in the LICENSE file in this source code package.
|
2019-06-14 16:52:10 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
# only execute as root, or use sudo
|
|
|
|
|
|
|
|
if [[ `id -u` -ne 0 ]]; then
|
|
|
|
echo "You must login as root, or execute this script with sudo"
|
|
|
|
exit 10
|
|
|
|
fi
|
|
|
|
|
|
|
|
# go ahead and check for the latest release on linux
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "Checking for updates..."
|
2019-06-14 16:52:10 +00:00
|
|
|
|
2020-01-19 23:57:58 +00:00
|
|
|
url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | grep 'browser_' | grep 'linux' | grep 'amd64' | cut -d\" -f4`
|
2019-06-14 16:52:10 +00:00
|
|
|
|
|
|
|
# check current version
|
|
|
|
|
2019-06-15 00:26:56 +00:00
|
|
|
bin_output=`./writefreely -v`
|
|
|
|
if [ -z "$bin_output" ]; then
|
2019-06-14 20:43:18 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-06-14 16:52:10 +00:00
|
|
|
|
2019-06-15 00:26:56 +00:00
|
|
|
current=${bin_output:12:5}
|
|
|
|
echo "Current version is v$current"
|
2019-06-14 16:52:10 +00:00
|
|
|
|
|
|
|
# grab latest version number
|
|
|
|
IFS='/'
|
|
|
|
read -ra parts <<< "$url"
|
|
|
|
|
|
|
|
latest=${parts[-2]}
|
|
|
|
echo "Latest release is $latest"
|
|
|
|
|
|
|
|
|
|
|
|
IFS='.'
|
2019-06-15 00:26:56 +00:00
|
|
|
read -ra cv <<< "$current"
|
2019-06-14 16:52:10 +00:00
|
|
|
read -ra lv <<< "${latest#v}"
|
|
|
|
|
|
|
|
IFS=' '
|
|
|
|
tempdir=$(mktemp -d)
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ${lv[0]} -gt ${cv[0]} ]]; then
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "New major version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 16:52:10 +00:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
elif [[ ${lv[0]} -eq ${cv[0]} ]] && [[ ${lv[1]} -gt ${cv[1]} ]]; then
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "New minor version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 16:52:10 +00:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
elif [[ ${lv[2]} -gt ${cv[2]} ]]; then
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "New patch version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 16:52:10 +00:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
else
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "Up to date."
|
2019-06-14 16:52:10 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
filename=${parts[-1]}
|
|
|
|
|
|
|
|
# extract
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "Extracting files..."
|
2019-06-14 16:52:10 +00:00
|
|
|
tar -zxf $tempdir/$filename -C $tempdir
|
|
|
|
|
2020-01-19 23:57:58 +00:00
|
|
|
# stop service
|
|
|
|
echo "Stopping writefreely systemd service..."
|
|
|
|
if `systemctl start writefreely`; then
|
|
|
|
echo "Success, service stopped."
|
|
|
|
else
|
|
|
|
echo "Upgrade failed to stop the systemd service, exiting early."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-06-14 16:52:10 +00:00
|
|
|
# copy files
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "Copying files..."
|
2020-01-19 23:57:58 +00:00
|
|
|
cp -r $tempdir/writefreely/{pages,static,templates,writefreely} .
|
|
|
|
|
|
|
|
# migrate db
|
|
|
|
./writefreely -migrate
|
2019-06-14 16:52:10 +00:00
|
|
|
|
|
|
|
# restart service
|
2020-01-29 10:46:59 +00:00
|
|
|
echo "Starting writefreely systemd service..."
|
2020-01-19 23:57:58 +00:00
|
|
|
if `systemctl start writefreely`; then
|
2019-06-14 17:05:08 +00:00
|
|
|
echo "Success, version has been upgraded to $latest."
|
|
|
|
else
|
2019-06-14 23:50:41 +00:00
|
|
|
echo "Upgrade complete, but failed to restart service."
|
2019-06-14 17:05:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|