Laminar/cfg/jobs/mastodon.run

71 lines
1.8 KiB
Bash
Executable file

#!/bin/env bash
# Upstream doc: https://docs.joinmastodon.org/admin/install/
set -euxo pipefail
IMAGE="ubuntu/24.04"
DIST="${IMAGE%%/*}"
VER="${IMAGE#*/}"
VER="${VER%/*}"
VER="${VER//./-}"
UPSTREAM_VER="4.3.1"
UPSTREAM_VER_DASH="${UPSTREAM_VER//./-}"
UPSTREAM_NAME="mastodon"
SERIAL="1benoitjpnet"
CNAME="$UPSTREAM_NAME-$UPSTREAM_VER_DASH-$SERIAL-$DIST-$VER"
ALIAS="$UPSTREAM_NAME-$UPSTREAM_VER-$SERIAL"
cd "$WORKSPACE"
incus launch images:$IMAGE "$CNAME" --quiet
wait_network $CNAME
# Mastodon
incus exec "$CNAME" -- bash -c '
apt update && \
apt upgrade -y && \
apt install -y --no-install-recommends \
curl \
wget \
gnupg \
apt-transport-https \
lsb-release \
ca-certificates
'
incus file push "$WORKSPACE"/{setup.sh,setup_mastodon.sh,postgresql.conf} \
"$CNAME"/tmp/
incus exec "$CNAME" -- bash /tmp/setup.sh
incus exec "$CNAME" \
--user 1001 \
--env HOME=/home/mastodon \
--force-noninteractive \
-- bash /tmp/setup_mastodon.sh
# Clean
incus exec "$CNAME" -- \
rm -rf \
/etc/machine-id \
/var/cache/apt \
/var/log/journal
# Publish
incus stop "$CNAME"
incus config metadata show "$CNAME" > "$ARCHIVE"/metadata.yaml
# Get the current Unix timestamp
current_timestamp=$(date +%s)
# Calculate expiry date as current timestamp + 1 week (604800 seconds)
expiry_date=$((current_timestamp + 604800))
# Update metadata values
sed -i \
-e "s/creation_date: .*/creation_date: $current_timestamp/" \
-e "s/expiry_date: .*/expiry_date: $expiry_date/" \
-e "s#description: .*#description: $UPSTREAM_NAME v$UPSTREAM_VER on $IMAGE release $SERIAL#" \
-e "s/name: .*/name: $CNAME/" \
-e "s/serial: .*/serial: $SERIAL/" \
"$ARCHIVE"/metadata.yaml
incus config metadata edit "$CNAME" < "$ARCHIVE"/metadata.yaml
incus publish "$CNAME" \
--alias $ALIAS \
--public \
--quiet
incus rm "$CNAME"