A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

109 lines
2.8 KiB

  1. #! /bin/bash
  2. ###############################################################################
  3. ## writefreely update script ##
  4. ## ##
  5. ## WARNING: running this script will overwrite any modifed assets or ##
  6. ## template files. If you have any custom changes to these files you ##
  7. ## should back them up FIRST. ##
  8. ## ##
  9. ## This must be run from the web application root directory ##
  10. ## i.e. /var/www/writefreely, and operates under the assumption that you##
  11. ## have not installed the binary `writefreely` in another location. ##
  12. ###############################################################################
  13. #
  14. # Copyright © 2019-2020 A Bunch Tell LLC.
  15. #
  16. # This file is part of WriteFreely.
  17. #
  18. # WriteFreely is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License, included
  20. # in the LICENSE file in this source code package.
  21. #
  22. # only execute as root, or use sudo
  23. if [[ `id -u` -ne 0 ]]; then
  24. echo "You must login as root, or execute this script with sudo"
  25. exit 10
  26. fi
  27. # go ahead and check for the latest release on linux
  28. echo "Checking for updates..."
  29. url=`curl -s https://api.github.com/repos/writeas/writefreely/releases/latest | grep 'browser_' | grep 'linux' | grep 'amd64' | cut -d\" -f4`
  30. # check current version
  31. bin_output=`./writefreely -v`
  32. if [ -z "$bin_output" ]; then
  33. exit 1
  34. fi
  35. current=${bin_output:12:5}
  36. echo "Current version is v$current"
  37. # grab latest version number
  38. IFS='/'
  39. read -ra parts <<< "$url"
  40. latest=${parts[-2]}
  41. echo "Latest release is $latest"
  42. IFS='.'
  43. read -ra cv <<< "$current"
  44. read -ra lv <<< "${latest#v}"
  45. IFS=' '
  46. tempdir=$(mktemp -d)
  47. if [[ ${lv[0]} -gt ${cv[0]} ]]; then
  48. echo "New major version available."
  49. echo "Downloading..."
  50. `wget -P $tempdir -q --show-progress $url`
  51. elif [[ ${lv[0]} -eq ${cv[0]} ]] && [[ ${lv[1]} -gt ${cv[1]} ]]; then
  52. echo "New minor version available."
  53. echo "Downloading..."
  54. `wget -P $tempdir -q --show-progress $url`
  55. elif [[ ${lv[2]} -gt ${cv[2]} ]]; then
  56. echo "New patch version available."
  57. echo "Downloading..."
  58. `wget -P $tempdir -q --show-progress $url`
  59. else
  60. echo "Up to date."
  61. exit 0
  62. fi
  63. filename=${parts[-1]}
  64. # extract
  65. echo "Extracting files..."
  66. tar -zxf $tempdir/$filename -C $tempdir
  67. # stop service
  68. echo "Stopping writefreely systemd service..."
  69. if `systemctl start writefreely`; then
  70. echo "Success, service stopped."
  71. else
  72. echo "Upgrade failed to stop the systemd service, exiting early."
  73. exit 1
  74. fi
  75. # copy files
  76. echo "Copying files..."
  77. cp -r $tempdir/writefreely/{pages,static,templates,writefreely} .
  78. # migrate db
  79. ./writefreely -migrate
  80. # restart service
  81. echo "Starting writefreely systemd service..."
  82. if `systemctl start writefreely`; then
  83. echo "Success, version has been upgraded to $latest."
  84. else
  85. echo "Upgrade complete, but failed to restart service."
  86. exit 1
  87. fi