30_packages_arch.sh 6.69 KB
Newer Older
1 2
# write .pkg.tar package meta-data
# USAGE: pkg_write_arch
3
# NEEDED VARS: GAME_NAME PKG_DEPS_ARCH
4 5
# CALLED BY: write_metadata
pkg_write_arch() {
6
	local pkg_deps
7
	if [ "$(get_value "${pkg}_DEPS")" ]; then
8
		# shellcheck disable=SC2046
9
		pkg_set_deps_arch $(get_value "${pkg}_DEPS")
10
	fi
11
	use_archive_specific_value "${pkg}_DEPS_ARCH"
12 13
	if [ "$(get_value "${pkg}_DEPS_ARCH")" ]; then
		pkg_deps="$pkg_deps $(get_value "${pkg}_DEPS_ARCH")"
14
	fi
15 16 17 18
	local pkg_size
	pkg_size=$(du --total --block-size=1 --summarize "$pkg_path" | tail --lines=1 | cut --fields=1)
	local target
	target="$pkg_path/.PKGINFO"
19

20 21 22
	PKG="$pkg"
	get_package_version

23 24 25 26
	mkdir --parents "${target%/*}"

	cat > "$target" <<- EOF
	pkgname = $pkg_id
27
	pkgver = $PKG_VERSION
28 29 30
	packager = $pkg_maint
	builddate = $(date +"%m%d%Y")
	size = $pkg_size
31
	arch = $pkg_architecture
32 33
	EOF

34
	if [ -n "$pkg_description" ]; then
35
		# shellcheck disable=SC2154
36 37 38 39
		cat >> "$target" <<- EOF
		pkgdesc = $GAME_NAME - $pkg_description - ./play.it script version $script_version
		EOF
	else
40
		# shellcheck disable=SC2154
41 42 43 44 45 46 47 48 49 50 51
		cat >> "$target" <<- EOF
		pkgdesc = $GAME_NAME - ./play.it script version $script_version
		EOF
	fi

	for dep in $pkg_deps; do
		cat >> "$target" <<- EOF
		depend = $dep
		EOF
	done

52
	if [ -n "$pkg_provide" ]; then
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
		cat >> "$target" <<- EOF
		conflict = $pkg_provide
		provides = $pkg_provide
		EOF
	fi

	target="$pkg_path/.INSTALL"

	if [ -e "$postinst" ]; then
		cat >> "$target" <<- EOF
		post_install() {
		$(cat "$postinst")
		}

		post_upgrade() {
		post_install
		}
		EOF
	fi

	if [ -e "$prerm" ]; then
		cat >> "$target" <<- EOF
		pre_remove() {
		$(cat "$prerm")
		}

		pre_upgrade() {
		pre_remove
		}
		EOF
	fi
}

86 87 88 89 90
# set list or Arch Linux dependencies from generic names
# USAGE: pkg_set_deps_arch $dep[…]
# CALLS: pkg_set_deps_arch32 pkg_set_deps_arch64
# CALLED BY: pkg_write_arch
pkg_set_deps_arch() {
91
	use_archive_specific_value "${pkg}_ARCH"
92
	local architecture
93
	architecture="$(get_value "${pkg}_ARCH")"
94 95
	case $architecture in
		('32')
96
			pkg_set_deps_arch32 "$@"
97 98
		;;
		('64')
99
			pkg_set_deps_arch64 "$@"
100 101 102 103 104 105 106 107
		;;
	esac
}

