From 0c44fe1c2eadc1441f71b036ad7dd8b5e6e7da61 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Fri, 14 Jun 2019 09:52:10 -0700 Subject: [PATCH 1/5] add update script this bash script will download a new version, if any, and exrtact it to a temporary location. Then copy the new files to the current directory and restart the systemd service. --- scripts/upgrade-server.sh | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 scripts/upgrade-server.sh diff --git a/scripts/upgrade-server.sh b/scripts/upgrade-server.sh new file mode 100755 index 0000000..5246d89 --- /dev/null +++ b/scripts/upgrade-server.sh @@ -0,0 +1,88 @@ +#! /bin/bash +############################################################################### +## 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. ## +############################################################################### +# +# Copyright © 2019 A Bunch Tell LLC. +# +# This file is part of WriteFreely. +# +# 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. +# + + +# 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 +echo "Checking for updates.." + +url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | grep 'browser_' | grep linux | cut -d\" -f4` + +# check current version + +current=`./writefreely -v` + +echo "Current version is v${current:(-5):5}" + +# grab latest version number +IFS='/' +read -ra parts <<< "$url" + +latest=${parts[-2]} +echo "Latest release is $latest" + + +IFS='.' +read -ra cv <<< "${current:(-5):5}" +read -ra lv <<< "${latest#v}" + +IFS=' ' +tempdir=$(mktemp -d) + + +if [[ ${lv[0]} -gt ${cv[0]} ]]; then + echo "New major version" + echo "Downloading.." + `wget -P $tempdir -q --show-progress $url` +elif [[ ${lv[0]} -eq ${cv[0]} ]] && [[ ${lv[1]} -gt ${cv[1]} ]]; then + echo "New minor version" + echo "Downloading.." + `wget -P $tempdir -q --show-progress $url` +elif [[ ${lv[2]} -gt ${cv[2]} ]]; then + echo "New patch version" + echo "Downloading.." + `wget -P $tempdir -q --show-progress $url` +else + echo "Nothing to change" + exit 0 +fi + +filename=${parts[-1]} + +# extract +echo "Extracing files.." +tar -zxf $tempdir/$filename -C $tempdir + +# copy files +echo "Copying files.." +cp -r $tempdir/{pages,static,templates,writefreely} . + +# restart service +echo "Restarting writefreely systemd service.." +`systemctl restart writefreely` +echo "Done, version has been upgraded to $latest." From f6ba1fc9c8a041380aae7bfab0fe937cbb54d769 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Fri, 14 Jun 2019 10:05:08 -0700 Subject: [PATCH 2/5] update script: error check restarting service basic error check with descriptive output in update_server.sh --- scripts/upgrade-server.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade-server.sh b/scripts/upgrade-server.sh index 5246d89..1bfab71 100755 --- a/scripts/upgrade-server.sh +++ b/scripts/upgrade-server.sh @@ -84,5 +84,9 @@ cp -r $tempdir/{pages,static,templates,writefreely} . # restart service echo "Restarting writefreely systemd service.." -`systemctl restart writefreely` -echo "Done, version has been upgraded to $latest." +if `systemctl restart writefreely`; then + echo "Success, version has been upgraded to $latest." +else + echo "Upgrade complete, but failed to restart service" + exit 1 +fi From 4c34b3473662d5b367b1c7f75cbe9e9f2e79835d Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 14 Jun 2019 16:43:18 -0400 Subject: [PATCH 3/5] Exit when no writefreely executable found (or `writefreely -v` otherwise doesn't output anything) Ref T555 --- scripts/upgrade-server.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/upgrade-server.sh b/scripts/upgrade-server.sh index 1bfab71..039fde8 100755 --- a/scripts/upgrade-server.sh +++ b/scripts/upgrade-server.sh @@ -36,6 +36,9 @@ url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | # check current version current=`./writefreely -v` +if [ -z "$current" ]; then + exit 1 +fi echo "Current version is v${current:(-5):5}" From 872ec4809b71833d38953d818473339fcec950cb Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 14 Jun 2019 19:50:41 -0400 Subject: [PATCH 4/5] Tweak status wording And fix a typo Ref T555 --- scripts/upgrade-server.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/upgrade-server.sh b/scripts/upgrade-server.sh index 039fde8..e02945d 100755 --- a/scripts/upgrade-server.sh +++ b/scripts/upgrade-server.sh @@ -29,7 +29,7 @@ if [[ `id -u` -ne 0 ]]; then fi # go ahead and check for the latest release on linux -echo "Checking for updates.." +echo "Checking for updates..." url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | grep 'browser_' | grep linux | cut -d\" -f4` @@ -59,37 +59,37 @@ tempdir=$(mktemp -d) if [[ ${lv[0]} -gt ${cv[0]} ]]; then - echo "New major version" - echo "Downloading.." + echo "New major version available." + echo "Downloading..." `wget -P $tempdir -q --show-progress $url` elif [[ ${lv[0]} -eq ${cv[0]} ]] && [[ ${lv[1]} -gt ${cv[1]} ]]; then - echo "New minor version" - echo "Downloading.." + echo "New minor version available." + echo "Downloading..." `wget -P $tempdir -q --show-progress $url` elif [[ ${lv[2]} -gt ${cv[2]} ]]; then - echo "New patch version" - echo "Downloading.." + echo "New patch version available." + echo "Downloading..." `wget -P $tempdir -q --show-progress $url` else - echo "Nothing to change" + echo "Up to date." exit 0 fi filename=${parts[-1]} # extract -echo "Extracing files.." +echo "Extracting files..." tar -zxf $tempdir/$filename -C $tempdir # copy files -echo "Copying files.." +echo "Copying files..." cp -r $tempdir/{pages,static,templates,writefreely} . # restart service -echo "Restarting writefreely systemd service.." +echo "Restarting writefreely systemd service..." if `systemctl restart writefreely`; then echo "Success, version has been upgraded to $latest." else - echo "Upgrade complete, but failed to restart service" + echo "Upgrade complete, but failed to restart service." exit 1 fi From 075f25b829dd0ad6599dac1026ac15c6375e534d Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Fri, 14 Jun 2019 17:26:56 -0700 Subject: [PATCH 5/5] fix: update script: non-standard version numbers store version output in new variable slice output indexed from beginning instead of end. allowing for custom build version numbers. also fix weird spacing from tabs being two spaces wide, sorry :) --- scripts/upgrade-server.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/upgrade-server.sh b/scripts/upgrade-server.sh index e02945d..c8e004a 100755 --- a/scripts/upgrade-server.sh +++ b/scripts/upgrade-server.sh @@ -1,23 +1,23 @@ #! /bin/bash ############################################################################### -## 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. ## +## 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. ## ############################################################################### # -# Copyright © 2019 A Bunch Tell LLC. +# Copyright © 2019 A Bunch Tell LLC. # -# This file is part of WriteFreely. +# This file is part of WriteFreely. # -# 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. +# 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. # @@ -35,12 +35,13 @@ url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | # check current version -current=`./writefreely -v` -if [ -z "$current" ]; then +bin_output=`./writefreely -v` +if [ -z "$bin_output" ]; then exit 1 fi -echo "Current version is v${current:(-5):5}" +current=${bin_output:12:5} +echo "Current version is v$current" # grab latest version number IFS='/' @@ -51,7 +52,7 @@ echo "Latest release is $latest" IFS='.' -read -ra cv <<< "${current:(-5):5}" +read -ra cv <<< "$current" read -ra lv <<< "${latest#v}" IFS=' '