You've already forked mastodon-utils
mirror of
https://github.com/jakejarvis/mastodon-utils.git
synced 2025-06-27 17:25:42 -04:00
clean up scripts
This commit is contained in:
13
README.md
13
README.md
@ -8,14 +8,21 @@ Random opinionated helper scripts & front-end customizations for my [personal Ma
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/jakejarvis/mastodon-scripts.git /home/mastodon/scripts
|
git clone https://github.com/jakejarvis/mastodon-scripts.git /home/mastodon/scripts
|
||||||
git config --global --add safe.directory /home/mastodon/scripts
|
|
||||||
|
|
||||||
|
# apply vanilla patches:
|
||||||
cd /home/mastodon/live
|
cd /home/mastodon/live
|
||||||
git apply --allow-binary-replacement --whitespace=warn /home/mastodon/scripts/patches/*.patch /home/mastodon/scripts/glitch/*.patch || true
|
git apply --allow-binary-replacement /home/mastodon/scripts/patches/*.patch
|
||||||
RAILS_ENV=production bundle exec rails assets:precompile
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# compile new assets:
|
||||||
|
RAILS_ENV=production bundle exec rails assets:precompile
|
||||||
chown -R mastodon:mastodon /home/mastodon/{scripts,live}
|
chown -R mastodon:mastodon /home/mastodon/{scripts,live}
|
||||||
|
|
||||||
|
# restart Mastodon:
|
||||||
systemctl restart mastodon-*
|
systemctl restart mastodon-*
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -5,21 +5,44 @@ set -euo pipefail
|
|||||||
|
|
||||||
# default paths
|
# default paths
|
||||||
MASTODON_ROOT=/home/mastodon
|
MASTODON_ROOT=/home/mastodon
|
||||||
|
APP_ROOT="$MASTODON_ROOT/live"
|
||||||
|
SCRIPTS_ROOT="$MASTODON_ROOT/scripts"
|
||||||
|
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||||
|
|
||||||
if [ ! -d "$MASTODON_ROOT/scripts" ]
|
# clone this repo if it doesn't exist in the proper location
|
||||||
|
if [ ! -d "$SCRIPTS_ROOT" ]
|
||||||
then
|
then
|
||||||
# clone repo
|
sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-scripts.git "$SCRIPTS_ROOT"
|
||||||
sudo -u mastodon git clone https://github.com/jakejarvis/mastodon-scripts.git "$MASTODON_ROOT/scripts"
|
|
||||||
|
|
||||||
# fix permissions
|
# fix permissions
|
||||||
sudo chown -R mastodon:mastodon "$MASTODON_ROOT/scripts"
|
sudo chown -R mastodon:mastodon "$SCRIPTS_ROOT"
|
||||||
sudo git config --global --add safe.directory "$MASTODON_ROOT/scripts"
|
sudo git config --global --add safe.directory "$SCRIPTS_ROOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# pull latest patches
|
# pull latest patches
|
||||||
cd "$MASTODON_ROOT/scripts"
|
cd "$SCRIPTS_ROOT"
|
||||||
sudo -u mastodon git pull origin main
|
sudo -u mastodon git fetch origin --all
|
||||||
|
sudo -u mastodon git reset origin/main --hard
|
||||||
|
|
||||||
# apply custom patches
|
# apply custom patches
|
||||||
cd "$MASTODON_ROOT/live"
|
cd "$APP_ROOT"
|
||||||
sudo -u mastodon git apply --allow-binary-replacement --whitespace=warn "$MASTODON_ROOT"/scripts/patches/*.patch || true
|
sudo -u mastodon git apply --allow-binary-replacement "$SCRIPTS_ROOT"/patches/*.patch
|
||||||
|
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ];
|
||||||
|
then
|
||||||
|
# apply additional glitch-only patches:
|
||||||
|
sudo -u mastodon git apply --allow-binary-replacement "$SCRIPTS_ROOT"/patches/glitch/*.patch
|
||||||
|
fi
|
||||||
|
|
||||||
|
# update dependencies
|
||||||
|
echo "Updating deps..."
|
||||||
|
sudo -u mastodon "$RBENV_ROOT/shims/bundle" install --jobs "$(getconf _NPROCESSORS_ONLN)"
|
||||||
|
sudo -u mastodon yarn install --pure-lockfile --network-timeout 100000
|
||||||
|
|
||||||
|
# compile new assets
|
||||||
|
echo "Compiling new assets..."
|
||||||
|
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails assets:precompile
|
||||||
|
sudo chown -R mastodon:mastodon "$APP_ROOT"
|
||||||
|
|
||||||
|
# restart frontend
|
||||||
|
echo "Restarting mastodon-web..."
|
||||||
|
sudo systemctl restart mastodon-web
|
||||||
|
@ -5,6 +5,8 @@ set -euo pipefail
|
|||||||
|
|
||||||
# default paths
|
# default paths
|
||||||
MASTODON_ROOT=/home/mastodon
|
MASTODON_ROOT=/home/mastodon
|
||||||
|
APP_ROOT="$MASTODON_ROOT/live"
|
||||||
|
BACKUPS_ROOT="$MASTODON_ROOT/backups"
|
||||||
|
|
||||||
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]
|
if [ "$(systemctl is-active mastodon-web.service)" = "active" ]
|
||||||
then
|
then
|
||||||
@ -14,10 +16,10 @@ then
|
|||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "$MASTODON_ROOT/backups" ]
|
if [ ! -d "$BACKUPS_ROOT" ]
|
||||||
then
|
then
|
||||||
sudo mkdir -p "$MASTODON_ROOT/backups"
|
sudo mkdir -p "$BACKUPS_ROOT"
|
||||||
sudo chown -R mastodon:mastodon "$MASTODON_ROOT/backups"
|
sudo chown -R mastodon:mastodon "$BACKUPS_ROOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEMP_DIR=$(sudo -u mastodon mktemp -d)
|
TEMP_DIR=$(sudo -u mastodon mktemp -d)
|
||||||
@ -32,7 +34,7 @@ echo "Backing up secrets..."
|
|||||||
sudo cp "$MASTODON_ROOT/live/.env.production" "$TEMP_DIR/env.production"
|
sudo cp "$MASTODON_ROOT/live/.env.production" "$TEMP_DIR/env.production"
|
||||||
|
|
||||||
echo "Compressing..."
|
echo "Compressing..."
|
||||||
ARCHIVE_DEST="$MASTODON_ROOT/backups/$(date "+%Y.%m.%d-%H.%M.%S").tar.gz"
|
ARCHIVE_DEST="$BACKUPS_ROOT/$(date "+%Y.%m.%d-%H.%M.%S").tar.gz"
|
||||||
sudo tar --owner=0 --group=0 -czvf "$ARCHIVE_DEST" -C "$TEMP_DIR" .
|
sudo tar --owner=0 --group=0 -czvf "$ARCHIVE_DEST" -C "$TEMP_DIR" .
|
||||||
sudo chown mastodon:mastodon "$ARCHIVE_DEST"
|
sudo chown mastodon:mastodon "$ARCHIVE_DEST"
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
MASTODON_ROOT=/home/mastodon
|
MASTODON_ROOT=/home/mastodon
|
||||||
|
APP_ROOT="$MASTODON_ROOT/live"
|
||||||
|
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||||
|
|
||||||
tootctl() {
|
tootctl() {
|
||||||
( cd "$MASTODON_ROOT/live" && sudo -u mastodon RAILS_ENV=production "$MASTODON_ROOT/.rbenv/shims/ruby" "$MASTODON_ROOT/live/bin/tootctl" "$@" )
|
( cd "$APP_ROOT" && sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$APP_ROOT/bin/tootctl" "$@" )
|
||||||
}
|
}
|
||||||
|
@ -5,50 +5,53 @@ set -euo pipefail
|
|||||||
|
|
||||||
# default paths
|
# default paths
|
||||||
MASTODON_ROOT=/home/mastodon
|
MASTODON_ROOT=/home/mastodon
|
||||||
|
APP_ROOT="$MASTODON_ROOT/live"
|
||||||
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
RBENV_ROOT="$MASTODON_ROOT/.rbenv"
|
||||||
|
|
||||||
# check for existing installation
|
# check for existing installation
|
||||||
if [ ! -d "$MASTODON_ROOT/live" ]
|
if [ ! -d "$APP_ROOT" ]; then
|
||||||
then
|
echo "$APP_ROOT doesn't exist, are you sure Mastodon is installed?"
|
||||||
echo "$MASTODON_ROOT/live doesn't exist, are you sure Mastodon is installed?"
|
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# pull latest mastodon source
|
# pull latest mastodon source
|
||||||
cd "$MASTODON_ROOT/live"
|
cd "$APP_ROOT"
|
||||||
sudo -u mastodon git fetch --all
|
sudo -u mastodon git fetch --all
|
||||||
sudo -u mastodon git checkout glitch-soc/main
|
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
|
||||||
sudo -u mastodon git pull glitch-soc main
|
# glitch-soc (uses latest commits)
|
||||||
|
echo "Pulling latest glitch-soc commits..."
|
||||||
|
sudo -u mastodon git checkout glitch-soc/main
|
||||||
|
else
|
||||||
|
# vanilla (uses latest release)
|
||||||
|
echo "Pulling latest Mastodon release..."
|
||||||
|
sudo -u mastodon git checkout "$(sudo -u mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
|
||||||
|
fi
|
||||||
|
|
||||||
# pull & apply latest patches
|
# pull & apply latest patches
|
||||||
. $(dirname "$0")/apply_patches.sh
|
. "$(dirname "$0")/apply_patches.sh"
|
||||||
|
|
||||||
# update dependencies
|
# set new ruby version
|
||||||
echo "Updating deps..."
|
RUBY_VERSION="$(sudo -u mastodon cat $APP_ROOT/.ruby-version)"
|
||||||
sudo -u mastodon "$RBENV_ROOT/shims/bundle" install --jobs "$(getconf _NPROCESSORS_ONLN)"
|
sudo -u mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc "$RBENV_ROOT/bin/rbenv" install "$RUBY_VERSION" || true
|
||||||
sudo -u mastodon yarn install --pure-lockfile --network-timeout 100000
|
sudo -u mastodon "$RBENV_ROOT/bin/rbenv" global "$RUBY_VERSION"
|
||||||
|
|
||||||
# run migrations:
|
# run migrations:
|
||||||
# https://docs.joinmastodon.org/admin/upgrading/
|
# https://docs.joinmastodon.org/admin/upgrading/
|
||||||
echo "Running pre-deploy database migrations..."
|
echo "Running pre-deploy database migrations..."
|
||||||
sudo -u mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
sudo -u mastodon SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||||
echo "Compiling new assets..."
|
|
||||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails assets:precompile
|
|
||||||
|
|
||||||
# restart mastodon
|
# restart mastodon
|
||||||
echo "Restarting services (round 1/2)..."
|
echo "Restarting services (round 1/2)..."
|
||||||
sudo systemctl reload mastodon-web
|
|
||||||
sudo systemctl restart mastodon-sidekiq mastodon-streaming
|
sudo systemctl restart mastodon-sidekiq mastodon-streaming
|
||||||
|
|
||||||
# clear caches & run post-deployment db migration
|
# clear caches & run post-deployment db migration
|
||||||
echo "Clearing cache..."
|
echo "Clearing cache..."
|
||||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$MASTODON_ROOT/live/bin/tootctl" cache clear
|
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/ruby" "$APP_ROOT/bin/tootctl" cache clear
|
||||||
echo "Running post-deploy database migrations..."
|
echo "Running post-deploy database migrations..."
|
||||||
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
sudo -u mastodon RAILS_ENV=production "$RBENV_ROOT/shims/bundle" exec rails db:migrate
|
||||||
|
|
||||||
# restart mastodon again
|
# restart mastodon again
|
||||||
echo "Restarting services (round 2/2)..."
|
echo "Restarting services (round 2/2)..."
|
||||||
sudo systemctl reload mastodon-web
|
sudo systemctl restart mastodon-web mastodon-sidekiq mastodon-streaming
|
||||||
sudo systemctl restart mastodon-sidekiq mastodon-streaming
|
|
||||||
|
|
||||||
echo "🎉 done!"
|
echo "🎉 done!"
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
. $(dirname "$0")/tootctl_shim.sh
|
. "$(dirname "$0")/tootctl_shim.sh"
|
||||||
|
|
||||||
tootctl version
|
tootctl version
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
. $(dirname "$0")/toot_shim.sh
|
. "$(dirname "$0")/toot_shim.sh"
|
||||||
|
|
||||||
tootctl media remove --days 7
|
tootctl media remove --days 7
|
||||||
tootctl preview_cards remove --days 90
|
tootctl preview_cards remove --days 90
|
||||||
|
Reference in New Issue
Block a user