File: game-data-packager-shared

package info (click to toggle)
game-data-packager 22
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 120 kB
  • ctags: 11
  • sloc: sh: 102; makefile: 55
file content (188 lines) | stat: -rw-r--r-- 3,659 bytes parent folder | download
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
supported() {
	echo "the following games are supported:"
	echo
	printf "\t    name\tdescription\n"
	printf "\t    ----\t-----------\n"

	find $SUPPORTED -type f | grep -v '\.svn' | grep -v 'swp$' | sort |
	while read file; do
		. $file
		printf "\t%8s\t%s\n" "$SHORTNAME" "$LONGNAME"
	done
}
options() {
	echo "game-data-packager arguments:"
	echo "        -n            not do not install the generated package (requires -d)"
	echo "        -d OUTDIR     write the generated .deb(s) to OUTDIR"
}

usage() {
	echo "usage:"
	printf "\tgame-data-packager [game-data-packager-args] game [game-args]\n"
	echo
	options
	echo
	supported
	echo
	echo "run game-data-packager [game] to see game-specific arguments."
	echo
}

set +u
if [ -n "$DEBUG" ]; then
debug() {
		echo "DEBUG: $*" >&2
}
else
debug() { :; }
fi
set -u

warn() {
	echo "WARNING: $*" >&2
}

verify_md5sum() {
	FILE=$1
	GOODSUM=$2
	SUM=`md5sum $FILE|cut -d' ' -f1`
	if [ "$SUM" != "$GOODSUM" ]; then
		echo "error: $FILE's md5 checksum is unknown." >&2
		echo "perhaps it is corrupted?" >&2
		echo "quitting." >&2
		exit 1
	fi
}

verify_directory() {
	DIR=$1
	if [ ! -d "$DIR" ]; then
		echo "error: $DIR is not a directory. Quitting." >&2
		exit 1
	fi
}

verify_file() {
	FILE=$1
	if [ ! -f "$FILE" ]; then
		echo "error: $FILE is not a file. Quitting." >&2
		exit 1
	fi
}

die() { 
    if [ $# -lt 2 ]; then
        RET=2
    else
        RET=$2
    fi
	echo $0: $1 >&2
	exit $RET
}

# TODO: this assumes every file is going to go in the same RELPATH. hmm.
slipstream() {
	DEB="$1"     # the .deb file we are going to mangle
	RELPATH="$2" # relative path in the unpacked .deb
	shift 2

	OLDWD=`pwd`
	cd "$WORKDIR"

	slipstream_permcheck "$DEB"
	slipstream_unpack "$DEB"

	while [ "$#" -gt 0 ]; do
		slipstream_file "$1" "$RELPATH"
		shift
	done

	slipstream_instsize
	slipstream_repack "$DEB"
	slipstream_cleanup

	cd "$OLDWD"
}

slipstream_permcheck() {
	DEB="$1"

	# ensure we can write to $DEB
	if [ ! -w "$DEB" ]; then
		ls -l "$DEB"
		die "wrong permissions on $DEB (I can't write to it)"
	fi

	# ensure we can write to the workdir
	if [ ! -w . ]; then
		die "cannot write to $PWD"
	fi
}
slipstream_unpack() {
	DEB="$1"
	dpkg-deb -e "$DEB" "./DEBIAN"
	dpkg-deb -x "$DEB" "./slipstream.unpacked"
}

slipstream_file() {
	FILE="$1"
	RELPATH="$2"

	cp -p "$FILE" "./slipstream.unpacked/$RELPATH"
	chmod 644 "./slipstream.unpacked/$RELPATH"

	# add a line to md5sums
	cd slipstream.unpacked
	md5sum "$RELPATH" >> "../DEBIAN/md5sums"
	cd ..
}

slipstream_instsize() {
	# figure out the new installed-size
	INSTSIZE=`du -sk ./slipstream.unpacked | cut -f1`
	sed -i  "s/^Installed-Size.*/Installed-Size: $INSTSIZE/" \
		"./DEBIAN/control"
}

slipstream_repack() {
	DEB="$1"     # the .deb file we are going to mangle

	# repack
	mv DEBIAN slipstream.unpacked
	# XXX: store output in a temporary file, then cat the file if
	# dpkg-deb fails for some reason. (this is all to hide a non-
	# suppressable "building package foo in ..." message)
	fakeroot dpkg-deb -b slipstream.unpacked "$DEB" >/dev/null

}

slipstream_cleanup() {
	rm -rf ./slipstream.unpacked
}

# stuff relating to installing the generated packages ########################

install_deb() {
	DEB="$1"
	sudo dpkg -i "$DEB"
}

unravel() {
	FILE="$1"
	if echo "$FILE" | grep ^/ >/dev/null; then
		:
	else
		# assume a relative path
		FILE="$PWD/$FILE"
	fi

	echo $FILE
}

if [ -f ./debian/changelog ]; then
    GAME_PACKAGE_VERSION=`dpkg-parsechangelog -ldebian/changelog --format \
        rfc822 | grep Version | cut -d' ' -f2`
else
    GAME_PACKAGE_VERSION=`dpkg-query --showformat='${Version}\n' \
        --show game-data-packager`
fi