-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoxx-apt-get
executable file
·127 lines (116 loc) · 3.26 KB
/
goxx-apt-get
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
#!/usr/bin/env bash
set -e
source goxx-env
exitnolinux() {
if [ "${GOOS}" != "linux" ]; then
echo >&2 "WARN: skipping packages installation on ${GOOS}"
exit 0
fi
}
setaptsources() {
local file=$1
local arch=$2
local mainuri=$3
local securi=$4
local release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
cat > "$file" <<EOL
deb [arch=$arch] $mainuri $release main restricted universe multiverse
deb [arch=$arch] $mainuri $release-updates main restricted universe multiverse
deb [arch=$arch] $mainuri $release-backports main restricted universe multiverse
deb [arch=$arch] $securi $release-security main restricted universe multiverse
EOL
}
if [ -z "${GOXX_SKIP_APT_PORTS}" ]; then
case "${GOXX_HOSTARCH}" in
amd64 | i386)
setaptsources "/etc/apt/sources.list" "$GOXX_HOSTARCH" "http://archive.ubuntu.com/ubuntu/" "http://security.ubuntu.com/ubuntu/"
;;
*)
setaptsources "/etc/apt/sources.list" "$GOXX_HOSTARCH" "http://ports.ubuntu.com/ubuntu-ports/" "http://ports.ubuntu.com/ubuntu-ports/"
;;
esac
if [ "$GOOS" = "linux" ] && [ "$GOXX_CROSS" = "1" ]; then
case "${GOXX_DEBARCH}" in
amd64 | i386)
setaptsources "/etc/apt/sources.list.d/port-$GOXX_DEBARCH.list" "$GOXX_DEBARCH" "http://archive.ubuntu.com/ubuntu/" "http://security.ubuntu.com/ubuntu/"
;;
*)
setaptsources "/etc/apt/sources.list.d/port-$GOXX_DEBARCH.list" "$GOXX_DEBARCH" "http://ports.ubuntu.com/ubuntu-ports/" "http://ports.ubuntu.com/ubuntu-ports/"
;;
esac
fi
if ! dpkg --print-foreign-architectures | grep "$GOXX_DEBARCH" >/dev/null; then
if [ "$GOOS" = "linux" ] && [ "$GOXX_CROSS" = "1" ]; then
dpkg --add-architecture "$GOXX_DEBARCH"
fi
apt-get update
fi
fi
if [ "$GOOS" = "linux" ] && [ "$GOXX_DEBARCH" = "$GOXX_HOSTARCH" ]; then
(set -x ; apt-get "$@")
exit 0
fi
suffix=$GOXX_TRIPLE
if [ "$suffix" = "x86_64-linux-gnu" ]; then
suffix="x86-64-linux-gnu"
fi
if [ "$GOOS" = "windows" ]; then
case "$GOARCH" in
amd64) suffix="mingw-w64-x86-64" ;;
386) suffix="mingw-w64-i686" ;;
arm64) suffix="mingw-w64-aarch64" ;;
arm) suffix="mingw-w64-arm" ;;
esac
fi
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
empty=1
for p in ${packages}; do
n=
if [ "$GOXX_CROSS" = "0" ] && [ -n "$(apt-cache madison "${p}" 2>/dev/null)" ]; then
n=${p}
elif [ -n "$(apt-cache madison "${p}-${suffix}" 2>/dev/null)" ]; then
n="${p}-${suffix}"
elif [ "${GOOS}" = "linux" ] && [ -n "$(apt-cache madison "${p}-${GOXX_DEBARCH}-cross" 2>/dev/null)" ]; then
n="${p}-${GOXX_DEBARCH}-cross"
elif [ "${GOOS}" = "linux" ] && [ -n "$(apt-cache madison "${p}:${GOXX_DEBARCH}" 2>/dev/null)" ]; then
n="${p}:${GOXX_DEBARCH}"
else
continue
fi
empty=
set -- "$@" "$n"
done
if [ -n "$empty" ]; then
exitnolinux
fi
set -x
exec apt-get "$@"