From 2b1b586d8857a2895afff481b9d404deba32c548 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Thu, 15 Dec 2022 13:45:37 -0500 Subject: [PATCH] renamed repo --- README.md | 63 +++++++++++-------- etc/nginx/nginx.conf | 2 +- etc/nginx/sites-available/mastodon.conf | 2 +- ...t.patch => increase-sidekiq-timeout.patch} | 0 scripts/apply_patches.sh | 14 ++--- scripts/setup_nginx.sh | 32 ++++++++++ scripts/tootctl_shim.sh | 2 - scripts/upgrade.sh | 4 +- scripts/weekly_cleanup.sh | 2 +- 9 files changed, 81 insertions(+), 40 deletions(-) rename patches/{increase-sidekiq-http-timeout.patch => increase-sidekiq-timeout.patch} (100%) create mode 100755 scripts/setup_nginx.sh diff --git a/README.md b/README.md index 054f2f8..07c4a64 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,69 @@ -# 🦣 Mastodon randomness +# 🦣 Mastodon utilities Random opinionated helper scripts & front-end customizations for my [personal Mastodon instance](https://fediverse.jarv.is/about) (running on [`glitch-soc`](https://github.com/glitch-soc/mastodon)). You definitely don't want to use any of this as-is — check out my more general purpose [mastodon-installer](https://github.com/jakejarvis/mastodon-installer) scripts instead. ## Notes -The [wiki of this repo](https://github.com/jakejarvis/mastodon-scripts/wiki) and the [`/etc` folder](etc/) are simply my way of not forgetting how I did something, which I do quite a bit. Refer there for random notes on PgBouncer, Grafana, etc. but **DO NOT BLINDLY COPY & PASTE** anything there without doing your own research! +The [wiki of this repo](https://github.com/jakejarvis/mastodon-utils/wiki) and the [`/etc` folder](etc/) are simply my way of not forgetting how I did something, which I do quite a bit. Refer there for random notes on PgBouncer, Grafana, etc. but **DO NOT BLINDLY COPY & PASTE** anything there without doing your own research! -- [Grafana & Prometheus](https://github.com/jakejarvis/mastodon-scripts/wiki/Prometheus-&-Grafana) -- [ElasticSearch](https://github.com/jakejarvis/mastodon-scripts/wiki/ElasticSearch) -- [PgBouncer](https://github.com/jakejarvis/mastodon-scripts/wiki/Postgres-&-PgBouncer) -- [Brotli compression](https://github.com/jakejarvis/mastodon-scripts/wiki/Brotli-compression-for-nginx) +- [Grafana & Prometheus](https://github.com/jakejarvis/mastodon-utils/wiki/Prometheus-&-Grafana) +- [ElasticSearch](https://github.com/jakejarvis/mastodon-utils/wiki/ElasticSearch) +- [PgBouncer](https://github.com/jakejarvis/mastodon-utils/wiki/Postgres-&-PgBouncer) +- [Brotli compression](https://github.com/jakejarvis/mastodon-utils/wiki/Brotli-compression-for-nginx) ## Usage ***AGAIN, DEFINITELY DO NOT JUST RUN THIS IF YOU'RE NOT ME!!! 😊*** +This sets up the bare minimum customizations **after** Mastodon is installed: + ```sh -git clone https://github.com/jakejarvis/mastodon-scripts.git /home/mastodon/scripts +git clone https://github.com/jakejarvis/mastodon-utils.git /home/mastodon/utils && cd /home/mastodon/utils -# apply vanilla patches: -cd /home/mastodon/live -git apply --allow-binary-replacement /home/mastodon/scripts/patches/*.patch +# setup nginx using conf files from this repo: +./scripts/setup_nginx.sh -# apply glitch-only patches: -if [ -d /home/mastodon/live/app/javascript/flavours/glitch ]; then - git apply --allow-binary-replacement /home/mastodon/scripts/patches/glitch/*.patch -fi +# apply vanilla (and glitch-soc) patches from this repo: +./scripts/apply_patches.sh -# compile new assets: -RAILS_ENV=production bundle exec rails assets:precompile -chown -R mastodon:mastodon /home/mastodon/{scripts,live} - -# restart Mastodon: -systemctl restart mastodon-* +# cherry-pick everything else below... ``` ## Patches +#### Vanilla and `glitch-soc`: + - [`favicons.patch`](patches/favicons.patch): Use custom icon images instead of Mastodon logo - [`robots.patch`](patches/robots.patch): Disallow search engines for all of Mastodon -- [`increase-sidekiq-http-timeout.patch`](patches/increase-sidekiq-http-timeout.patch): Minor increase in time before Sidekiq decides a remove instance isn't available. **Use this one carefully!** +- [`increase-sidekiq-timeout.patch`](patches/increase-sidekiq-timeout.patch): Small bump in Sidekiq's timeout before it decides a remote instance isn't available. **Use this one very carefully!** - [`system-font.patch`](patches/system-font.patch): Use the system's default sans-serif font stack instead of Roboto - - [Additional `glitch-soc` patch](patches/glitch/system-font.patch) + - [`glitch/system-font.patch`](patches/glitch/system-font.patch) - [`hide-contact-email.patch`](patches/hide-contact-email.patch): Hides the `mailto:` link on the About page - - [Additional `glitch-soc` patch](patches/glitch/hide-contact-email.patch) + - [`glitch/hide-contact-email.patch`](patches/glitch/hide-contact-email.patch) - [`hide-rules.patch`](patches/hide-rules.patch): Applies just to homepage, meant only for single-user instances - - [Additional `glitch-soc` patch](patches/glitch/hide-rules.patch) + - [`glitch/hide-rules.patch`](patches/glitch/hide-rules.patch) - [`hide-signup.patch`](patches/hide-signup.patch): Hide the "create account" button (for aesthetics, **not security!**) - - [Additional `glitch-soc` patch](patches/glitch/hide-signup.patch) -- `glitch-soc` only: + - [`glitch/hide-signup.patch`](patches/glitch/hide-signup.patch) + +#### `glitch-soc` only: - [`custom-glitch-defaults.patch`](patches/glitch/custom-glitch-defaults.patch): Sets default Glitch appearance settings for logged-out users - [`remove-glitch-cruft.patch`](patches/glitch/remove-glitch-cruft.patch): Removes a bunch of junk no longer used by `glitch-soc` - [`sidebar-logo.patch`](patches/glitch/sidebar-logo.patch): Restore Mastodon logo in logged-out sidebar +## Scripts + +- [`apply_patches.sh`](scripts/apply_patches.sh): Dangerously applies ***every patch*** listed above, and automatically detects if `glitch-soc` patches should also be applied +- [`backup.sh`](scripts/backup.sh): Backs up Postgres, Redis, and `.env.production` secrets to a `.tar.gz` file in `/home/mastodon/backups` — useful for a periodic cronjob +- [`setup_nginx.sh`](scripts/setup_nginx.sh): Sets up symlinks from `/etc/nginx` to nginx confs in this repo +- [`tootctl_shim.sh`](scripts/tootctl_shim.sh): Small shell shim to run `tootctl` in `/home/mastodon/live` as the `mastodon` user by anyone & from anywhere + - Add this line to the `.bash_profile` of the user you normally login as: + - `. /home/mastodon/utils/scripts/tootctl_shim.sh` +- [`upgrade.sh`](scripts/upgrade.sh): Upgrades Mastodon server (latest version if vanilla Mastodon, latest commit if `glitch-soc`) and re-applies patches listed above +- [`version.sh`](scripts/version.sh): Tests `tootctl_shim.sh` by printing Mastodon version (`tootctl version`) +- [`weekly_cleanup.sh`](scripts/weekly_cleanup.sh): Runs Mastodon's built-in [cleanup commands](https://docs.joinmastodon.org/admin/setup/#cleanup), designed for a [weekly cronjob](https://github.com/jakejarvis/mastodon-utils/wiki/Cleanup-tasks) + - Keeps 7 days of media (in object storage) + - Keeps 90 days of generated preview cards + ## License MIT diff --git a/etc/nginx/nginx.conf b/etc/nginx/nginx.conf index 76247a6..6eec262 100644 --- a/etc/nginx/nginx.conf +++ b/etc/nginx/nginx.conf @@ -3,7 +3,7 @@ worker_processes auto; pid /run/nginx.pid; # compiled brotli modules from https://github.com/google/ngx_brotli -# see: https://github.com/jakejarvis/mastodon-scripts/wiki/Brotli-compression-for-nginx +# see: https://github.com/jakejarvis/mastodon-utils/wiki/Brotli-compression-for-nginx load_module modules/ngx_http_brotli_filter_module.so; load_module modules/ngx_http_brotli_static_module.so; diff --git a/etc/nginx/sites-available/mastodon.conf b/etc/nginx/sites-available/mastodon.conf index fb8fb1d..521f294 100644 --- a/etc/nginx/sites-available/mastodon.conf +++ b/etc/nginx/sites-available/mastodon.conf @@ -52,7 +52,7 @@ server { gzip_min_length 256; # https://github.com/google/ngx_brotli#sample-configuration - # https://github.com/jakejarvis/mastodon-scripts/wiki/Brotli-compression-for-nginx + # https://github.com/jakejarvis/mastodon-utils/wiki/Brotli-compression-for-nginx brotli on; brotli_comp_level 4; brotli_static on; diff --git a/patches/increase-sidekiq-http-timeout.patch b/patches/increase-sidekiq-timeout.patch similarity index 100% rename from patches/increase-sidekiq-http-timeout.patch rename to patches/increase-sidekiq-timeout.patch diff --git a/scripts/apply_patches.sh b/scripts/apply_patches.sh index 6418a47..3f630aa 100755 --- a/scripts/apply_patches.sh +++ b/scripts/apply_patches.sh @@ -6,26 +6,26 @@ set -euo pipefail # default paths MASTODON_ROOT=/home/mastodon APP_ROOT="$MASTODON_ROOT/live" -SCRIPTS_ROOT="$MASTODON_ROOT/scripts" +UTILS_ROOT="$MASTODON_ROOT/utils" RBENV_ROOT="$MASTODON_ROOT/.rbenv" # clone this repo if it doesn't exist in the proper location -if [ ! -d "$SCRIPTS_ROOT" ] +if [ ! -d "$UTILS_ROOT" ] then - sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-scripts.git "$SCRIPTS_ROOT" + sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-utils.git "$UTILS_ROOT" # fix permissions - sudo chown -R mastodon:mastodon "$SCRIPTS_ROOT" - sudo git config --global --add safe.directory "$SCRIPTS_ROOT" + sudo chown -R mastodon:mastodon "$UTILS_ROOT" + sudo git config --global --add safe.directory "$UTILS_ROOT" fi # apply custom patches cd "$APP_ROOT" -sudo -u mastodon git apply --reject --allow-binary-replacement "$SCRIPTS_ROOT"/patches/*.patch +sudo -u mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/*.patch if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then # apply additional glitch-only patches: - sudo -u mastodon git apply --reject --allow-binary-replacement "$SCRIPTS_ROOT"/patches/glitch/*.patch + sudo -u mastodon git apply --reject --allow-binary-replacement "$UTILS_ROOT"/patches/glitch/*.patch fi # update dependencies diff --git a/scripts/setup_nginx.sh b/scripts/setup_nginx.sh new file mode 100755 index 0000000..7c10bdc --- /dev/null +++ b/scripts/setup_nginx.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# symlinks files from this repo to their proper location + +# exit when any step fails +set -euo pipefail + +# default paths +MASTODON_ROOT=/home/mastodon +APP_ROOT="$MASTODON_ROOT/live" +UTILS_ROOT="$MASTODON_ROOT/utils" + +# clone this repo if it doesn't exist in the proper location +if [ ! -d "$UTILS_ROOT" ] +then + sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-utils.git "$UTILS_ROOT" + + # fix permissions + sudo chown -R mastodon:mastodon "$UTILS_ROOT" + sudo git config --global --add safe.directory "$UTILS_ROOT" +fi + +# setup nginx config +sudo rm -rf /etc/nginx/sites-available +sudo rm -rf /etc/nginx/sites-enabled/* +sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak +sudo ln -sf "$UTILS_ROOT/etc/nginx/nginx.conf" /etc/nginx/nginx.conf +sudo ln -sf "$UTILS_ROOT/etc/nginx/modules" /usr/lib/nginx/modules +sudo ln -sf "$UTILS_ROOT/etc/nginx/sites-available" /etc/nginx/sites-available +sudo ln -sf /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf +sudo ln -sf /etc/nginx/sites-available/mastodon.conf /etc/nginx/sites-enabled/mastodon.conf +sudo nginx -t +sudo nginx -s reload diff --git a/scripts/tootctl_shim.sh b/scripts/tootctl_shim.sh index 48f3baa..94f246b 100755 --- a/scripts/tootctl_shim.sh +++ b/scripts/tootctl_shim.sh @@ -1,7 +1,5 @@ #!/bin/sh -set -e - MASTODON_ROOT=/home/mastodon APP_ROOT="$MASTODON_ROOT/live" RBENV_ROOT="$MASTODON_ROOT/.rbenv" diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 973ab3b..3e4ec09 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -6,7 +6,7 @@ set -euo pipefail # default paths MASTODON_ROOT=/home/mastodon APP_ROOT="$MASTODON_ROOT/live" -SCRIPTS_ROOT="$MASTODON_ROOT/scripts" +UTILS_ROOT="$MASTODON_ROOT/utils" RBENV_ROOT="$MASTODON_ROOT/.rbenv" # check for existing installation @@ -30,7 +30,7 @@ else fi # pull & apply latest patches -. "$SCRIPTS_ROOT/scripts/apply_patches.sh" +. "$UTILS_ROOT/scripts/apply_patches.sh" # create blank custom.css (this overrides any CSS set in the admin panel, but if that's not being used, then # this quickly saves a request to the backend) diff --git a/scripts/weekly_cleanup.sh b/scripts/weekly_cleanup.sh index b04c2f4..5cd0396 100755 --- a/scripts/weekly_cleanup.sh +++ b/scripts/weekly_cleanup.sh @@ -2,7 +2,7 @@ # cronjob ran once per week at 3 AM on Sunday; see https://crontab.guru/#0_3_*_*_0 # syntax for crontab -e: -# 0 3 * * 0 root /home/mastodon/scripts/weekly_cleanup.sh >> /home/mastodon/logs/cron.log 2>&1 +# 0 3 * * 0 root /home/mastodon/utils/weekly_cleanup.sh >> /home/mastodon/logs/cron.log 2>&1 set -e