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.

170 lines
5.9 KiB

4 years ago
  1. #!/bin/sh -e
  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. validate_hugo () {
  21. # Exit with error if hugo is not installed
  22. if ! hash hugo 2>/dev/null ; then
  23. echo "Error: After Dark requires Hugo version 0.51 or greater" >&2; exit 1
  24. fi
  25. # Exit with error if not minimum required hugo version
  26. re="v(0\d*\.([5-9][1-9]|[6-9])|[1-9]).*"
  27. if ! hugo version | grep -qE "$re" ; then
  28. echo "Error: After Dark requires Hugo version 0.51 or greater" >&2; exit 1
  29. fi
  30. }
  31. create_site_dir () {
  32. SITE_DIR="flying-toasters"
  33. if [ "$1" != "" ] ; then
  34. SITE_DIR="$1"
  35. fi
  36. SITE_DIR_ABS="$PWD/$SITE_DIR"
  37. mkdir -p "$SITE_DIR"
  38. }
  39. create_site () {
  40. echo "Creating a new Hugo site ..."
  41. hugo new site "$SITE_DIR" 1>/dev/null
  42. cd "$SITE_DIR" || exit 1
  43. }
  44. download_theme () {
  45. echo "Downloading the latest version of After Dark ..."
  46. LATEST_META=$(wget -qO - https://registry.npmjs.org/after-dark/latest)
  47. vers=$(echo "$LATEST_META" | grep -oE "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  48. mkdir -p themes/after-dark
  49. wget -qO - https://registry.npmjs.org/after-dark/-/after-dark-"$vers".tgz | tar --strip-components=1 -xz -C themes/after-dark
  50. echo "Version $vers downloaded to $SITE_DIR/themes/after-dark"
  51. }
  52. download_module () {
  53. [ -z "$1" ] && { echo "Error: Attempt to download undefined module" >&2; exit 1; }
  54. echo "Downloading $1 module for After Dark ..."
  55. meta=$(wget -qO - https://registry.npmjs.org/"$1"/latest)
  56. vers=$(echo "$meta" | grep -oE "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ')
  57. mkdir -p themes/"$1"
  58. wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$vers".tgz | tar --strip-components=1 -xz -C themes/"$1"
  59. echo "Version $vers downloaded to $SITE_DIR/themes/$1"
  60. }
  61. configure_theme () {
  62. echo "Configuring basic After Dark theme settings ..."
  63. tee "config.toml" > /dev/null <<TOML
  64. baseurl = "https://domain.example" # Controls base URL sitewide
  65. languageCode = "en-US" # Controls site language
  66. title = "After Dark" # Homepage title and page title suffix
  67. paginate = 11 # Number of posts to show before paginating
  68. copyright = "Copyright &copy; Copyright Owner. Licensed under <a target=\"_blank\" rel=\"external noopener license\" href=\"https://creativecommons.org/licenses/by-nd/4.0/\">CC-BY-ND-4.0</a>." # Optional, remove to suppress copyright notices
  69. # Controls default theme and theme components
  70. theme = [
  71. "fractal-forest", # OBSD
  72. "after-dark" # AGPL-3.0-or-later
  73. ]
  74. disableLiveReload = false # Optional, set true to disable live reload
  75. enableRobotsTXT = true # Suggested, enable robots.txt file
  76. sectionPagesMenu = "main" # Enable menu system for lazy bloggers
  77. [markup.goldmark.renderer]
  78. unsafe = true # Optional, allows HTML inside your CommonMark content
  79. [markup.tableOfContents]
  80. startLevel = 1 # Suggested, draws TOC using all heading levels
  81. endLevel = 6 # Suggested, draws TOC using all heading levels
  82. [markup.highlight]
  83. noClasses = false # Suggested, used for custom syntax highlighting
  84. [params]
  85. description = "" # Suggested, controls default description meta
  86. author = "" # Optional, controls author name display on posts
  87. hide_author = false # Optional, set true to hide author name on posts
  88. disable_csp = false # Optional, set true to disable content security policy
  89. images = [
  90. "https://source.unsplash.com/collection/983219/2000x1322"
  91. ] # Suggested, controls default Open Graph images
  92. [params.layout.menu.main]
  93. hidden = true # Optional, set false or remove to show section menu
  94. [params.layout.footer]
  95. hidden = false # Optional, set true to hide footer
  96. [params.modules.fractal_forest]
  97. enabled = true # Optional, set false to disable module
  98. decoders = ["bpgdec8a"] # Optional, 8-bit javascript decoder with animation
  99. TOML
  100. }
  101. update_archetypes () {
  102. echo "Updating the default content archetype ..."
  103. rm -f archetypes/default.md
  104. cp themes/after-dark/archetypes/default.md archetypes
  105. }
  106. create_welcome_post () {
  107. echo "Creating welcome post ..."
  108. hugo new post/welcome.md 1>/dev/null
  109. }
  110. serve_site () {
  111. echo "Starting site server ..."
  112. hugo serve --buildDrafts --navigateToChanged --port 1313 1>/dev/null &
  113. }
  114. generate_help_docs () {
  115. echo "Generating help documentation ..."
  116. THEME_PATH=themes/after-dark
  117. meta_path="$THEME_PATH"/data/npm
  118. mkdir -p "$meta_path" && echo "$LATEST_META" | tr '\r\n' ' ' > "$meta_path"/latest.json
  119. cd "$THEME_PATH"/docs && mkdir themes && ln -s ../.. "$THEME_PATH"
  120. hugo new validate.md --kind validate 1>/dev/null
  121. }
  122. serve_help () {
  123. echo "Starting help server ..."
  124. hugo serve --disableLiveReload --port 1414 1>/dev/null &
  125. }
  126. echo "Welcome to the After Dark quick installer. Press CTRL-C at any time to abort."
  127. validate_hugo
  128. create_site_dir "$1"
  129. create_site
  130. download_theme
  131. update_archetypes
  132. download_module "fractal-forest"
  133. configure_theme
  134. create_welcome_post
  135. serve_site
  136. generate_help_docs
  137. serve_help
  138. YELLOW='\033[0;33m'
  139. NC='\033[0m'
  140. printf "${YELLOW}Installation successful!${NC}\n"
  141. echo "Site created in $SITE_DIR_ABS"
  142. echo "Site server started at http://localhost:1313/"
  143. echo "To stop it run \"kill \$(ps aux | awk '/[h]ugo.*1313/ {print \$2}')\"."
  144. echo "Help server started at http://localhost:1414/"
  145. echo "To stop and restart it run \"./themes/after-dark/bin/help\"."
  146. echo "Thank you for choosing After Dark."