You've already forked mastodon-utils
							
							
				mirror of
				https://github.com/jakejarvis/mastodon-utils.git
				synced 2025-11-04 10:20:11 -05:00 
			
		
		
		
	use bash script for some customizations instead of Git patches
This commit is contained in:
		@@ -23,10 +23,6 @@ if [ ! -d "$BACKUPS_ROOT" ]; then
 | 
			
		||||
  as_mastodon mkdir -p "$BACKUPS_ROOT"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ ! -d "$LOGS_ROOT" ]; then
 | 
			
		||||
  as_mastodon mkdir -p "$LOGS_ROOT"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
TEMP_DIR=$(as_mastodon mktemp -d)
 | 
			
		||||
 | 
			
		||||
echo "Backing up Postgres..."
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										94
									
								
								scripts/customize.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										94
									
								
								scripts/customize.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# exit when any step fails
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
 | 
			
		||||
# initialize path (only if needed)
 | 
			
		||||
if [ "${MASTODON_INIT_RUN:=}" != true ]; then
 | 
			
		||||
  . "$(dirname "$(realpath "$0")")"/../init.sh
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# re-detect glitch-soc
 | 
			
		||||
MASTODON_IS_GLITCH="$(test -d "$APP_ROOT/app/javascript/flavours/glitch" && echo true || echo false)"
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# apply custom patches (skips errors)
 | 
			
		||||
for f in "$UTILS_ROOT"/patches/*.patch; do
 | 
			
		||||
  as_mastodon git apply --reject --allow-binary-replacement "$f" || true
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# apply additional glitch-only patches if applicable
 | 
			
		||||
if [ "$MASTODON_IS_GLITCH" = true ]; then
 | 
			
		||||
  for f in "$UTILS_ROOT"/patches/glitch/*.patch; do
 | 
			
		||||
    as_mastodon git apply --reject --allow-binary-replacement "$f" || true
 | 
			
		||||
  done
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# remove this list of unused glitch cruft
 | 
			
		||||
if [ "$MASTODON_IS_GLITCH" = true ]; then
 | 
			
		||||
  removePaths=(
 | 
			
		||||
    "app/javascript/images/clippy_frame.png"
 | 
			
		||||
    "app/javascript/images/clippy_wave.gif"
 | 
			
		||||
    "app/javascript/images/icon_*.png"
 | 
			
		||||
    "app/javascript/images/start.png"
 | 
			
		||||
    "app/javascript/skins/vanilla/win95/"
 | 
			
		||||
    "app/javascript/styles/win95.scss"
 | 
			
		||||
    "public/background-cybre.png"
 | 
			
		||||
    "public/clock.js"
 | 
			
		||||
    "public/logo-cybre-glitch.gif"
 | 
			
		||||
    "public/riot-glitch.png"
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  for f in "${removePaths[@]}"; do
 | 
			
		||||
    as_mastodon rm -rf --preserve-root "$APP_ROOT/$f"
 | 
			
		||||
  done
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# apply a more restrictive robots.txt
 | 
			
		||||
as_mastodon tee "$APP_ROOT/public/robots.txt" > /dev/null <<EOT
 | 
			
		||||
# block everything except About page
 | 
			
		||||
User-agent: *
 | 
			
		||||
Allow: /about
 | 
			
		||||
Disallow: /
 | 
			
		||||
 | 
			
		||||
# sorry, Elon :)
 | 
			
		||||
User-agent: Twitterbot
 | 
			
		||||
Disallow: /
 | 
			
		||||
EOT
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# change default settings, mostly for logged-out visitors
 | 
			
		||||
# requires yq (`snap install yq` - it's like jq but for yaml: https://github.com/mikefarah/yq/#install)
 | 
			
		||||
if command -v yq >/dev/null 2>&1; then
 | 
			
		||||
  as_mastodon yq -i '.defaults.site_title = "Mastodon"' "$APP_ROOT/config/settings.yml"
 | 
			
		||||
  as_mastodon yq -i '.defaults.show_application = true' "$APP_ROOT/config/settings.yml"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# change glitch-only settings located in a JS file, also mostly for logged-out visitors
 | 
			
		||||
if [ "$MASTODON_IS_GLITCH" = true ]; then
 | 
			
		||||
  set_default() {
 | 
			
		||||
    as_mastodon sed \
 | 
			
		||||
      -e "s/$1\s*:\s*.*/$1: $2, \/\/ updated by customize.sh/g" \
 | 
			
		||||
      -i "$APP_ROOT/app/javascript/flavours/glitch/reducers/local_settings.js"
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  set_default "show_reply_count" "true"
 | 
			
		||||
  set_default "hicolor_privacy_icons" "true"
 | 
			
		||||
  set_default "rewrite_mentions" "'acct'"
 | 
			
		||||
  set_default "lengthy" "false"
 | 
			
		||||
  set_default "letterbox" "false"
 | 
			
		||||
  set_default "language" "false"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# ---
 | 
			
		||||
 | 
			
		||||
