1 # This file provides several functions to ease packaging of Unreal based games
2 # for Arch Linux. It should be sourced in the PKGBUILD's build() function.
4 # For an example of the usage of the functions take a look at the "ut1999"
5 # PKGBUILD on the Arch Linux AUR.
7 # Usage: _unreal_handle_files command from_dir to_dir ignore_regex < file_list
9 # Tries to find the basename of the files read from standard input in
10 # "from_dir" case insensitively and applies "command" which has the
11 # form "cmd source dest" (like cp or mv) to it, where the "dest" is
12 # "to_dir"/entry from stdin. The files given by the case insensitive
13 # egrep style regular expression "ignore_regex" won't be searched. You
14 # probably want to make sure that the target directories already exist.
16 # This function usually doesn't get called directly but by
17 # _unreal_(copy|install|move)_files with "command" already filled in.
18 _unreal_handle_files
() {
22 /usr
/bin
/find -- "$2" -regextype posix-egrep \
23 -iname "$(basename -- "${stdin}")" -a ! -iregex "$4" \
24 -print |
while read file
26 $1 "${file}" "$3/${stdin}" ||
return 1
31 # Usage: _unreal_copy_files from_dir to_dir ignore_regexp < file_list
33 # Calls _unreal_handle_files with "cp" as command.
34 _unreal_copy_files
() {
35 _unreal_handle_files
"/bin/cp --force --" "$@" ||
return 1
38 # Usage: _unreal_install_files from_dir to_dir ignore_regexp < file_list
40 # Basically calls _unreal_handle_files with "install" as command.
41 _unreal_install_files
() {
42 _unreal_handle_files
"/bin/install --mode=644 -D --" "$@" ||
return 1
45 # Usage: _unreal_move_files from_dir to_dir ignore_regexp < file_list
47 # Just calls _unreal_handle_files with "mv" as command.
48 _unreal_move_files
() {
49 _unreal_handle_files
"/bin/mv --force --" "$@" ||
return 1
52 # Usage: _unreal_decompress_files from_dir to_dir ingore_regex < file_list
54 # Reads a "file_list" from standard input, tries to find their basenames
55 # in "from_dir" case insensitively and decompresses them with the
56 # command "to_dir/ucc". The direcories given by the case insensitive
57 # egrep style regular expression "ignore_dir_regex" won't be searched.
59 # ucc stores the decomressed files in "to_dir/System". So you might
60 # want to apply the same "file_list" (minus the .uz ending) to
61 # _unreal_move_files to correct the location.
62 _unreal_decompress_files
() {
64 /usr
/bin
/find -- "$1" -regextype posix-egrep \
65 -iname "$(basename -- "${stdin}")" -a ! -iregex "$3" \
66 -print |
while read file
68 "$2/ucc" decompress
"${file}" -nohomedir ||
return 1
73 # Usage: _unreal_loki_patcher continue_on_fail from_dir to_dir ignore_regex
75 # Apply the Xdelta patches and gzip replacement files residing in the
76 # parallel directory structure in "from_dir" to the files in "to_dir",
77 # where files matching the egrep regular expression "ignore_regex"
78 # will be ignored. If "continue_on_fail" is "true" the function whill
79 # continue even if a single patch couldn't be applied. If it is "false"
80 # the function will terminate when only a single patch doesn't apply
83 # This function usually doesn't get called directly but by
84 # _unreal_fail_{fast,safe}_patcher with "continue_on_fail" already
86 _unreal_loki_patcher
() {
89 /bin
/mkdir
-p xdelta.tmp
91 /usr
/bin
/find .
-regextype posix-egrep \
92 -type f
-a ! -iregex ".*/xdelta.tmp/.*" -a ! -iregex "$4" \
93 -print |
while read file
95 case "$(file -b -- "${file}")" in
97 dest
="$(echo "${file}" | /bin/sed 's/\.0$//')"
98 /usr
/bin
/xdelta
patch -- "${file}" "$3/${dest}" \
99 "xdelta.tmp/$(basename -- "${dest}")" \
100 && /bin
/install --mode=644 -D -- \
101 "xdelta.tmp/$(basename -- "${dest}")" "$3/${dest}" \
105 /bin
/gzip --decompress --stdout -- "${file}" > "$3/${file}" \
109 /bin
/install --mode=755 -D -- "${file}" "$3/${file}" \
113 /bin
/install --mode=644 -D -- "${file}" "$3/${file}" \
121 # Usage: _unreal_fail_safe_patcher from_dir to_dir ignore_regex
123 # Tries to apply the patches found in "form_dir" to "to_dir", but
124 # doesn't exit if a single patch doesn't apply.
125 _unreal_fail_safe_patcher
() {
126 _unreal_loki_patcher
"true" "$@" ||
return 1
129 # Usage: _unreal_fail_fast_patcher from_dir to_dir ignore_regex
131 # Like _unreal_fail_safe_patcher, but exits if only a single patch
132 # couldn't be applied successfully.
133 _unreal_fail_fast_patcher
() {
134 _unreal_loki_patcher
"false" "$@" ||
return 1