slackbuilds/n/forgejo-bin/SlackBuild
2024-02-04 11:25:03 +01:00

153 lines
4.1 KiB
Bash
Executable file

#!/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)}
BUILD=${BUILD:-6}
TAG=${TAG:-gwh}
TMP=${TMP:-/tmp/$TAG}
PKG=$TMP/pkg-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
PREFIX=/usr
REPOSITORY=${REPOSITORY:-/home/installs/SlackBuilds/_repositories/$PRGNAM}
mkdir -p $REPOSITORY
FORGEJO_WORK_DIR=/var/lib/forgejo
# 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 "
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
cp $REPOSITORY/forgejo-${VERSION}-linux-${SRC_ARCH} $PKG$PREFIX/bin/forgejo
chmod +x $PKG$PREFIX/bin/forgejo
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
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}
mkdir -p $PKG/var/log/forgejo
chown -R forgejo:forgejo $PKG/var/log/forgejo
( 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/
cat <<EOF > $PKG/etc/rc.d/rc.$PRGNAM
#!/bin/bash
#Slackware startup deamon script
# Name of Service
NAME="Forgejo Daemon"
# Command to run
CMD="/usr/bin/forgejo"
# user used to run the daemon
USERNAME=forgejo
# Option to run with deamon
OPTIONS=" --config /etc/forgejo/app.ini"
func_status() {
pgrep -u \$USERNAME forgejo && echo Running || echo Stopped
}
func_stop() {
pkill -u \$USERNAME forgejo
func_status
}
func_start() {
echo -n "Starting \$NAME ... "
su - \$USERNAME -c "\$CMD \$OPTIONS" &
sleep 2
func_status
}
case \$1 in
"start")
func_start
;;
"stop")
func_stop
;;
"restart")
func_stop
sleep 2
func_start
;;
"status")
func_status
;;
*)
echo "Usage; start|stop|restart"
;;
esac
EOF
chmod +x $PKG/etc/rc.d/rc.$PRGNAM
mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# 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:
$PRGNAM: Forgejo is a self-hosted lightweight software forge.
$PRGNAM: Easy to install and low maintenance, it just does the job.
$PRGNAM:
$PRGNAM: edit /etc/forgejo/app.ini
$PRGNAM: see https://forgejo.org/docs/latest/admin/config-cheat-sheet/
$PRGNAM:
$PRGNAM:
$PRGNAM: https://forgejo.org/
$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