/build-mastodon-dev.sh
#!/bin/sh

. lib.sh
. common.opts

load_opts "$1"

PACKAGES="$(cat pkglist-mastodon.txt | tr '[:space:]' ' ')"

set -e
set -x

JAILNAME=$MASTODON_JAILNAME
ADDR=$MASTODON_ADDR

bastille create $JAILNAME $FREEBSD_RELEASE $ADDR

IPV6_ADDR=fdcb:dbd4:3a2f:$(echo $ADDR | cut -d. -f3)::$(echo $ADDR | cut -d. -f4)
bastille config $JAILNAME set ip6.addr $IPV6_ADDR
bastille restart $JAILNAME

bastille pkg $JAILNAME install -y $PACKAGES
bastille cmd $JAILNAME pw user add mastodon -m -h -
jexec -U mastodon $JAILNAME /bin/sh <<SCRIPT
set -e
set -x

cd
git clone $MASTODON_REPO live
cd ~/live
git checkout -b prod $MASTODON_VERSION
bundle config deployment 'true'
bundle install
yarn install --pure-lockfile
SCRIPT
bastille cmd $JAILNAME gem install foreman --no-document

sed -e "s/\$DB_HOST/$POSTGRES_ADDR/" \
    -e "s/\$REDIS_HOST/$REDIS_ADDR/" \
    -e "s/\$HOSTNAME/$HOSTNAME/" \
    mastodon/env.production.tmpl > env
bastille cp $JAILNAME env /home/mastodon/live/.env
rm env