50a4c2b4ec
Signed-off-by: Gwenhael Le Moine <gwenhael.le.moine@gmail.com>
172 lines
4.4 KiB
Bash
Executable file
172 lines
4.4 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:-5}
|
|
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
|
|
|
|
GITEA_WORK_DIR=/var/lib/gitea
|
|
|
|
# Check if the gitea user and group exist. If not, then bail.
|
|
if [ "$(id -g gitea 2> /dev/null)" != "817" -o "$(id -u gitea 2> /dev/null)" != "817" ]; then
|
|
echo " You must have an 'gitea' user and group to run this script."
|
|
echo " # groupadd -g 817 gitea"
|
|
echo " # useradd -d /var/lib/gitea -g gitea -s /bin/bash -u 817 gitea --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/gitea
|
|
chmod +x $PKG$PREFIX/bin/gitea
|
|
|
|
mkdir -p $PKG/etc/gitea/
|
|
cp $CWD/app.ini $PKG/etc/gitea/app.ini.new
|
|
chown -R gitea:gitea $PKG/etc/gitea
|
|
chmod 770 $PKG/etc/gitea
|
|
|
|
mkdir -p $PKG${GITEA_WORK_DIR}/{custom,data/gitea-repositories,indexers,public,log,.ssh}
|
|
chown -R gitea:gitea $PKG/var/lib/gitea
|
|
chmod 750 $PKG${GITEA_WORK_DIR}/{data,indexers,log}
|
|
|
|
mkdir -p $PKG/var/log/gitea
|
|
chown -R gitea:gitea $PKG/var/log/gitea
|
|
|
|
( 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/gitea"
|
|
|
|
# user used to run the daemon
|
|
USERNAME=gitea
|
|
|
|
# Process name of daemon, for killing it.
|
|
PROCESSNAME=\$CMD
|
|
|
|
# Option to run with deamon
|
|
OPTIONS=" --config /etc/gitea/app.ini"
|
|
|
|
PIDFILE=/var/lib/gitea/gitea.pid
|
|
|
|
func_stop() {
|
|
[ -e \$PIDFILE ] && kill \$(cat \$PIDFILE)
|
|
rm \$PIDFILE
|
|
|
|
if [ ! "\$(pgrep gitea)" ]; then
|
|
echo "Error!"
|
|
else
|
|
echo "Stopped!"
|
|
fi
|
|
}
|
|
|
|
func_start() {
|
|
echo -n "Starting \$NAME ... "
|
|
su - \$USERNAME -c "\$CMD \$OPTIONS" &
|
|
echo \$\$ > \$PIDFILE
|
|
|
|
sleep 2
|
|
|
|
if [ "\$(pgrep gitea)" ]; then
|
|
echo "Started!"
|
|
else
|
|
echo "Error!"
|
|
fi
|
|
}
|
|
|
|
func_status() {
|
|
if [ "\$(pgrep gitea)" ]; then
|
|
echo "Running!"
|
|
else
|
|
echo "NOT running!"
|
|
fi
|
|
}
|
|
|
|
|
|
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/gitea/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
|