71 lines
2.4 KiB
Bash
Executable file
71 lines
2.4 KiB
Bash
Executable file
#!/bin/env bash
|
|
# Upstream doc: https://forgejo.org/docs/latest/admin/installation-binary/
|
|
set -euxo pipefail
|
|
|
|
IMAGE="ubuntu/24.04"
|
|
DIST="${IMAGE%%/*}"
|
|
VER="${IMAGE#*/}"
|
|
VER="${VER%/*}"
|
|
VER="${VER//./-}"
|
|
UPSTREAM_VER="9.0.0"
|
|
UPSTREAM_VER_DASH="${UPSTREAM_VER//./-}"
|
|
UPSTREAM_NAME="forgejo"
|
|
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 for network
|
|
timeout 30 bash -c "until incus exec $CNAME -- ping -c1 google.com &>/dev/null; do sleep 1; done"
|
|
|
|
# Forgejo
|
|
incus exec $CNAME -- mkdir /etc/esh
|
|
incus exec $CNAME -- apt update
|
|
incus exec $CNAME -- apt upgrade -y
|
|
incus exec $CNAME -- apt install -y --no-install-recommends wget git git-lfs redis-server
|
|
incus exec $CNAME -- \
|
|
wget --quiet \
|
|
https://codeberg.org/forgejo/forgejo/releases/download/v${UPSTREAM_VER}/forgejo-${UPSTREAM_VER}-linux-amd64 \
|
|
-O /usr/local/bin/forgejo
|
|
incus exec $CNAME -- chmod +x /usr/local/bin/forgejo
|
|
incus exec $CNAME -- adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
|
|
incus exec $CNAME -- mkdir /var/lib/forgejo
|
|
incus exec $CNAME -- chown git:git /var/lib/forgejo
|
|
incus exec $CNAME -- chmod 750 /var/lib/forgejo
|
|
incus exec $CNAME -- mkdir /etc/forgejo
|
|
incus exec $CNAME -- chown root:git /etc/forgejo
|
|
incus exec $CNAME -- chmod 770 /etc/forgejo
|
|
incus exec $CNAME -- \
|
|
wget --quiet \
|
|
-O /etc/systemd/system/forgejo.service \
|
|
https://codeberg.org/forgejo/forgejo/raw/branch/forgejo/contrib/systemd/forgejo.service
|
|
#incus file push setup.sh $CNAME/usr/local/bin/
|
|
|
|
# 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
|