summaryrefslogtreecommitdiffstats
path: root/games/tetrinetx/tetrinetx.SlackBuild
blob: 9e78ab78575f3218b11a2e5d120d9f62f1b934ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash

# Slackware build script for tetrinetx

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# The _15 in VERSION is the Debian patchlevel. They're currently
# the only ones maintaining this at all.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=tetrinetx
VERSION=${VERSION:-1.13.16+qirc_1.40c_15}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

set -e

SRCVER="$( echo $VERSION | cut -d_ -f1-2 | tr _ - )"
DEBVER="$( echo $VERSION | cut -d_ -f3 )"
DEBSRCVER="$( echo $VERSION | cut -d+ -f1 )"

# We get two possible filenames for the tarball depending on what
# exactly was used to download it.
TARBALL="$CWD/$PRGNAM-$SRCVER.tar.gz"
if [ ! -e "$TARBALL" ]; then
  TARBALL="$( echo "$TARBALL" | sed 's,+,%2B,g' )"
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$SRCVER
tar xvf $TARBALL
cd $PRGNAM-$SRCVER
tar xvf $CWD/${PRGNAM}_${DEBSRCVER}-${DEBVER}.debian.tar.xz
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

# Incorporate all of Debian's changes. This includes IPv6 support,
# and putting the config files in /etc/$PRGNAM and log file in /var.
patch -p1 < debian/patches/debian-changes

# Debian's patch breaks IPv4 support, fix.
patch -p1 < $CWD/restore_ipv4.diff

if [ "${IPV4:-no}" = "yes" ]; then
  IPVER=4
else
  SLKCFLAGS+=" -DUSE_IPV6"
  IPVER=6
fi

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION

# Easier to just do this, than to munge the compile script into doing
# the right thing.
${CC:-gcc} $SLKCFLAGS -o $PRGNAM src/main.c -ladns
mkdir -p $PKG/usr/games $PKG/usr/man/man6 $PKG/etc/$PRGNAM $PKGDOC
install -s -m0755 $PRGNAM $PKG/usr/games
for i in bin/game*.{conf,secure,{p,}motd}; do
  cp -a $i $PKG/etc/$PRGNAM/$( basename $i ).new
done
cp -a bin/game.*.example $PKG/etc/$PRGNAM

# The Debian man page is useless, I wrote a better one.
gzip -9c < $CWD/$PRGNAM.6 > $PKG/usr/man/man6/$PRGNAM.6.gz

# Log rotation looks broken: it doesn't restart the daemon after
# rotating the log. tetrinetx doesn't allow a SIGHUP to reopen the
# log, meaning we'd have to call the rc script to restart it. And if
# we do, we kill any games in progress. There's nothing like apache's
# "graceful" restart. Leave it out, and let the user deal with it (or
# not; it would take a long time for the log to fill a modern drive).
#mkdir -p $PKG/etc/logrotate.d
#cp -a debian/logrotate $PKG/etc/logrotate.d/$PRGNAM

# Bare-bones init script written by SlackBuild author.
mkdir -p $PKG/etc/rc.d
install -m0755 -oroot -groot $CWD/rc.$PRGNAM $PKG/etc/rc.d/rc.$PRGNAM.new

# These dirs have to be writable by the user the daemon runs as.
dirs="$PKG/var/games/$PRGNAM $PKG/var/log/$PRGNAM $PKG/var/run/$PRGNAM"
mkdir -p $dirs
chown games:games $dirs

mkdir -p $PKGDOC
cp -a AUTHORS COPYING ChangeLog README* $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
sed "s,@IPVER@,$IPVER," < $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE