1
mirror of https://github.com/jakejarvis/mastodon-utils.git synced 2025-04-26 02:15:22 -04:00

renamed repo

This commit is contained in:
Jake Jarvis 2022-12-15 13:45:37 -05:00
parent 046c63d220
commit 2b1b586d88
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
9 changed files with 81 additions and 40 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

32
scripts/setup_nginx.sh Executable file
View File

@ -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

View File

@ -1,7 +1,5 @@
#!/bin/sh
set -e
MASTODON_ROOT=/home/mastodon
APP_ROOT="$MASTODON_ROOT/live"
RBENV_ROOT="$MASTODON_ROOT/.rbenv"

View File

@ -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)

View File

@ -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