# create a blank 'custom.css' to save a request to the backend, assuming it's not being used
 | 
			
		||||
as_mastodon touch "$APP_ROOT/public/custom.css"
 | 
			
		||||
@@ -23,10 +23,10 @@ if [ -d "$APP_ROOT" ]; then
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# ask for required info up-front
 | 
			
		||||
read -p "Server FQDN? " MASTODON_DOMAIN
 | 
			
		||||
read -p "Public domain? (the second part of usernames, usually the same as FQDN) " MASTODON_USERNAME_DOMAIN
 | 
			
		||||
read -p "Admin username? " MASTODON_ADMIN_USERNAME
 | 
			
		||||
read -p "Admin email? " MASTODON_ADMIN_EMAIL
 | 
			
		||||
read -rp "Server FQDN? " MASTODON_DOMAIN
 | 
			
		||||
read -rp "Public domain? (the second part of usernames, usually the same as FQDN) " MASTODON_USERNAME_DOMAIN
 | 
			
		||||
read -rp "Admin username? " MASTODON_ADMIN_USERNAME
 | 
			
		||||
read -rp "Admin email? " MASTODON_ADMIN_EMAIL
 | 
			
		||||
 | 
			
		||||
# leave our mark
 | 
			
		||||
INSTALLER_WUZ_HERE="# Generated by mastodon-installer @ $(date)"
 | 
			
		||||
@@ -44,7 +44,7 @@ if ! id -u "$MASTODON_USER" >/dev/null 2>&1; then
 | 
			
		||||
  sudo chown -R "$MASTODON_USER":"$MASTODON_USER" "$MASTODON_ROOT"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# install latest ubuntu updates
 | 
			
		||||
# install latest ubuntu updates & basic prerequisites
 | 
			
		||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
 | 
			
		||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 | 
			
		||||
  curl \
 | 
			
		||||
@@ -52,6 +52,7 @@ sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 | 
			
		||||
  gnupg \
 | 
			
		||||
  apt-transport-https \
 | 
			
		||||
  lsb-release \
 | 
			
		||||
  git \
 | 
			
		||||
  ca-certificates
 | 
			
		||||
 | 
			
		||||
# add official postgresql apt repository
 | 
			
		||||
@@ -70,39 +71,39 @@ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/nginx
 | 
			
		||||
# https://docs.joinmastodon.org/admin/install/#system-packages
 | 
			
		||||
