-
Notifications
You must be signed in to change notification settings - Fork 4
/
make-unizip
executable file
·133 lines (114 loc) · 3.98 KB
/
make-unizip
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
#! /usr/bin/env bash
# ===========================================================================
#
# Copyright (c) 2021 Unvanquished Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===========================================================================
set -eu
if [ $# != 1 ] || [ ! -d "$1" ]
then
echo "Usage: $0 <release_dir>"
echo 'Creates a partial universal zip with whatever components have been built'
exit 1
fi
release_dir="$(sed -E 's!/+!/!g; s!(.)/$!\1!' <<< "$1")" # 7z chokes on extra slashes
version='0' # TODO
work_dir="${release_dir}/unizip_staging"
release_basename="unvanquished_${version}"
release_zip="${release_basename}.zip"
symbols_basename="symbols_${version}"
symbols_zip="symbols_${version}.zip"
content_dir="${work_dir}/${release_basename}"
extractSymbols () {
local archive="$1"
if symbol_archive=$(7z l "${archive}" | grep -oE 'symbols.*\.7z|unvanquished_.*/symbols_.*\.zip')
then
echo "extracting ${symbol_archive}"
mkdir -p "${work_dir}/symbols"
7z x -o"${work_dir}" "${archive}" "${symbol_archive}" >/dev/null
7z x -o"${work_dir}/symbols" "${work_dir}/${symbol_archive}" >/dev/null
echo "deleting ${symbol_archive} from ${archive}"
7z d "${archive}" "${symbol_archive}" >/dev/null
fi
}
if [ -d "${work_dir}" ]
then
rm -rv "${work_dir}"
fi
mkdir -v "${work_dir}"
mkdir -v "${content_dir}"
# If there is already a supposedly incomplete release zip, for example
# an unvanquished_0.zip containing linux-amd64.zip, windows-i386.zip
# and windows-amd64.zip, and a lone macos-amd64.zip build next to it,
# extend unvanquished_0.zip with macos-amd64.zip.
if [ -f "${release_dir}/${release_zip}" ]
then
extractSymbols "${release_dir}/${release_zip}"
7z x -o"${work_dir}" "${release_dir}/${release_zip}" >/dev/null
fi
if cp --preserve=timestamps "$0" "${work_dir}/timestamp-test"
then
alias cp='cp --preserve=timestamps'
fi
cp -v "$(dirname $0)/unizip-readme.txt" "${content_dir}/README.txt"
# Prepare pkg/
mkdir -pv "${content_dir}/pkg"
for dpk in $(find "${release_dir}" ! -path "${work_dir}/*" -name '*.dpk')
do
dest="${content_dir}/pkg/$(basename "${dpk}")"
cp -v "${dpk}" "${dest}"
extractSymbols "${dest}"
done
(
cd "${content_dir}/pkg"
if ls *.dpk >/dev/null 2>&1
then
md5sum --binary -- *.dpk > md5sums
else
touch md5sums
fi
)
# Prepare <os>-<arch>.zip
for os_zip in $(find "${release_dir}" ! -path "${work_dir}/*" -name '*.zip' | grep -E '/(windows|macos|linux)-[^/]*$')
do
dest="${content_dir}/$(basename "${os_zip}")"
cp -v "${os_zip}" "${dest}"
extractSymbols "${dest}"
done
# Compress symbols
(
if [ -d "${work_dir}/symbols" ]
then
cd "${work_dir}/symbols"
7z a -tzip -mx=9 "../${release_basename}/symbols_${version}.zip" .
fi
)
# Create (partial) universal zip
(
cd "${work_dir}"
if [ -f "../unvanquished_${version}.zip" ]
then
rm -v "../unvanquished_${version}.zip"
fi
# Even though almost all the contents are compressed already, it still saves some...
7z a -tzip -mx=9 "../${release_zip}" "${release_basename}"
)
rm -rv "${work_dir}"