Laminar/run/mastodon/workspace/setup_mastodon.sh

48 lines
2 KiB
Bash

#!/usr/bin/env bash
set -euox pipefail
cd /home/mastodon
git clone https://github.com/mastodon/mastodon.git live && cd live
git checkout "$(git tag -l | grep '^v[0-9.]*$' | sort -V | tail -n 1)"
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
{
# shellcheck disable=SC2016
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'
# shellcheck disable=SC2016
echo 'eval "$(rbenv init -)"'
# shellcheck disable=SC2016
echo 'export RAILS_ENV=production'
} | tee -a ~/.bashrc ~/.profile
# shellcheck disable=SC1090
source ~/.profile
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install
bundle config deployment 'true'
bundle config without 'development test'
bundle install -j"$(getconf _NPROCESSORS_ONLN)"
yarn install
# Next steps are manual when container is started for the first time
# https://docs.joinmastodon.org/admin/install/#generating-a-configuration
# If upgrading from a previous image, rough notes until automated
# cp /home/mastodon/live/.env.production /home/mastodon/backup/
# sudo -u postgres pg_dump -d mastodon_production -F c | tee /home/mastodon/backup/mastodon_production.sql > /dev/null
# cp /etc/nginx/sites-available/mastodon /home/mastodon/backup/nginx.mastodon
# tofu apply
# sudo -u postgres createdb mastodon_production
# cat /home/mastodon/backup/mastodon_production.sql | sudo -u postgres pg_restore -d mastodon_production -F c
# cp /home/mastodon/backup/nginx.mastodon /etc/nginx/sites-available/mastodon
# ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
# rm /etc/nginx/sites-enabled/default
# chmod o+x /home/mastodon
# systemctl restart nginx
# sudo -u mastodon -i
# cp backup/.env.production live/
# cd live
# bin/rails assets:precompile
# cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable --now mastodon-web mastodon-sidekiq mastodon-streaming
# sudo -u mastodon -i
# cd live
# bin/tootctl feeds build