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.

66 lines
2.5 KiB

4 years ago
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2019 Josh Habdas <jhabdas@protonmail.com>
  4. #
  5. # This file is part of After Dark.
  6. #
  7. # After Dark is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # After Dark is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. stop_help_server () {
  21. echo "Stopping help server if running ..."
  22. kill "$(ps aux | awk '/[h]ugo.*1414/ {print $2}')" 2>/dev/null || true
  23. }
  24. generate_help_docs () {
  25. stop_help_server
  26. echo "Generating help documentation ..."
  27. THEME_PATH=themes/after-dark
  28. meta_path="$THEME_PATH"/data/npm
  29. mkdir -p "$meta_path" && echo "$LATEST_META" | tr '\r\n' ' ' > "$meta_path"/latest.json
  30. cd "$THEME_PATH"/docs && mkdir themes && ln -s ../.. "$THEME_PATH"
  31. hugo new validate.md --kind validate 1>/dev/null
  32. }
  33. update_module () {
  34. meta_file=themes/"$1"/data/npm/latest.json
  35. if [ -f "$meta_file" ] ; then
  36. current_vers=$(sed -n 's/.*"version":"\([^"]*\).*/\1/p' < "$meta_file")
  37. else
  38. echo "Cannot detect version. Upgrade $1 anyway (y/n)? \c"
  39. read -r answer
  40. [ "$answer" = "${answer#[Yy]}" ] && exit 1
  41. fi
  42. LATEST_META=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
  43. latest_vers=$(echo "$LATEST_META" | grep -oE "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  44. if [ "$current_vers" ] ; then
  45. if [ "$current_vers" = "$latest_vers" ] ; then
  46. echo "Did not upgrade $1. Already using latest version." >&1; exit 0
  47. else
  48. echo "Upgrading $1 from $current_vers to $latest_vers ..."
  49. fi
  50. else
  51. echo "Upgrading $1 from unknown version to $latest_vers ..."
  52. fi
  53. rm -rf themes/"$1"/* # maintains dotfiles, e.g. git and env
  54. wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$latest_vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
  55. echo "Version $latest_vers downloaded to themes/$1"
  56. [ "$1" = "after-dark" ] && generate_help_docs
  57. echo "Upgrade complete! Please see CHANGELOG.md for changes."
  58. }
  59. set -e
  60. update_module "after-dark"