sudo DEBIAN_FRONTEND=noninteractive apt-get update
 | 
			
		||||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 | 
			
		||||
  git-core \
 | 
			
		||||
  g++ \
 | 
			
		||||
  libpq-dev \
 | 
			
		||||
  libxml2-dev \
 | 
			
		||||
  libxslt1-dev \
 | 
			
		||||
  imagemagick \
 | 
			
		||||
  redis-server \
 | 
			
		||||
  redis-tools \
 | 
			
		||||
  postgresql \
 | 
			
		||||
  postgresql-contrib \
 | 
			
		||||
  libidn11-dev \
 | 
			
		||||
  libicu-dev \
 | 
			
		||||
  libreadline6-dev \
 | 
			
		||||
  autoconf \
 | 
			
		||||
  bison \
 | 
			
		||||
  build-essential \
 | 
			
		||||
  ffmpeg \
 | 
			
		||||
  file \
 | 
			
		||||
  g++ \
 | 
			
		||||
  gcc \
 | 
			
		||||
  imagemagick \
 | 
			
		||||
  libaugeas-dev \
 | 
			
		||||
  libffi-dev \
 | 
			
		||||
  libgdbm-dev \
 | 
			
		||||
  libicu-dev \
 | 
			
		||||
  libidn11-dev \
 | 
			
		||||
  libjemalloc-dev \
 | 
			
		||||
  libncurses5-dev \
 | 
			
		||||
  libncurses-dev \
 | 
			
		||||
  libpq-dev \
 | 
			
		||||
  libprotobuf-dev \
 | 
			
		||||
  libreadline-dev \
 | 
			
		||||
  libssl-dev \
 | 
			
		||||
  libxml2-dev \
 | 
			
		||||
  libxslt1-dev \
 | 
			
		||||
  libyaml-dev \
 | 
			
		||||
  pkg-config \
 | 
			
		||||
  protobuf-compiler \
 | 
			
		||||
  zlib1g-dev \
 | 
			
		||||
  nginx \
 | 
			
		||||
  pkg-config \
 | 
			
		||||
  postgresql \
 | 
			
		||||
  postgresql-contrib \
 | 
			
		||||
  protobuf-compiler \
 | 
			
		||||
  python3 \
 | 
			
		||||
  python3-venv \
 | 
			
		||||
  libaugeas0
 | 
			
		||||
  redis-server \
 | 
			
		||||
  redis-tools \
 | 
			
		||||
  shared-mime-info \
 | 
			
		||||
  zlib1g-dev
 | 
			
		||||
 | 
			
		||||
# install rbenv & ruby-build
 | 
			
		||||
# https://github.com/rbenv/rbenv#basic-git-checkout
 | 
			
		||||
@@ -118,21 +119,13 @@ as_mastodon git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
 | 
			
		||||
as_mastodon git clone https://github.com/mastodon/mastodon.git "$APP_ROOT" && cd "$APP_ROOT"
 | 
			
		||||
as_mastodon git config --global --add safe.directory "$APP_ROOT"
 | 
			
		||||
as_mastodon git checkout "$(as_mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
 | 
			
		||||
# uncomment to install glitch-soc fork:
 | 
			
		||||
# uncomment (and keep above lines) to install glitch-soc fork:
 | 
			
		||||
# as_mastodon git remote add glitch-soc https://github.com/glitch-soc/mastodon
 | 
			
		||||
# as_mastodon git fetch --all
 | 
			
		||||
# as_mastodon git checkout glitch-soc/main
 | 
			
		||||
 | 
			
		||||
# apply custom patches (skips errors):
 | 
			
		||||
