slackbuilds/UNUSED/n/syncthing/syncthing.SlackBuild
2016-09-18 22:25:38 +02:00

145 lines
3.5 KiB
Bash
Executable file

#!/bin/sh -x
CWD=$(pwd)
PRGNAM=$(basename $CWD)
VERSION=${VERSION:-0.10.25}
ARCH=${ARCH:-$(uname -m)}
BUILD=${BUILD:-3}
TAG=${TAG:-cyco}
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/pkg-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
PREFIX=/usr
USERNAME=cycojesus
echo $ARCH | grep -q arm && SRC_ARCH=arm
echo $ARCH | grep -q 86 && SRC_ARCH=386
echo $ARCH | grep -q 64 && SRC_ARCH=amd64
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf ${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}
[ ! -e $CWD/${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}.tar.gz ] && wget -c "https://github.com/${PRGNAM}/${PRGNAM}/releases/download/v${VERSION}/${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}.tar.gz" -O $CWD/${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}.tar.gz
tar xvf $CWD/${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}.tar.gz
cd ${PRGNAM}-linux-${SRC_ARCH}-v${VERSION}
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
-exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 \
-o -perm 400 \) -exec chmod 644 {} \;
mkdir -p $PKG$PREFIX/bin/
mv ${PRGNAM} $PKG$PREFIX/bin/
chown $USERNAME $PKG$PREFIX/bin/${PRGNAM}
( 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/usr/doc/$PRGNAM-$VERSION
cp -a *.txt etc/ $PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKG/etc/rc.d/
cat <<EOF > $PKG/etc/rc.d/rc.$PRGNAM
#!/bin/bash
#Slackware startup deamon script
# Name of Service
NAME="Syncthing Daemon"
# Command to run
CMD="/usr/bin/syncthing"
# Process name of daemon, for killing it.
PROCESSNAME=\$CMD
# The name of the user that should run Transmission.
# It's RECOMENDED to run Transmission in it's own user,
# by default, this is set to 'transmission'.
# For the sake of security you shouldn't set a password
# on this user
USERNAME="$USERNAME"
# Option to run with deamon
OPTIONS=" -home=/home/\$USERNAME/ "
func_stop() {
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 "\$CMD \$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 (Open Source Continuous File Synchronization)
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM:
$PRGNAM: http://discourse.syncthing.net/
$PRGNAM:
EOF
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.txz