-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsysroot.sh
More file actions
152 lines (123 loc) · 3.49 KB
/
Copy pathsysroot.sh
File metadata and controls
152 lines (123 loc) · 3.49 KB
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
#!/usr/bin/env bash
set -eu
declare -r workdir="${PWD}"
declare -r temporary_directory='/tmp/netbsd-sysroot'
declare -ra targets=(
# 'hpcsh'
# 'vax'
# 'emips'
# 'evbppc'
# 'hppa'
'amd64'
'i386'
# 'alpha'
# 'sparc'
# 'sparc64'
'evbarm-aarch64'
# 'evbarm-earmv7hf'
# 'evbarm-earmv6hf'
)
[ -d "${temporary_directory}" ] || mkdir "${temporary_directory}"
cd "${temporary_directory}"
for target in "${targets[@]}"; do
case "${target}" in
amd64)
declare triplet='x86_64-unknown-netbsd';;
i386)
declare triplet='i386-unknown-netbsdelf';;
emips)
declare triplet='mips-unknown-netbsd';;
alpha)
declare triplet='alpha-unknown-netbsd';;
hppa)
declare triplet='hppa-unknown-netbsd';;
sparc)
declare triplet='sparc-unknown-netbsdelf';;
sparc64)
declare triplet='sparc64-unknown-netbsd';;
vax)
declare triplet='vax-unknown-netbsdelf';;
hpcsh)
declare triplet='shle-unknown-netbsdelf';;
evbppc)
declare triplet='powerpc-unknown-netbsd';;
evbarm-aarch64)
declare triplet='aarch64-unknown-netbsd';;
evbarm-earmv7hf)
declare triplet='armv7-unknown-netbsdelf-eabihf';;
evbarm-earmv6hf)
declare triplet='armv6-unknown-netbsdelf-eabihf';;
esac
declare netbsd_version='10.1'
declare url="https://ftp.netbsd.org/pub/NetBSD/NetBSD-${netbsd_version}/${target}/binary/sets"
declare extension='.tar.xz'
if [ "${target}" = 'i386' ]; then
extension='.tgz'
fi
declare base_url="${url}/base${extension}"
declare comp_url="${url}/comp${extension}"
declare base_output="${temporary_directory}/$(basename "${base_url}")"
declare comp_output="${temporary_directory}/$(basename "${comp_url}")"
declare sysroot_directory="${workdir}/${triplet}"
declare tarball_filename="${sysroot_directory}.tar.xz"
[ -d "${sysroot_directory}" ] || mkdir "${sysroot_directory}"
echo "- Generating sysroot for ${triplet}"
if [ -f "${tarball_filename}" ]; then
echo "+ Already exists. Skip"
continue
fi
echo "- Fetching data from ${base_url}"
curl \
--url "${base_url}" \
--retry '30' \
--retry-all-errors \
--retry-delay '0' \
--retry-max-time '0' \
--location \
--silent \
--output "${base_output}"
echo "- Unpacking ${base_output}"
tar \
--directory="${sysroot_directory}" \
--strip=2 \
--extract \
--file="${base_output}" \
'./usr/lib' \
'./usr/include'
tar \
--directory="${sysroot_directory}" \
--extract \
--file="${base_output}" \
'./lib'
echo "- Fetching data from ${base_url}"
curl \
--url "${comp_url}" \
--retry '30' \
--retry-all-errors \
--retry-delay '0' \
--retry-max-time '0' \
--location \
--silent \
--output "${comp_output}"
echo "- Unpacking ${comp_output}"
tar \
--directory="${sysroot_directory}" \
--strip=2 \
--extract \
--file="${comp_output}" \
'./usr/lib' \
'./usr/include'
# Update permissions
while read name; do
if [ -f "${name}" ]; then
chmod 644 "${name}"
elif [ -d "${name}" ]; then
chmod 755 "${name}"
fi
done <<< "$(find "${sysroot_directory}/include" "${sysroot_directory}/lib")"
echo "- Creating tarball at ${tarball_filename}"
tar --directory="$(dirname "${sysroot_directory}")" --create --file=- "$(basename "${sysroot_directory}")" | xz --threads='0' --extreme --compress -9 --memlimit-compress='100%' > "${tarball_filename}"
sha256sum "${tarball_filename}" | sed "s|$(dirname "${sysroot_directory}")/||" > "${tarball_filename}.sha256"
rm --force --recursive "${sysroot_directory}"
rm --force --recursive "${temporary_directory}/"*
done