for PATCH in "$UTILS_ROOT"/patches/*.patch; do
 | 
			
		||||
  as_mastodon git apply --reject --allow-binary-replacement "$PATCH" || true
 | 
			
		||||
done
 | 
			
		||||
# apply additional glitch-only patches if applicable:
 | 
			
		||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
 | 
			
		||||
  for PATCH in "$UTILS_ROOT"/patches/glitch/*.patch; do
 | 
			
		||||
    as_mastodon git apply --reject --allow-binary-replacement "$PATCH" || true
 | 
			
		||||
  done
 | 
			
		||||
fi
 | 
			
		||||
# apply customizations
 | 
			
		||||
. "$UTILS_ROOT"/scripts/customize.sh
 | 
			
		||||
 | 
			
		||||
# install ruby
 | 
			
		||||
as_mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install --skip-existing
 | 
			
		||||
@@ -215,7 +208,7 @@ STREAMING_CLUSTER_NUM=1
 | 
			
		||||
# STATSD_ADDR=localhost:9125" | as_mastodon tee "$APP_ROOT/.env.production" >/dev/null
 | 
			
		||||
 | 
			
		||||
# manually setup db
 | 
			
		||||
as_mastodon RAILS_ENV=production bundle exec rails db:setup
 | 
			
		||||
as_mastodon RAILS_ENV=production SAFETY_ASSURED=1 bundle exec rails db:setup
 | 
			
		||||
 | 
			
		||||
# precompile assets
 | 
			
		||||
as_mastodon RAILS_ENV=production bundle exec rails assets:precompile
 | 
			
		||||
@@ -276,10 +269,15 @@ tootctl accounts create \
 | 
			
		||||
  --role Owner \
 | 
			
		||||
  --confirmed
 | 
			
		||||
 | 
			
		||||
# set cleanup tasks to run weekly
 | 
			
		||||
# create directory for cron logdrain
 | 
			
		||||
as_mastodon mkdir -p "$LOGS_ROOT"
 | 
			
		||||
as_mastodon touch "$LOGS_ROOT"/cron.log
 | 
			
		||||
 | 
			
		||||
# set cleanup & backup tasks to run weekly
 | 
			
		||||
# https://docs.joinmastodon.org/admin/setup/#cleanup
 | 
			
		||||
(sudo crontab -l; echo -e "\n$INSTALLER_WUZ_HERE
 | 
			
		||||
@weekly  bash -c \"$UTILS_ROOT/scripts/weekly_cleanup.sh >> $LOGS_ROOT/cron.log 2>&1\"
 | 
			
		||||
@weekly  bash -c \"$UTILS_ROOT/scripts/backup.sh >> $LOGS_ROOT/cron.log 2>&1\"
 | 
			
		||||
") | sudo crontab -
 | 
			
		||||
 | 
			
		||||
echo "🎉 done! don't forget to fill in .env.production with optional credentials"
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ fi
 | 
			
		||||
# pull latest mastodon source
 | 
			
		||||
cd "$APP_ROOT"
 | 
			
		||||
as_mastodon git fetch --all
 | 
			
		||||
as_mastodon git stash push --message "pre-upgrade changes"
 | 
			
		||||
as_mastodon git stash push --include-untracked --message "pre-upgrade changes"
 | 
			
		||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
 | 
			
		||||
  # glitch-soc (uses latest commits)
 | 
			
		||||
  echo "Pulling latest glitch-soc commits..."
 | 
			
		||||
@@ -30,16 +30,8 @@ else
 | 
			
		||||
  as_mastodon git checkout "$(as_mastodon git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# apply custom patches (skips errors):
 | 
			
		||||
for PATCH in "$UTILS_ROOT"/patches/*.patch; do
 | 
			
		||||
  as_mastodon git apply --reject --allow-binary-replacement "$PATCH" || true
 | 
			
		||||
done
 | 
			
		||||
# apply additional glitch-only patches if applicable:
 | 
			
		||||
if [ -d "$APP_ROOT/app/javascript/flavours/glitch" ]; then
 | 
			
		||||
  for PATCH in "$UTILS_ROOT"/patches/glitch/*.patch; do
 | 
			
		||||
    as_mastodon git apply --reject --allow-binary-replacement "$PATCH" || true
 | 
			
		||||
  done
 | 
			
		||||
fi
 | 
			
		||||
# re-apply customizations
 | 
			
		||||
. "$UTILS_ROOT"/scripts/customize.sh
 | 
			
		||||
 | 
			
		||||
# set new ruby version
 | 
			
		||||
as_mastodon RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install --skip-existing
 | 
			
		||||
 
 | 
			
		||||
@@ -5,18 +5,15 @@
 | 
			
		||||
#   0 3 * * 0  bash -c "/home/mastodon/utils/scripts/weekly_cleanup.sh >> /home/mastodon/logs/cron.log 2>&1"
 | 
			
		||||
 | 
			
		||||
# exit when any step fails
 | 
			
		||||
set -euo pipefail
 | 
			
		||||
set -o pipefail
 | 
			
		||||
 | 
			
		||||
echo -e "\n===== weekly_cleanup.sh: started at $(date '+%Y-%m-%d %H:%M:%S') =====\n"
 | 
			
		||||
 | 
			
		||||
# initialize path
 | 
			
		||||
. "$(dirname "$(realpath "$0")")"/../init.sh
 | 
			
		||||
 | 
			
		||||
if [ ! -d "$LOGS_ROOT" ]; then
 | 
			
		||||
  as_mastodon mkdir -p "$LOGS_ROOT"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
tootctl media remove --days 7
 | 
			
		||||
tootctl media remove --days 14
 | 
			
		||||
tootctl media remove --prune-profiles --days 90
 | 
			
		||||
tootctl preview_cards remove --days 90
 | 
			
		||||
 | 
			
		||||
echo -e "\n===== weekly_cleanup.sh: finished at $(date '+%Y-%m-%d %H:%M:%S') =====\n"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user