# set list or Arch Linux 32-bit dependencies from generic names
# USAGE: pkg_set_deps_arch32 $dep[…]
# CALLED BY: pkg_set_deps_arch
pkg_set_deps_arch32() {
108
	for dep in "$@"; do
109 110 111 112
		case $dep in
			('alsa')
				pkg_dep='lib32-alsa-lib lib32-alsa-plugins'
			;;
113 114 115
			('bzip2')
				pkg_dep='lib32-bzip2'
			;;
116 117 118 119 120 121 122
			('dosbox')
				pkg_dep='dosbox'
			;;
			('freetype')
				pkg_dep='lib32-freetype2'
			;;
			('gcc32')
123
				pkg_dep='gcc-multilib lib32-gcc-libs'
124
			;;
125 126 127
			('gconf')
				pkg_dep='lib32-gconf'
			;;
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
			('glibc')
				pkg_dep='lib32-glibc'
			;;
			('glu')
				pkg_dep='lib32-glu'
			;;
			('glx')
				pkg_dep='lib32-libgl'
			;;
			('gtk2')
				pkg_dep='lib32-gtk2'
			;;
			('json')
				pkg_dep='lib32-json-c'
			;;
143 144 145
			('libcurl')
				pkg_dep='lib32-curl'
			;;
146 147 148 149 150 151
			('libcurl-gnutls')
				pkg_dep='lib32-libcurl-gnutls'
			;;
			('libstdc++')
				pkg_dep='lib32-gcc-libs'
			;;
152 153 154
			('libudev1')
				pkg_dep='lib32-systemd'
			;;
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
			('libxrandr')
				pkg_dep='lib32-libxrandr'
			;;
			('nss')
				pkg_dep='lib32-nss'
			;;
			('openal')
				pkg_dep='lib32-openal'
			;;
			('pulseaudio')
				pkg_dep='pulseaudio'
			;;
			('sdl1.2')
				pkg_dep='lib32-sdl'
			;;
			('sdl2')
				pkg_dep='lib32-sdl2'
			;;
			('sdl2_image')
				pkg_dep='lib32-sdl2_image'
			;;
			('sdl2_mixer')
				pkg_dep='lib32-sdl2_mixer'
			;;
179 180 181
			('theora')
				pkg_dep='lib32-libtheora'
			;;
182 183 184
			('vorbis')
				pkg_dep='lib32-libvorbis'
			;;
185
			('wine'|'wine32'|'wine64')
186 187
				pkg_dep='wine'
			;;
188 189 190
			('wine-staging'|'wine32-staging'|'wine64-staging')
				pkg_dep='wine-staging'
			;;
191 192 193 194 195 196
			('winetricks')
				pkg_dep='winetricks'
			;;
			('xcursor')
				pkg_dep='lib32-libxcursor'
			;;
197 198 199
			('xft')
				pkg_dep='lib32-libxft'
			;;
200 201 202 203 204 205
			('xgamma')
				pkg_dep='xorg-xgamma'
			;;
			('xrandr')
				pkg_dep='xorg-xrandr'
			;;
206 207 208 209 210 211 212 213 214 215 216 217
			(*)
				pkg_deps="$dep"
			;;
		esac
		pkg_deps="$pkg_deps $pkg_dep"
	done
}

