-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathxx-apt
executable file
·215 lines (189 loc) · 4.95 KB
/
xx-apt
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env sh
set -e
if [ -z "$XX_APT_NOLOCK" ]; then
lock="/var/lock/xx-apt"
exec 9>$lock
flock -x 9
export XX_APT_NOLOCK=1
fi
if [ -n "$XX_DEBUG_APT" ]; then
set -x
fi
for l in $(xx-info env); do
export "${l?}"
done
checkpkg() {
apt show "$@"
}
exitnolinux() {
if [ "${TARGETOS}" != "linux" ]; then
echo >&2 "skipping packages installation on ${XX_OS}"
exit 0
fi
}
# these are not supported yet
case "${TARGETARCH}" in
mips*)
echo >&2 "skipping packages installation on ${XX_ARCH}"
exit 0
;;
riscv*)
case "${XX_VENDOR}" in
debian)
if ! grep "sid main" /etc/apt/sources.list >/dev/null; then
echo >&2 "skipping packages installation on ${XX_ARCH}. riscv64 currently only supported on sid"
exit 0
fi
;;
ubuntu)
if ! grep 'VERSION="2' /etc/os-release >/dev/null 2>/dev/null; then
echo >&2 "skipping packages installation on ${XX_ARCH}. riscv64 requires 20.04+"
exit 0
fi
;;
esac
;;
*) ;;
esac
arg0="$(basename "$0")"
if [ "$arg0" = "xx-apt-get" ]; then
arg0="apt-get"
else
arg0="apt"
fi
fixubuntusources() {
# fix all current sources to native arch
nativearch="$(TARGETPLATFORM="" TARGETPAIR="" TARGETARCH="" TARGETOS="" xx-info arch)"
sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i /etc/apt/sources.list
if ! xx-info is-cross; then return; fi
# add custom list for target
debarch=$(xx-info debian-arch)
targetlist=/etc/apt/sources.list.d/xx-$debarch.list
if [ -f "$targetlist" ]; then return; fi
mainurl=archive.ubuntu.com/ubuntu
securityurl=security.ubuntu.com/ubuntu
case "${debarch}" in
arm64 | armhf | ppc64el | s390x | riscv64)
mainurl=ports.ubuntu.com/ubuntu-ports
securityurl=$mainurl
;;
esac
# shellcheck disable=SC1091
ubuntuname=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
cat <<eot >"$targetlist"
deb [arch=$debarch] http://$mainurl/ $ubuntuname main restricted universe multiverse
deb [arch=$debarch] http://$mainurl/ $ubuntuname-updates main restricted universe multiverse
deb [arch=$debarch] http://$mainurl/ $ubuntuname-backports main restricted universe multiverse
deb [arch=$debarch] http://$securityurl/ $ubuntuname-security main restricted universe multiverse
eot
}
packages=
parsed=
n=$#
for p in "$@"; do
if [ $# = $n ]; then set --; fi
arg=
case "$p" in
-*)
arg="$p"
;;
"install" | "remove" | "search" | "show" | "list" | "info")
parsed=1
arg="$p"
;;
*)
if [ -n "$parsed" ]; then
if [ -z "${packages}" ]; then
packages="$p"
else
packages="${packages} ${p}"
fi
else
arg="$p"
fi
;;
esac
if [ -n "$arg" ]; then
set -- "$@" "$arg"
fi
done
if [ -z "${parsed}" ]; then
exitnolinux
exec apt "$@"
fi
nocross=
if ! xx-info is-cross; then
nocross=1
fi
if [ "$TARGETARCH" = "riscv64" ] && [ "$(xx-info vendor)" = "debian" ]; then
apt-get update
apt-get install -y debian-ports-archive-keyring
echo "deb [ arch=riscv64 ] http://ftp.ports.debian.org/debian-ports sid main" >>/etc/apt/sources.list.d/riscv64-sid.list
fi
if ! dpkg --print-foreign-architectures | grep "$XX_PKG_ARCH" >/dev/null; then
if [ "$XX_OS" = "linux" ]; then
if [ "$(xx-info vendor)" = "ubuntu" ] && [ -z "$nocross" ]; then
# ubuntu uses different repositories for amd64/386 and rest of the architectures
# so we need to fix the sources.list and add new ones
fixubuntusources
fi
dpkg --add-architecture "$XX_PKG_ARCH"
fi
apt-get update
fi
suffix=$XX_TRIPLE
if [ "$suffix" = "x86_64-linux-gnu" ]; then
suffix="x86-64-linux-gnu"
fi
if [ "$XX_OS" = "windows" ]; then
case "$XX_ARCH" in
amd64) suffix="mingw-w64-x86-64" ;;
386) suffix="mingw-w64-i686" ;;
arm64) suffix="mingw-w64-aarch64" ;;
arm) suffix="mingw-w64-arm" ;;
esac
fi
packages2=
for p in ${packages}; do
if [ "${p}" = "xx-c-essentials" ]; then
p="libc6-dev"
if "$arg0" info "libgcc-10-dev:${XX_PKG_ARCH}" >/dev/null 2>/dev/null; then
p="$p libgcc-10-dev"
else
p="$p libgcc-8-dev"
fi
elif [ "${p}" = "xx-cxx-essentials" ]; then
if "$arg0" info "libstdc++-10-dev:${XX_PKG_ARCH}" >/dev/null 2>/dev/null; then
p="libstdc++-10-dev"
else
p="libstdc++-8-dev"
fi
fi
if [ -z "$packages2" ]; then
packages2="$p"
else
packages2="${packages2} $p"
fi
done
empty=1
for p in ${packages2}; do
n=
if [ -n "$nocross" ]; then
n=${p}
elif checkpkg "${p}-${suffix}" >/dev/null 2>/dev/null; then
n="${p}-${suffix}"
elif [ "${XX_OS}" = "linux" ] && [ -n "${XX_APT_PREFER_CROSS}" ] && checkpkg "${p}-${XX_PKG_ARCH}-cross" >/dev/null 2>/dev/null; then
n="${p}-${XX_PKG_ARCH}-cross"
elif [ "${XX_OS}" = "linux" ]; then
n="${p}:${XX_PKG_ARCH}"
else
continue
fi
empty=
set -- "$@" "$n"
done
if [ -n "$empty" ]; then
exitnolinux
fi
echo >&2 "+ $arg0 " "$@"
exec "$arg0" "$@"