Laminar/cfg/jobs/mastodon.run

73 lines
1.9 KiB
Text
Raw Normal View History

2024-10-10 22:36:29 +09:00
#!/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.0"
UPSTREAM_VER_DASH="${UPSTREAM_VER//./-}"
UPSTREAM_NAME="mastodon"
2024-10-11 18:58:28 +09:00
SERIAL="2benoitjpnet"
2024-10-10 22:36:29 +09:00
CNAME="$UPSTREAM_NAME-$UPSTREAM_VER_DASH-$SERIAL-$DIST-$VER"
ALIAS="$UPSTREAM_NAME-$UPSTREAM_VER-$SERIAL"
2024-10-11 18:38:45 +09:00
cd "$WORKSPACE"
incus launch images:$IMAGE "$CNAME" --quiet
2024-10-10 22:36:29 +09:00
# Wait for network
2024-10-11 18:38:45 +09:00
timeout 30 bash -c "until incus exec $CNAME -- ping -c1 google.com &>/dev/null; do sleep 1; done"
2024-10-10 22:36:29 +09:00
# Mastodon
2024-10-11 18:38:45 +09:00
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
2024-10-10 22:36:29 +09:00
'
2024-10-11 18:58:28 +09:00
incus file push "$WORKSPACE"/{setup.sh,setup_mastodon.sh,postgresql.conf} \
"$CNAME"/tmp/
2024-10-11 18:38:45 +09:00
incus exec "$CNAME" -- bash /tmp/setup.sh
incus exec "$CNAME" \
--user 1001 \
--env HOME=/home/mastodon \
--force-noninteractive \
-- bash /tmp/setup_mastodon.sh
2024-10-10 22:36:29 +09:00
# Clean
2024-10-11 18:38:45 +09:00
incus exec "$CNAME" -- \
2024-10-10 22:36:29 +09:00
rm -rf \
2024-10-11 18:38:45 +09:00
/etc/machine-id \
/var/cache/apt \
/var/log/journal
2024-10-10 22:36:29 +09:00
# Publish
2024-10-11 18:38:45 +09:00
incus stop "$CNAME"
incus config metadata show "$CNAME" > "$ARCHIVE"/metadata.yaml
2024-10-10 22:36:29 +09:00
# Get the current Unix timestamp
current_timestamp=$(date +%s)
# Calculate expiry date as current timestamp + 1 week (604800 seconds)
2024-10-11 18:38:45 +09:00
expiry_date=$((current_timestamp + 604800))
2024-10-10 22:36:29 +09:00
# 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/" \
2024-10-11 18:38:45 +09:00
"$ARCHIVE"/metadata.yaml
2024-10-10 22:36:29 +09:00
2024-10-11 18:38:45 +09:00
incus config metadata edit "$CNAME" < "$ARCHIVE"/metadata.yaml
incus publish "$CNAME" \
--alias $ALIAS \
--public \
--quiet
incus rm "$CNAME"