From 7c1762289a9bc83d85b38b408c32e9da26278d04 Mon Sep 17 00:00:00 2001 From: Sharp-tailed Grouse Date: Tue, 18 Oct 2022 13:54:31 -0400 Subject: [PATCH] Move scripts to their own dir (aptly named script) Move scripts to their own directory. Add `serve` script for serving locally (from internal build repo). Rename: - clean.sh -> script/clean - make.sh -> script/make Now you can type `make serve` to serve the guide locally. $ make all clean guide serve Requirements are still included in the `serve` file. Signed-off-by: Sharp-tailed Grouse --- Makefile | 30 ++++++++++++------------ script/README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++ script/clean | 12 ++++++++++ script/make | 45 ++++++++++++++++++++++++++++++++++++ script/serve | 37 ++++++++++++++++++++++++++++++ script/serve-as-user | 49 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 212 insertions(+), 15 deletions(-) create mode 100644 script/README.md create mode 100644 script/clean create mode 100644 script/make create mode 100644 script/serve create mode 100644 script/serve-as-user diff --git a/Makefile b/Makefile index e7c1d8a..0432f24 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ -all: guide - -guide: clean - ./script/make.sh - -.phony: serve -serve: # This gets all gems and installs bundler. - # Serves the guide locally using Jekyll. 🍽️ - @echo "Serving site..." - ./script/serve.sh - -clean: # Clean artifacts. 🧹 - @echo "Cleaning..." - ./script/clean.sh - +all: guide + +guide: clean + ./script/make + +.phony: serve +serve: # This gets all gems and installs bundler. + # Serves the guide locally using Jekyll. 🍽️ + @echo "Serving site..." + ./script/serve + +clean: # Clean artifacts. 🧹 + @echo "Cleaning..." + ./script/clean + diff --git a/script/README.md b/script/README.md new file mode 100644 index 0000000..8bc767d --- /dev/null +++ b/script/README.md @@ -0,0 +1,54 @@ +### Serving locally (system-wide): + +- Ruby >=2.7.3 needs to be installed +- Git needs to be installed +- Move this file to the root dir (the clone dir) +- Don't run directly as `root` +- Needs to be executed with sudo permissions + * Essentially, `sudo ./serve` +- Ignore the errors of "gem update" + +### Serving locally (as user only): + +- Ruby >=2.7.3 needs to be installed (with sudo) +- Git needs to be installed (with sudo) +- Move this file to the root dir (the clone dir) +- Add the following to your user's `.profile`: + +``` +GEM_HOME="$(ruby -e 'puts Gem.user_dir')" +PATH="$PATH:$GEM_HOME/bin" +``` + +### Run the build script: + + > cp ./serve ../../ + > cd thgtoa/ + > sudo ./serve + [sudo] password for : + + ...snip... + +Wait a while for this to finish (first run takes a few minutes). +Now you have updated the gem dependencies. + +### Congrats, it's a...bundle: + + Bundle complete! 2 Gemfile dependencies, 92 gems now installed. + Use `bundle info [gemname]` to see where a bundled gem is installed. + +### Serve the site locally: + > sudo bundle exec jekyll serve + ...snip ... + + Server address: http://127.0.0.1:4000 + Server running... press ctrl-c to stop. + +You are now free to make your desired changes for the guide. +You can clone remotes and test them here, you can do whatever. + +### Non-root user install: + +- +- +- diff --git a/script/clean b/script/clean new file mode 100644 index 0000000..99a1dae --- /dev/null +++ b/script/clean @@ -0,0 +1,12 @@ +#!/bin/bash + +rm *.pdf &> /dev/null +rm *.html &> /dev/null +rm *.odt &> /dev/null +rm *.minisig &> /dev/null +rm *.asc &> /dev/null +rm sha256sum.txt &> /dev/null +rm b2sum.txt &> /dev/null +rm -r export/{.,}* &> /dev/null + +true diff --git a/script/make b/script/make new file mode 100644 index 0000000..a273cec --- /dev/null +++ b/script/make @@ -0,0 +1,45 @@ +#!/bin/bash + +if [[ "$1" == "" ]]; then + # Build all `md` files + for f in *.md; do + echo "Building: $f" + bn="$(basename "$f" .md)" + "$0" "$bn" + done + echo "Built all documents. Calculating hashes..." + cd export/ + sha256sum ./* > sha256sum.txt + b2sum ./* > b2sum.txt + echo "Calculated hashes. Signing generated files..." + for f in ./*; do + echo "Signing: $f" + # verify with GPG + gpg --armor --detach-sign --sign "$f" + # verify with `minisign -Vm -P RWQ0WYJ07DUokK8V/6LNJ9bf/O/QM9k4FSlDmzgEeXm7lEpw3ecYjXDM` + yes '' | minisign -S -s /home/user/.minisign/minisign.key -m "$f" + done + cd ../ + cp /home/user/KEY_ROTATION.md.7DFFD7471FB76E2A8ABBBCDDD769B3749E933B8A.asc ./KEY_ROTATION.md.asc + cp /home/user/KEY_ROTATION.md.902835EC74825934.minisig ./KEY_ROTATION.md.minisig + gpg --armor --export 42FF35DB9DE7C088AB0FD4A70C216A52F6DF4920 > 42FF35DB9DE7C088AB0FD4A70C216A52F6DF4920.asc + sha256sum *.md > sha256sum.txt + gpg --armor --detach-sign sha256sum.txt + yes '' | minisign -S -s /home/user/.minisign/minisign.key -m sha256sum.txt + b2sum *.md > b2sum.txt + gpg --armor --detach-sign b2sum.txt + yes '' | minisign -S -s /home/user/.minisign/minisign.key -m b2sum.txt + echo "Signed all files." + echo "Done." + exit +fi + +bn="$1" + +#echo "Generating HTML..." +#pandoc --self-contained "$bn".md -o export/"$bn".html --metadata title="The Hitchhiker's Guide to Online Anonymity" +#echo "Generating PDF..." +#pandoc --self-contained "$bn".md -o export/"$bn".pdf --metadata title="The Hitchhiker's Guide to Online Anonymity" -t context +#echo "Generating ODT..." +#pandoc --self-contained "$bn".md -o export/"$bn".odt --metadata title="The Hitchhiker's Guide to Online Anonymity" + diff --git a/script/serve b/script/serve new file mode 100644 index 0000000..8e3c3e2 --- /dev/null +++ b/script/serve @@ -0,0 +1,37 @@ +#!/bin/bash + +# Prerequisites: +# 1. git +# 2. ruby +# 3. ruby-dev +# +# Script MUST be in the root of the git clone directory of your choice. +# You MUST execute it with elevated privileges. +# +# When done you can execute these commands: +# $ bundle exec jekyll serve --livereload (will build and serve the project locally) +# $ bundle exec jekyll build (will build the site in _site folder) + +gem update # Errors are safely ignored. +gem install bundler jekyll # Speaks for itself. +rm -f Gemfile* # Out with the old.. +bundle init # ..and in with the new. +rm -rf ./vendor/ # In case `bundle init` above does anything weird. + +# Creating the Gemfile we want +cat <Gemfile +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +# gem "jekyll", "~> 4.2" +gem "github-pages", group: :jekyll_plugins +gem "jekyll-optional-front-matter", group: :jekyll_plugins +gem "webrick", "~> 1.7" +EOF +bundle install # this will install gems and create a new Gemfile.lock + +echo "Now you can test locally: " +echo "$ bundle exec jekyll serve --livereload" diff --git a/script/serve-as-user b/script/serve-as-user new file mode 100644 index 0000000..cc50980 --- /dev/null +++ b/script/serve-as-user @@ -0,0 +1,49 @@ +#!/bin/bash + +# Prerequisites: +# 1. git +# 2. ruby +# 3. ruby-dev +# +# Script MUST be in the root of the git clone directory of your choice. +# You MUST execute it with elevated privileges. +# +# When done you can execute these commands: +# $ bundle exec jekyll serve --livereload (will build and serve the project locally) +# $ bundle exec jekyll build (will build the site in _site folder) + +function pause() +{ + read -p "$*" +} + +echo add the following to your non-root .profile: +echo '''export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"''' +echo '''export PATH="$PATH:$GEM_HOME/bin"''' + +pause 'Press [Enter] key to continue...' + +sudo gem update # Errors are safely ignored. +gem install bundler --user-install # Speaks for itself. +gem install jekyll --user-install # Speaks for itself. +rm -f Gemfile* # Out with the old.. +bundle init # ..and in with the new. +rm -rf ./vendor/ # In case `bundle init` above does anything weird. + +# Creating the Gemfile we want +cat <Gemfile +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +# gem "jekyll", "~> 4.2" +gem "github-pages", group: :jekyll_plugins +gem "jekyll-optional-front-matter", group: :jekyll_plugins +gem "webrick", "~> 1.7" +EOF +bundle install --user-install # this will install gems and create a new Gemfile.lock + +echo "Now you can test locally: " +echo "$ bundle exec jekyll serve --livereload"