forked from Unvanquished/Unvanquished
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basepak.sh
executable file
·127 lines (105 loc) · 3.1 KB
/
basepak.sh
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
#! /bin/bash
#
# Creates pak.pre.pk3 (containing assets and client translations)
# and vms.pre.pk3 (containing QVMs and game translations)
#
# If there is a directory named 'pak' at the top of the source tree,
# its content is included in pak.pre.pk3.
set -e
shopt -s nullglob
PAKNAME=test
PAKVERSION=0
OLDVERSION=
while :; do
case "$1" in
-h|--help)
echo "Usage: $0 [-n|--name PAK VERSION] [-d|--depends OLDVERSION] TAG [BUILD_DIR]"
echo ' PAK is the base name for the .pk3 (defaults to "test")'
echo ' VERSION is the version of the .pk3 (defaults to 0)'
echo ' OLDVERSION is the previous version of the .pk3, used for dependency info'
echo ' TAG identifies a git commit; it should normally be a release tag'
echo ' BUILD_DIR is the build directory, relative to the current'
exit 0
;;
-n|--name)
PAKNAME="$2"
PAKVERSION="$3"
# note: doesn't test for consecutive punctuation
if test -z "$PAKNAME" -o -z "$PAKVERSION" -o \
-z "$(echo "$PAKNAME" | LANG=C grep -e '^[[:alpha:]][-+~./[:alnum:]]*$')" -o \
-n "$(echo "$PAKVERSION" | LANG=C tr -d -- '-+~.[:alnum:]')"; then
echo 'you need a valid pak name and version' >&2
exit 2
fi
shift 3
;;
-d|--depends)
OLDVERSION="$2"
if test -n "$OLDVERSION" -a \
-n "$(echo "$OLDVERSION" | LANG=C tr -d -- '-+~.[:alnum:]')"; then
echo 'you need a valid pak name and version' >&2
exit 2
fi
shift 2
;;
-*)
echo "unrecognised option '$1'" >&2
exit 2
;;
*)
break
;;
esac
done
PAKBASE="$1"
shift || :
BUILDDIR="${1:-.}"
shift || :
if test -z "$PAKBASE"; then
echo 'the current release tag is needed' >&2
exit 2
fi
PAKFILENAME="$(basename "$PAKNAME")_$PAKVERSION.pk3"
cd "$(dirname "$0")"
BASEDIR="$PWD"
if test -n "$BUILDDIR" && test ! -d "$BASEDIR/$BUILDDIR"; then
echo "directory '$BUILDDIR' not found" >&2
exit 2
fi
rm -f -- "$PAKFILENAME"
dozip()
{
test $# == 0 || zip -9 "$BASEDIR/$PAKFILENAME" "$@"
}
echo '[33mGathering resource files[m'
cd "$BASEDIR/main"
if test -n "$(git diff --name-only "$PAKBASE" . | sed -e 's%main/%%' | grep -v '^translation/[^c]')"; then
dozip $(git diff --name-only "$PAKBASE" . | sed -e 's%main/%%' | grep -v '^translation/[^c]')
fi
if test -n "$OLDVERSION"; then
mkdir -p "$BASEDIR/pak"
rm -f "$BASEDIR/pak/DEPS"
echo "$PAKNAME $OLDVERSION" >"$BASEDIR/pak/DEPS"
fi
if test -d "$BASEDIR/pak"; then
cd "$BASEDIR/pak"
dozip $(find -type f -a ! -name '*~' | sort)
cd - >/dev/null
fi
echo '[33mGathering VM code[m'
cd "$BASEDIR/$BUILDDIR"
dozip sgame-*-stripped.nexe cgame-*-stripped.nexe
echo '[33mRenaming *-stripped.nexe[m'
zipnote "$BASEDIR/$PAKFILENAME" |
sed -e '/-stripped\.nexe$/ { p; s/^@ /@=/; s/-stripped\.nexe$/.nexe/; }' |
zipnote -w "$BASEDIR/$PAKFILENAME"
cd "$BASEDIR"
if (which advzip && test -f "$PAKFILENAME") &>/dev/null; then
echo '[33mOptimising[m'
advzip -z4 "$PAKFILENAME"
fi
if test -f "$PAKFILENAME"; then
echo '[32mDone![m'
else
echo '[32mNothing to do![m'
fi