2019-06-14 18:52:10 +02:00
|
|
|
#! /bin/bash
|
|
|
|
###############################################################################
|
2019-06-15 02:26:56 +02:00
|
|
|
## writefreely update script ##
|
|
|
|
## ##
|
2023-03-05 08:23:26 +01:00
|
|
|
## WARNING: running this script will overwrite any modified assets or ##
|
2019-06-15 02:26:56 +02:00
|
|
|
## 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 18:52:10 +02:00
|
|
|
###############################################################################
|
|
|
|
#
|
2022-11-11 05:49:16 +01:00
|
|
|
# Copyright © 2019-2020 Musing Studio LLC.
|
2019-06-14 18:52:10 +02:00
|
|
|
#
|
2019-06-15 02:26:56 +02:00
|
|
|
# This file is part of WriteFreely.
|
2019-06-14 18:52:10 +02:00
|
|
|
#
|
2019-06-15 02:26:56 +02: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 18:52:10 +02: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-15 01:50:41 +02:00
|
|
|
echo "Checking for updates..."
|
2019-06-14 18:52:10 +02:00
|
|
|
|
2020-01-20 00:57:58 +01: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 18:52:10 +02:00
|
|
|
|
|
|
|
# check current version
|
|
|
|
|
2019-06-15 02:26:56 +02:00
|
|
|
bin_output=`./writefreely -v`
|
|
|
|
if [ -z "$bin_output" ]; then
|
2019-06-14 22:43:18 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-06-14 18:52:10 +02:00
|
|
|
|
2019-06-15 02:26:56 +02:00
|
|
|
current=${bin_output:12:5}
|
|
|
|
echo "Current version is v$current"
|
2019-06-14 18:52:10 +02:00
|
|
|
|
|
|
|
# grab latest version number
|
|
|
|
IFS='/'
|
|
|
|
read -ra parts <<< "$url"
|
|
|
|
|
|
|
|
latest=${parts[-2]}
|
|
|
|
echo "Latest release is $latest"
|
|
|
|
|
|
|
|
|
|
|
|
IFS='.'
|
2019-06-15 02:26:56 +02:00
|
|
|
read -ra cv <<< "$current"
|
2019-06-14 18:52:10 +02:00
|
|
|
read -ra lv <<< "${latest#v}"
|
|
|
|
|
|
|
|
IFS=' '
|
|
|
|
tempdir=$(mktemp -d)
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ${lv[0]} -gt ${cv[0]} ]]; then
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "New major version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 18:52:10 +02:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
elif [[ ${lv[0]} -eq ${cv[0]} ]] && [[ ${lv[1]} -gt ${cv[1]} ]]; then
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "New minor version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 18:52:10 +02:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
elif [[ ${lv[2]} -gt ${cv[2]} ]]; then
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "New patch version available."
|
|
|
|
echo "Downloading..."
|
2019-06-14 18:52:10 +02:00
|
|
|
`wget -P $tempdir -q --show-progress $url`
|
|
|
|
else
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "Up to date."
|
2019-06-14 18:52:10 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
filename=${parts[-1]}
|
|
|
|
|
|
|
|
# extract
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "Extracting files..."
|
2019-06-14 18:52:10 +02:00
|
|
|
tar -zxf $tempdir/$filename -C $tempdir
|
|
|
|
|
2020-01-20 00:57:58 +01: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 18:52:10 +02:00
|
|
|
# copy files
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "Copying files..."
|
2020-01-20 00:57:58 +01:00
|
|
|
cp -r $tempdir/writefreely/{pages,static,templates,writefreely} .
|
|
|
|
|
|
|
|
# migrate db
|
|
|
|
./writefreely -migrate
|
2019-06-14 18:52:10 +02:00
|
|
|
|
|
|
|
# restart service
|
2020-01-29 11:46:59 +01:00
|
|
|
echo "Starting writefreely systemd service..."
|
2020-01-20 00:57:58 +01:00
|
|
|
if `systemctl start writefreely`; then
|
2019-06-14 19:05:08 +02:00
|
|
|
echo "Success, version has been upgraded to $latest."
|
|
|
|
else
|
2019-06-15 01:50:41 +02:00
|
|
|
echo "Upgrade complete, but failed to restart service."
|
2019-06-14 19:05:08 +02:00
|
|
|
exit 1
|
|
|
|
fi
|