2023-09-02 09:25:50 +02:00
#!/bin/bash
CWD=$(pwd)
PRGNAM=$(basename $CWD)
VERSION=${VERSION:-$(curl -q https://codeberg.org/forgejo/forgejo/releases.rss | grep title | head -n2 | tail -n1 | sed 's|<title>||g' | sed 's|</title>||g' | xargs)}
ARCH=${ARCH:-$(uname -m)}
2024-02-04 10:45:38 +01:00
BUILD=${BUILD:-6}
2023-09-02 09:25:50 +02:00
TAG=${TAG:-gwh}
TMP=${TMP:-/tmp/$TAG}
PKG=$TMP/pkg-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
PREFIX=/usr
2024-11-18 09:55:36 +01:00
REPOSITORY=${REPOSITORY:-/var/cache/SlackBuilds.gwh/$PRGNAM}
2023-09-02 09:25:50 +02:00
mkdir -p $REPOSITORY
2024-02-04 10:45:38 +01:00
FORGEJO_WORK_DIR=/var/lib/forgejo
2023-09-02 09:25:50 +02:00
2024-02-04 10:45:38 +01:00
# Check if the forgejo user and group exist. If not, then bail.
if [ "$(id -g forgejo 2> /dev/null)" != "817" -o "$(id -u forgejo 2> /dev/null)" != "817" ]; then
echo " You must have an 'forgejo' user and group to run this script."
echo " # groupadd -g 817 forgejo"
echo " # useradd -d /var/lib/forgejo -g forgejo -s /bin/bash -u 817 forgejo --system "
2023-09-02 09:25:50 +02:00
exit 1
fi
echo $ARCH | grep -q arm && SRC_ARCH=arm-7
echo $ARCH | grep -q 86 && SRC_ARCH=386
echo $ARCH | grep -q 64 && SRC_ARCH=amd64
mkdir -p $REPOSITORY
if [ ! -e $REPOSITORY/forgejo-${VERSION}-linux-${SRC_ARCH}.xz ]; then
wget -c https://codeberg.org/forgejo/forgejo/releases/download/${VERSION}/forgejo-${VERSION#v}-linux-${SRC_ARCH}.xz -O $REPOSITORY/forgejo-${VERSION}-linux-${SRC_ARCH}.xz
fi
xz -d $REPOSITORY/forgejo-${VERSION}-linux-${SRC_ARCH}.xz
rm -fr $PKG
mkdir -p $PKG$PREFIX/bin
2024-02-04 10:45:38 +01:00
cp $REPOSITORY/forgejo-${VERSION}-linux-${SRC_ARCH} $PKG$PREFIX/bin/forgejo
chmod +x $PKG$PREFIX/bin/forgejo
2023-09-02 09:25:50 +02:00
2024-02-04 10:45:38 +01:00
mkdir -p $PKG/etc/forgejo/
cp $CWD/app.ini $PKG/etc/forgejo/app.ini.new
chown -R forgejo:forgejo $PKG/etc/forgejo
chmod 770 $PKG/etc/forgejo
2023-09-02 09:25:50 +02:00
2024-02-04 10:45:38 +01:00
mkdir -p $PKG${FORGEJO_WORK_DIR}/{custom,data/forgejo-repositories,indexers,public,log,.ssh}
chown -R forgejo:forgejo $PKG/var/lib/forgejo
chmod 750 $PKG${FORGEJO_WORK_DIR}/{data,indexers,log}
2023-09-02 09:25:50 +02:00
2024-02-04 10:45:38 +01:00
mkdir -p $PKG/var/log/forgejo
chown -R forgejo:forgejo $PKG/var/log/forgejo
2023-09-02 09:25:50 +02:00
( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/etc/rc.d/
2023-12-11 09:11:38 +01:00
cat <<EOF > $PKG/etc/rc.d/rc.$PRGNAM
2023-09-02 09:25:50 +02:00
#!/bin/bash
#Slackware startup deamon script
# Name of Service
NAME="Forgejo Daemon"
# Command to run
2024-02-04 10:45:38 +01:00
CMD="/usr/bin/forgejo"
2023-09-02 09:25:50 +02:00
# user used to run the daemon
2024-02-04 10:45:38 +01:00
USERNAME=forgejo
2023-09-02 09:25:50 +02:00
# Option to run with deamon
2024-02-04 10:45:38 +01:00
OPTIONS=" --config /etc/forgejo/app.ini"
2023-09-02 09:25:50 +02:00
2024-02-04 11:25:03 +01:00
func_status() {
pgrep -u \$USERNAME forgejo && echo Running || echo Stopped
}
2023-09-02 09:25:50 +02:00
func_stop() {
2024-02-04 11:25:03 +01:00
pkill -u \$USERNAME forgejo
func_status
2023-09-02 09:25:50 +02:00
}
func_start() {
echo -n "Starting \$NAME ... "
2023-12-11 09:11:38 +01:00
su - \$USERNAME -c "\$CMD \$OPTIONS" &
2023-09-02 09:25:50 +02:00
sleep 2
2024-02-04 11:25:03 +01:00
func_status
2023-12-11 09:11:38 +01:00
}
2023-09-02 09:25:50 +02:00
case \$1 in
"start")
func_start
;;
"stop")
func_stop
;;
"restart")
func_stop
sleep 2
func_start
;;
2023-12-11 09:11:38 +01:00
"status")
func_status
;;
2023-09-02 09:25:50 +02:00
*)
echo "Usage; start|stop|restart"
;;
esac
EOF
2023-12-11 09:11:38 +01:00
chmod +x $PKG/etc/rc.d/rc.$PRGNAM
2023-09-02 09:25:50 +02:00
mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
2023-09-02 10:43:20 +02:00
# HOW TO EDIT THIS FILE:
2023-09-02 09:25:50 +02:00
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler--------------------------------------------------------|
$PRGNAM: $PRGNAM (A painless self-hosted Git service.)
$PRGNAM:
2023-12-11 09:11:38 +01:00
$PRGNAM: Forgejo is a self-hosted lightweight software forge.
$PRGNAM: Easy to install and low maintenance, it just does the job.
2023-09-02 09:25:50 +02:00
$PRGNAM:
2024-02-04 10:45:38 +01:00
$PRGNAM: edit /etc/forgejo/app.ini
2023-12-11 09:11:38 +01:00
$PRGNAM: see https://forgejo.org/docs/latest/admin/config-cheat-sheet/
2023-09-02 09:25:50 +02:00
$PRGNAM:
$PRGNAM:
2023-12-11 09:11:38 +01:00
$PRGNAM: https://forgejo.org/
2023-09-02 09:25:50 +02:00
$PRGNAM:
EOF
cd $PKG
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
/sbin/makepkg --linkadd y --chown n --prepend $OUTPUT/$PRGNAM-$(echo $VERSION | tr - _)-$ARCH-$BUILD$TAG.txz