-
Notifications
You must be signed in to change notification settings - Fork 21
Fixed bugs and refactor of main file. #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9e548b8
f5b60e6
4cb7559
11e54e9
123bd95
ba353d2
33eb5da
b47f0f9
08d7f7c
2c1f008
e79cba9
937dd01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,8 @@ | ||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script | ||||||||||||||||||||||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ###################################### | ||||||||||||||||||||||
| # ARISE | ||||||||||||||||||||||
| # https://github.com/spectrasecure/arise | ||||||||||||||||||||||
|
|
@@ -10,14 +14,28 @@ arise_version="1.1.0" | |||||||||||||||||||||
| # Don't edit below this line unless you know what you're doing | ||||||||||||||||||||||
| ############################################################## | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| cd "$(dirname $0)" | ||||||||||||||||||||||
| cd "$SCRIPT_DIR" | ||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set the default as an option so that a user can change the SCRIPT_DIR if they want to above; otherwise they leave it unset and it uses the default.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's nice for the moment (and the forseable future?) that arise is small enough that it comes with the website that it builds, kind of like the way the gnu autotools are "installed" in the project they compile (but without the complexity of gnu But if you insist, I'll do as you say. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
HerissonMignion marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Set the site config directories. Don't touch this-- changing the config location is not supported at this time | ||||||||||||||||||||||
| config="arise-out/config" | ||||||||||||||||||||||
| source arise-source/config/arise.conf | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Check if we're running a current version of bash before potentially causing code that won't run properly on ancient bash versions | ||||||||||||||||||||||
| [ "$BASH_VERSINFO" -lt 5 ] && echo -e 'ERROR: Arise requires Bash version 5 or greater to run. Please install a newer version of Bash or ensure that you are using the newest version installed on your computer.\n\nYour current version of Bash is: '"$BASH_VERSINFO"'\n\nYou can verify the current running version of Bash by running the following command: echo "$BASH_VERSINFO"' && exit 1 | ||||||||||||||||||||||
| if [ "$BASH_VERSINFO" -lt 5 ]; then | ||||||||||||||||||||||
| cat <<ERROR >&2 | ||||||||||||||||||||||
| ERROR: Arise requires Bash version 5 or greater to run. Please install | ||||||||||||||||||||||
| a newer version of Bash or ensure that you are using the newest | ||||||||||||||||||||||
| version installed on your computer. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Your current version of Bash is: $BASH_VERSINFO | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| You can verify the current running version of Bash by running the | ||||||||||||||||||||||
| following command: echo "\$BASH_VERSINFO" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ERROR | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Makes sure that our paths have or don't have a '/' as expected regardless of user input. | ||||||||||||||||||||||
| ## Favicon should have a '/' at the start of the path. | ||||||||||||||||||||||
|
|
@@ -26,134 +44,187 @@ source arise-source/config/arise.conf | |||||||||||||||||||||
| [[ ${base_url: -1} == '/' ]] && base_url=${base_url::-1} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Source functions | ||||||||||||||||||||||
| for FILE in lib/functions/inline/* ; do [[ $FILE == *.sh ]] && source $FILE ; done | ||||||||||||||||||||||
| for FILE in lib/functions/subshell/* ; do [[ $FILE == *.sh ]] && source $FILE ; done | ||||||||||||||||||||||
| for FILE in lib/functions/{subshell,inline}/*.sh; do | ||||||||||||||||||||||
| source "$FILE" | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Display our pretty logo no matter what when the program is run :) | ||||||||||||||||||||||
| arise_logo | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Set default build settings | ||||||||||||||||||||||
| force_overwrite=false | ||||||||||||||||||||||
| keep_source=false | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Read our arguments and set the build mode for processing. Display help if an invalid option is made. | ||||||||||||||||||||||
| if [[ $@ == "build" ]]; then | ||||||||||||||||||||||
| arise_build="full" | ||||||||||||||||||||||
| echo "Starting site deploy. Building full site." | ||||||||||||||||||||||
| elif [[ $@ == "build -k" ]]; then | ||||||||||||||||||||||
| arise_build="full" | ||||||||||||||||||||||
| keep_source=true | ||||||||||||||||||||||
| echo "Starting site deploy. Building full site. Source .md files will be retained in the final output." | ||||||||||||||||||||||
| elif [[ $@ == "build -f" ]]; then | ||||||||||||||||||||||
| arise_build="full" | ||||||||||||||||||||||
| echo "Starting site deploy. Building full site." | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r; | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| if [[ $REPLY =~ ^[Yy]$ ]]; then | ||||||||||||||||||||||
| force_overwrite=true; | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo 'Aborting.'; | ||||||||||||||||||||||
| exit 1; | ||||||||||||||||||||||
| fi; | ||||||||||||||||||||||
| elif [[ $@ == "build -kf" ]] || [[ $@ == "build -fk" ]]; then | ||||||||||||||||||||||
| arise_build="full" | ||||||||||||||||||||||
| keep_source=true | ||||||||||||||||||||||
| echo "Starting site deploy. Building full site. Source .md files will be retained in the final output." | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r; | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| if [[ $REPLY =~ ^[Yy]$ ]]; then | ||||||||||||||||||||||
| force_overwrite=true; | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo 'Aborting.'; | ||||||||||||||||||||||
| exit 1; | ||||||||||||||||||||||
| fi; | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| while getopts ":psrkf" options; do | ||||||||||||||||||||||
| case "${options}" in | ||||||||||||||||||||||
| p) | ||||||||||||||||||||||
| [[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; } | ||||||||||||||||||||||
| arise_build="pages_only"; | ||||||||||||||||||||||
| echo "Starting site deploy. Building pages only."; | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| s) | ||||||||||||||||||||||
| [[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; } | ||||||||||||||||||||||
| arise_build="sitemap_only"; | ||||||||||||||||||||||
| echo "Starting site deploy. Building sitemap only."; | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| r) | ||||||||||||||||||||||
| [[ -n "$arise_build" ]] && { arise_help; echo -e '\n\nERROR: Multiple exclusive build options detected. Aborting.'; exit 1; } | ||||||||||||||||||||||
| arise_build="rss_only"; | ||||||||||||||||||||||
| echo "Starting site deploy. Building RSS feed only."; | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| k) | ||||||||||||||||||||||
| keep_source=true; | ||||||||||||||||||||||
| echo "Source .md files will be retained in the final output."l | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| f) | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r; | ||||||||||||||||||||||
| echo; | ||||||||||||||||||||||
| if [[ $REPLY =~ ^[Yy]$ ]]; then | ||||||||||||||||||||||
| force_overwrite=true; | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo 'Aborting.'; | ||||||||||||||||||||||
| exit 1; | ||||||||||||||||||||||
| fi; | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| esac | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
| force_overwrite=0 | ||||||||||||||||||||||
| keep_source=0 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| build_pages=0 | ||||||||||||||||||||||
| build_sitemap=0 | ||||||||||||||||||||||
| build_rss=0 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # first pass to separate options (-asdf becomes -a -s -d -f) | ||||||||||||||||||||||
| trailing_args=() | ||||||||||||||||||||||
| while (($#)); do | ||||||||||||||||||||||
| arg=$1 | ||||||||||||||||||||||
| shift | ||||||||||||||||||||||
| case "$arg" in | ||||||||||||||||||||||
| (--?*) | ||||||||||||||||||||||
| trailing_args+=("$arg") | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (--) | ||||||||||||||||||||||
| trailing_args+=(--) | ||||||||||||||||||||||
| break | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-*) | ||||||||||||||||||||||
| for letter in $(echo "${arg#-}" | grep -o .); do | ||||||||||||||||||||||
| trailing_args+=("-$letter") | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (*) | ||||||||||||||||||||||
| trailing_args+=("$arg") | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| esac | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
| set -- "${trailing_args[@]}" "$@" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| trailing_args=() | ||||||||||||||||||||||
| while (($#)); do | ||||||||||||||||||||||
| arg="$1" | ||||||||||||||||||||||
| shift | ||||||||||||||||||||||
| case "$arg" in | ||||||||||||||||||||||
| (-h|--help) | ||||||||||||||||||||||
| arise_help | ||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-p|--pages) | ||||||||||||||||||||||
| build_pages=1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-s|--sitemap) | ||||||||||||||||||||||
| build_sitemap=1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-r|--rss) | ||||||||||||||||||||||
| build_rss=1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-f|--force) | ||||||||||||||||||||||
| force_overwrite=1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-k|--keep-source) | ||||||||||||||||||||||
| keep_source=1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (--) | ||||||||||||||||||||||
| break | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (-*) | ||||||||||||||||||||||
| echo "Unknown option: $arg" >&2 | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| (*) | ||||||||||||||||||||||
| trailing_args+=("$arg") | ||||||||||||||||||||||
| ;; | ||||||||||||||||||||||
| esac | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
| set -- "${trailing_args[@]}" "$@" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Display help if no arguments are provided | ||||||||||||||||||||||
| if [ "$#" -eq 0 ]; then | ||||||||||||||||||||||
| arise_help | ||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| [[ -z "$arise_build" ]] && { arise_help; exit 1; } | ||||||||||||||||||||||
| # Ensure first non-option argument is 'build' for default behaviour. Shift arguments and continue. | ||||||||||||||||||||||
| if [ "$1" != "build" ]; then | ||||||||||||||||||||||
| arise_help | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| shift | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ! (($build_pages || $build_sitemap || $build_rss)); then | ||||||||||||||||||||||
| build_pages=1 | ||||||||||||||||||||||
| build_sitemap=1 | ||||||||||||||||||||||
| build_rss=1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| echo | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (($force_overwrite)); then | ||||||||||||||||||||||
| read -p 'WARNING: Specifying "-f" will DELETE the current contents of '"$(realpath arise-out)"'. Proceed? [y/N]: ' -n 1 -r | ||||||||||||||||||||||
| echo | ||||||||||||||||||||||
| if ! [[ $REPLY =~ ^[Yy]$ ]]; then | ||||||||||||||||||||||
| echo 'Aborting.' | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make sure "arise_out" is empty and copy the source files over there to work from during the build process. | ||||||||||||||||||||||
| [[ -d arise-out ]] && [[ "$force_overwrite" == true ]] && rm -rf arise-out | ||||||||||||||||||||||
| [[ -d arise-out ]] && (($force_overwrite)) && rm -rf arise-out | ||||||||||||||||||||||
| mkdir -p arise-out | ||||||||||||||||||||||
| [[ -n "$(ls -A arise-out)" ]] && echo -e 'ERROR: The build output directory "/arise-out" is not empty. Program aborted to prevent overwrite of existing data.\n\nPlease empty the output directory before running Arise again or run your command with the "-f" flag to overwrite the existing output (dangerous).' && exit 1 | ||||||||||||||||||||||
| if [[ -n "$(ls -A arise-out)" ]]; then | ||||||||||||||||||||||
| cat <<"ERROR" >&2 | ||||||||||||||||||||||
| ERROR: The build output directory "/arise-out" is not empty. Program | ||||||||||||||||||||||
| aborted to prevent overwrite of existing data. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Please empty the output directory before running Arise again or run | ||||||||||||||||||||||
| your command with the "-f" flag to overwrite the existing output | ||||||||||||||||||||||
| (dangerous). | ||||||||||||||||||||||
| ERROR | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| cp -r "arise-source/". "arise-out" | ||||||||||||||||||||||
| ## Set an absolute path for $config | ||||||||||||||||||||||
| config=$(realpath $config) | ||||||||||||||||||||||
| config=$(realpath "$config") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Define a temporary file for a list of all source files for post-build cleanup | ||||||||||||||||||||||
| removelist="arise-out/arise-remove-$RANDOM.tmp" | ||||||||||||||||||||||
| touch $removelist | ||||||||||||||||||||||
| removelist=$(realpath $removelist) | ||||||||||||||||||||||
| removelist=$(realpath "$removelist") | ||||||||||||||||||||||
| touch "$removelist" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Run the build process depending on whatever options have been set | ||||||||||||||||||||||
| if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "pages_only" ]]; then | ||||||||||||||||||||||
| echo -n "Building pages..." | ||||||||||||||||||||||
| build_page_tree arise-out || { echo "ERROR: An error was encountered while building pages. Aborting build cycle."; exit 1; } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| if (($build_pages)); then | ||||||||||||||||||||||
| echo -n "Building pages..." | ||||||||||||||||||||||
| build_page_tree arise-out || { | ||||||||||||||||||||||
| echo "ERROR: An error was encountered while building pages. Aborting build cycle." >&2 | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "rss_only" ]]; then | ||||||||||||||||||||||
| echo -n "Building RSS feed..." | ||||||||||||||||||||||
| build_rss arise-out/rss.xml || { echo "ERROR: An error was encountered while building the RSS feed. Aborting build cycle."; exit 1; } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| if (($build_rss)); then | ||||||||||||||||||||||
| echo -n "Building RSS feed..." | ||||||||||||||||||||||
| build_rss arise-out/rss.xml || { | ||||||||||||||||||||||
| echo "ERROR: An error was encountered while building the RSS feed. Aborting build cycle." >&2 | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ "$arise_build" == "full" ]] || [[ "$arise_build" == "sitemap_only" ]]; then | ||||||||||||||||||||||
| echo -n "Building sitemap..." | ||||||||||||||||||||||
| build_sitemap arise-out/sitemap.xml || { echo "ERROR: An error was encountered while building the sitemap. Aborting build cycle."; exit 1; } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| if (($build_sitemap)); then | ||||||||||||||||||||||
| echo -n "Building sitemap..." | ||||||||||||||||||||||
| build_sitemap arise-out/sitemap.xml || { | ||||||||||||||||||||||
| echo "ERROR: An error was encountered while building the sitemap. Aborting build cycle." >&2 | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ "$keep_source" == false ]]; then | ||||||||||||||||||||||
| echo -n "Cleaning up build source files from output..." | ||||||||||||||||||||||
| # Remove every page that we built from as part of the build cycle | ||||||||||||||||||||||
| while read fname; do | ||||||||||||||||||||||
| [[ -f "$fname" ]] && rm "$fname" | ||||||||||||||||||||||
| done <$removelist | ||||||||||||||||||||||
| # Remove site config templates | ||||||||||||||||||||||
| rm "$config/header.html" | ||||||||||||||||||||||
| rm "$config/content_header.html" | ||||||||||||||||||||||
| rm "$config/footer.html" | ||||||||||||||||||||||
| rm "$config/arise.conf" | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| if ! (($keep_source)); then | ||||||||||||||||||||||
| echo -n "Cleaning up build source files from output..." | ||||||||||||||||||||||
| # Remove every page that we built from as part of the build cycle | ||||||||||||||||||||||
| while IFS="" read -r fname; do | ||||||||||||||||||||||
| [[ -f "$fname" ]] && rm "$fname" | ||||||||||||||||||||||
| done < "$removelist" | ||||||||||||||||||||||
| # Remove site config templates | ||||||||||||||||||||||
| rm "$config/header.html" | ||||||||||||||||||||||
| rm "$config/content_header.html" | ||||||||||||||||||||||
| rm "$config/footer.html" | ||||||||||||||||||||||
| rm "$config/arise.conf" | ||||||||||||||||||||||
| echo " DONE." | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| rm $removelist | ||||||||||||||||||||||
| rm "$removelist" | ||||||||||||||||||||||
| echo -e '\nBuild completed! Built artefacts have been generated at:\n'"$(realpath arise-out)" | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason you modified this and moved it up here is to allow a config option to make it easier to overwrite To make this cleaner, I changed it to an optional item; see additional suggestion below to use the snippet by default but allow overwrite.
Since PR base branch changes aren't disabled and GitHub reviews won't let me comment on the entire file, can I ask that you move this option below the version tag stub but above the 'begin main function' stub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I added this is because the script(s) is very reliant on relative paths to the root of the arise folder. My rationale is that it doesn't hurt to begin with a cd to the directory of the arise (and I get the path via this line) instead of relying on the user or external factors to have the appropriate current directory.
The reason this is at the top of the file is because that stackoverflow answer that I always copy paste in such situation says to be aware that this must be done before cd-ing to any other directory, so i paste it on the first lines.