# set list or Arch Linux 64-bit dependencies from generic names
# USAGE: pkg_set_deps_arch64 $dep[…]
# CALLED BY: pkg_set_deps_arch
pkg_set_deps_arch64() {
218
	for dep in "$@"; do
219 220 221 222
		case $dep in
			('alsa')
				pkg_dep='alsa-lib alsa-plugins'
			;;
223 224 225
			('bzip2')
				pkg_dep='bzip2'
			;;
226 227 228 229 230 231 232
			('dosbox')
				pkg_dep='dosbox'
			;;
			('freetype')
				pkg_dep='freetype2'
			;;
			('gcc32')
233
				pkg_dep='gcc-multilib lib32-gcc-libs'
234
			;;
235 236 237
			('gconf')
				pkg_dep='gconf'
			;;
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
			('glibc')
				pkg_dep='glibc'
			;;
			('glu')
				pkg_dep='glu'
			;;
			('glx')
				pkg_dep='libgl'
			;;
			('gtk2')
				pkg_dep='gtk2'
			;;
			('json')
				pkg_dep='json-c'
			;;
253 254 255
			('libcurl')
				pkg_dep='curl'
			;;
256 257 258 259 260 261
			('libcurl-gnutls')
				pkg_dep='libcurl-gnutls'
			;;
			('libstdc++')
				pkg_dep='gcc-libs'
			;;
262 263 264
			('libudev1')
				pkg_dep='libsystemd'
			;;
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
			('libxrandr')
				pkg_dep='libxrandr'
			;;
			('nss')
				pkg_dep='nss'
			;;
			('openal')
				pkg_dep='openal'
			;;
			('pulseaudio')
				pkg_dep='pulseaudio'
			;;
			('sdl1.2')
				pkg_dep='sdl'
			;;
			('sdl2')
				pkg_dep='sdl2'
			;;
			('sdl2_image')
				pkg_dep='sdl2_image'
			;;
			('sdl2_mixer')
				pkg_dep='sdl2_mixer'
			;;
289 290 291
			('theora')
				pkg_dep='libtheora'
			;;
292 293 294
			('vorbis')
				pkg_dep='libvorbis'
			;;
295
			('wine'|'wine32'|'wine64')
296 297 298 299 300 301 302 303
				pkg_dep='wine'
			;;
			('winetricks')
				pkg_dep='winetricks'
			;;
			('xcursor')
				pkg_dep='libxcursor'
			;;
304 305 306
			('xft')
				pkg_dep='libxft'
			;;
307 308 309 310 311 312
			('xgamma')
				pkg_dep='xorg-xgamma'
			;;
			('xrandr')
				pkg_dep='xorg-xrandr'
			;;
313 314 315 316 317 318 319 320
			(*)
				pkg_dep="$dep"
			;;
		esac
		pkg_deps="$pkg_deps $pkg_dep"
	done
}

321
# build .pkg.tar package
322
# USAGE: pkg_build_arch $pkg_path
323
# NEEDED VARS: (OPTION_COMPRESSION) (LANG) PLAYIT_WORKDIR
324 325 326
# CALLS: pkg_print
# CALLED BY: build_pkg
pkg_build_arch() {
327 328
	local pkg_filename
	pkg_filename="$PWD/${1##*/}.pkg.tar"
329 330 331

	if [ -e "$pkg_filename" ]; then
		pkg_build_print_already_exists "${pkg_filename##*/}"
332
		eval ${pkg}_PKG=\"$pkg_filename\"
333
		export ${pkg?}_PKG
334 335 336
		return 0
	fi

337 338
	local tar_options
	tar_options='--create --group=root --owner=root'
339

340
	case $OPTION_COMPRESSION in
341 342 343 344 345 346 347 348
		('gzip')
			tar_options="$tar_options --gzip"
			pkg_filename="${pkg_filename}.gz"
		;;
		('xz')
			tar_options="$tar_options --xz"
			pkg_filename="${pkg_filename}.xz"
		;;
349 350 351 352
		('bzip2')
			tar_options="$tar_options --bzip2"
			pkg_filename="${pkg_filename}.bz2"
		;;
353 354
		('none') ;;
		(*)
355
			liberror 'OPTION_COMPRESSION' 'pkg_build_arch'
356 357
		;;
	esac
358 359

	pkg_print "${pkg_filename##*/}"
360 361 362
	if [ "$DRY_RUN" = '1' ]; then
		printf '\n'
		eval ${pkg}_PKG=\"$pkg_filename\"
363
		export ${pkg?}_PKG
364 365
		return 0
	fi
366

367
	(
368
		cd "$1"
369 370
		local files
		files='.PKGINFO *'
371 372 373 374 375
		if [ -e '.INSTALL' ]; then
			files=".INSTALL $files"
		fi
		tar $tar_options --file "$pkg_filename" $files
	)
376

377
	eval ${pkg}_PKG=\"$pkg_filename\"
378
	export ${pkg?}_PKG
379 380

	print_ok
381 382
}