forked from Unvanquished/Unvanquished
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tarball.sh
executable file
·117 lines (101 loc) · 2.71 KB
/
tarball.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
#! /bin/sh
set -e
cd "$(dirname "$0")"
PACKAGE_NAME="$(sed -e '/^#define PRODUCT_NAME_LOWER/! d; s/[^\"]*\"//; s/\".*$//; s/[^0-9a-z.]/-/g' src/engine/qcommon/q_shared.h)"
PACKAGE_VERSION="$(sed -e '/^#define PRODUCT_VERSION/! d; s/[^\"]*\"//; s/\".*$//; s/[^0-9a-z.]/-/g' src/engine/qcommon/q_shared.h)"
PACKAGE="$PACKAGE_NAME-$PACKAGE_VERSION"
STRIP_SOURCES=
STRIP_BINARIES=
STRIP_ASSETS=
STRIP_DEAD=
FORMAT=tar.xz
while test $# != 0; do
case "$1" in
strip-sources)
STRIP_SOURCES=1
;;
strip-binaries)
STRIP_BINARIES=1
;;
strip-assets)
STRIP_ASSETS=1
;;
strip-unused)
STRIP_UNUSED=1
;;
strip)
STRIP_SOURCES=1
STRIP_BINARIES=1
STRIP_ASSETS=1
STRIP_DEAD=1
;;
7z|zip|tar.gz|tar.bz2|tar.xz)
FORMAT="$1"
;;
-\?|-h|--help)
echo "$(basename "$0") [options]"
echo ' builds an optionally stripped-down source archive file'
echo 'Source control options (at least one):'
echo ' strip-sources - remove library code copies'
echo ' strip-binaries - remove DLLs etc.'
echo ' strip-assets - remove various images etc. found in the pak files'
echo ' strip-unused - remove some "dead" code'
echo ' strip - all of the above'
echo 'Archive file formats (select one):'
echo ' 7z zip tar.gz tar.bz2 tar.xz'
echo 'Other options:'
exit 0
;;
*)
echo 'Unrecognised argument "'"$1"'"'
exit 2
;;
esac
shift
done
cleanup()
{
rm -rf "$PACKAGE"
}
trap cleanup EXIT
if test ! -d .git || test "$(git clean -ndf | grep -v '\.#'; git status -s)" != ''; then
echo 'I need a clean tree!'
exit 2
fi
# copy the files
mkdir $PACKAGE
cp -al $(ls -1 | grep -v $PACKAGE) $PACKAGE
rm $PACKAGE/tarball.sh
# kill backup files etc.
find $PACKAGE \( -name '.*' -o -name '*~' -o -name '*.orig' -o -name '*.rej' \) -delete
# purge all but *required* libraries
# nothing to do here at present
#test "$STRIP_SOURCES" = '' ||
# rm -rf $(ls -1d $PACKAGE/src/libs/* | grep -v '/\(...\)')
# purge binaries
test "$STRIP_BINARIES" = '' || {
rm -rf $PACKAGE/bin
find $PACKAGE \( -name '*.dll' -o -name '*.lib' \) -delete
}
# purge (most) assets
test "$STRIP_ASSETS" = '' || {
rm -rf $PACKAGE/main/[!ut]* $PACKAGE/main/ui/*[!h] $PACKAGE/main/translations/game
}
# remove some disabled-by-default code
test "$STRIP_DEAD" = '' || {
: # nothing to do?
}
# kill empty directories
find $PACKAGE -type d -print0 | sort -zr | xargs -0r rmdir --ignore-fail-on-non-empty
# now build the archive
case "$FORMAT" in
7z)
7z a -r $PACKAGE.7z $PACKAGE
;;
zip)
zip -9r $PACKAGE.zip $PACKAGE
;;
tar.*)
tar cvaf $PACKAGE.$FORMAT $PACKAGE
;;
esac