#!/bin/bash CWD=$(pwd) # Check if the minecraft user and group exist. If not, then bail. if [ "$(id -g minecraft 2> /dev/null)" != "987" -o "$(id -u minecraft 2> /dev/null)" != "987" ]; then echo " You must have an 'minecraft' user and group to run this script." echo " # groupadd -g 987 minecraft" echo " # useradd -d /opt/$PRGNAM -g minecraft -s /bin/bash -u 987 minecraft --system " exit 1 fi PRGNAM=$(basename $CWD) VERSION=${VERSION:-$(curl https://www.minecraft.net/en-us/download/server | grep "minecraft_server.*\.jar" -o | grep -o "[0-9][0-9.]*[0-9]" | head -n1)} ARCH=${ARCH:-$(uname -m)} BUILD=${BUILD:-1} 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 [ ! -e $REPOSITORY/${PRGNAM}-${VERSION}.jar ] && wget -c $(curl https://www.minecraft.net/en-us/download/server | grep -o "https.*server\.jar") -O $REPOSITORY/${PRGNAM}-${VERSION}.jar rm -fr $PKG mkdir -p $PKG/opt/$PRGNAM cp $REPOSITORY/${PRGNAM}-${VERSION}.jar $PKG/opt/$PRGNAM/$PRGNAM.jar cat < $PKG/opt/$PRGNAM/start.sh #!/bin/bash java -Xms1G -Xmx1G -jar /opt/$PRGNAM/$PRGNAM.jar nogui EOF chmod +x $PKG/opt/$PRGNAM/start.sh chown -R minecraft:minecraft $PKG/opt/$PRGNAM/ mkdir -p $PKG/etc/rc.d/ cat < $PKG/etc/rc.d/rc.$PRGNAM #!/bin/bash #Slackware startup deamon script # Name of Service NAME="Minecraft Daemon" # user used to run the daemon USERNAME=minecraft PIDFILE=/var/run/minecraft.pid func_stop() { [ -e \$PIDFILE ] && kill \$(cat \$PIDFILE) && rm \$PIDFILE } func_start() { echo -n "Starting \$NAME ... " su - \$USERNAME -c /opt/$PRGNAM/start.sh & echo $! > \$PIDFILE } 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 < $PKG/install/doinst.sh #!/bin/bash [ ! -e /opt/$PRGNAM/eula.txt ] && /etc/rc.d/rc.$PRGNAM start EOF cat < $PKG/install/slack-desc |-----handy-ruler--------------------------------------------------------| $PRGNAM: $PRGNAM (Proprietary Minecraft Server) $PRGNAM: $PRGNAM: $PRGNAM: $PRGNAM: $PRGNAM: $PRGNAM: https://www.minecraft.net/en-us/download/server/ $PRGNAM: $PRGNAM: $PRGNAM: $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