160 lines
4.3 KiB
Bash
Executable file
160 lines
4.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
CWD=$(pwd)
|
|
|
|
PRGNAM=$(basename $CWD)
|
|
VERSION=${VERSION:-$(curl -s https://api.github.com/repos/go-${PRGNAM}/${PRGNAM}/releases/latest | grep tag_name | grep -o "[0-9.]*")}
|
|
ARCH=${ARCH:-$(uname -m)}
|
|
BUILD=${BUILD:-2}
|
|
TAG=${TAG:-gwh}
|
|
|
|
TMP=${TMP:-/tmp/$TAG}
|
|
PKG=$TMP/pkg-$PRGNAM
|
|
OUTPUT=${OUTPUT:-/tmp}
|
|
PREFIX=/usr
|
|
|
|
REPOSITORY=${REPOSITORY:-/var/cache/SlackBuilds.gwh/$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
|
|
|
|
[ ! -e $REPOSITORY/gitea-${VERSION}-linux-${SRC_ARCH}.xz ] && wget -c https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-${SRC_ARCH}.xz -O $REPOSITORY/gitea-${VERSION}-linux-${SRC_ARCH}.xz
|
|
xz -d $REPOSITORY/gitea-${VERSION}-linux-${SRC_ARCH}.xz
|
|
|
|
rm -fr $PKG
|
|
|
|
mkdir -p $PKG$PREFIX/bin
|
|
cp $REPOSITORY/gitea-${VERSION}-linux-${SRC_ARCH} $PKG$PREFIX/bin/${PRGNAM}
|
|
chmod +x $PKG$PREFIX/bin/${PRGNAM}
|
|
|
|
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="Gitea 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
|
|
|
|
GITEA_WORK_DIR=$GITEA_WORK_DIR
|
|
|
|
func_stop() {
|
|
[ -e \$PIDFILE ] && kill \$(cat \$PIDFILE)
|
|
# if [ "\$(ps aux | grep \$PROCESSNAME | grep -v grep)" ]; then
|
|
# echo -n "Stopping \$NAME ... "
|
|
# killall \$PROCESSNAME
|
|
# sleep 2
|
|
# fi
|
|
|
|
if [ ! "\$(ps aux | grep \$PROCESSNAME | grep -v grep)" ]; then
|
|
echo "Done!"
|
|
else
|
|
echo "Error!"
|
|
fi
|
|
}
|
|
|
|
func_start() {
|
|
echo -n "Starting \$NAME ... "
|
|
su - \$USERNAME -c "GITEA_WORK_DIR=$GITEA_WORK_DIR \$CMD --pid \$PIDFILE \$OPTIONS" &
|
|
sleep 2
|
|
|
|
if [ "\$(ps aux | grep \$PROCESSNAME | grep -v grep)" ]; then
|
|
echo "Done!"
|
|
else
|
|
echo "Error!"
|
|
fi
|
|
}
|
|
|
|
|
|
case \$1 in
|
|
"start")
|
|
func_start
|
|
;;
|
|
|
|
"stop")
|
|
func_stop
|
|
;;
|
|
|
|
"restart")
|
|
func_stop
|
|
sleep 2
|
|
func_start
|
|
;;
|
|
*)
|
|
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: Gitea is a community managed fork of Gogs, lightweight code hosting
|
|
$PRGNAM: solution written in Go and published under the MIT license.
|
|
$PRGNAM:
|
|
$PRGNAM: edit /etc/gitea/app.ini
|
|
$PRGNAM: see https://docs.gitea.io/en-us/config-cheat-sheet/
|
|
$PRGNAM:
|
|
$PRGNAM:
|
|
$PRGNAM: https://gitea.io/
|
|
$PRGNAM:
|
|
EOF
|
|
|
|
cd $PKG
|
|
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
|
|
|
|
/sbin/makepkg --linkadd y --chown n --prepend $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.txz
|