-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_macports
executable file
·240 lines (194 loc) · 4.77 KB
/
install_macports
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/sh
# install_macports — Install MacPorts on a GitHub Runner
# Melusina Actions (https://github.com/melusina-org/setup-macports)
# This file is part of Melusina Actions.
#
# Copyright © 2022–2023 Michaël Le Barbier
# All rights reserved.
# Install MacPorts (https://github.com/melusina-org/gha-install-macports)
# This file is part of Install MacPorts.
#
# Copyright © 2022–2023 Michaël Le Barbier
# All rights reserved.
# This file must be used under the terms of the MIT License.
# This source file is licensed as described in the file LICENSE, which
# you should have received as part of this distribution. The terms
# are also available at https://opensource.org/licenses/MIT
: ${TOPLEVELDIR:=$(git rev-parse --show-toplevel)}
: ${subrdir:=${TOPLEVELDIR}/subr}
. "${subrdir}/stdlib.sh"
. "${subrdir}/macos.sh"
. "${subrdir}/macports.sh"
github_owner='macports'
github_repo='macports-base'
parameterfile='.github/parameters/gha-install-macports.yaml'
github_api()
(
url()
{
printf 'https://api.github.com'
printf '/%s' "$@"
}
exec curl --silent -H "Accept: application/vnd.github+json" $(url "$@")
)
extract_releases()
{
github_api repos "${github_owner}" "${github_repo}" releases
}
transform_releases()
{
python3 -c'
import json
import sys
releases = json.loads(sys.stdin.read())
for release in releases:
if release["draft"]: continue
for asset in release["assets"]:
print(f"""{release["tag_name"]}|{release["name"]}|{asset["browser_download_url"]}""")
'
}
find_package()
{
python3 -c'
import json
import re
import sys
macos = sys.argv[1]
tag_name = sys.argv[2]
package_pattern = macos + "[.]pkg$"
releases = json.loads(sys.stdin.read())
package = ":not-found"
for release in releases:
if release["draft"]: continue
if release["tag_name"] == tag_name:
for asset in release["assets"]:
if re.search(package_pattern, asset["browser_download_url"]):
package = asset["browser_download_url"]
print(package)
' "$@"
}
find_macos()
{
python3 -c'
import json
import re
import sys
macos_names = set()
releases = json.loads(sys.stdin.read())
def extract_macos_name(download_url):
macos_name = download_url
macos_name = re.sub(".pkg$", "", macos_name)
macos_name = re.sub(".*MacPorts-[0-9._]*-", "", macos_name)
macos_name = re.sub("beta[0-9._]*-", "", macos_name)
macos_name = re.sub("rc[0-9._]*-", "", macos_name)
return macos_name
for release in releases:
if release["draft"]: continue
for asset in release["assets"]:
if re.search(".pkg$", asset["browser_download_url"]):
macos_names.add(extract_macos_name(asset["browser_download_url"]))
def fsort(l):
l.sort
return l
for macos_name in fsort(list(macos_names)):
print(macos_name)
'
}
fetch_releases()
{
extract_releases | transform_releases
}
fetch_macos_db()
{
extract_releases | find_macos | sort
}
fetch_package()
{
extract_releases | find_package "$@"
}
usage()
{
if [ "$#" -gt 0 ]; then
wlog 'Failure' "$@"
fi
cat 1>&2 <<'EOF'
Usage: install_macports [VERSION-OR-PATHNAME]
Install MacPorts
EOF
exit 64
}
fetch_and_install_package()
{
local pathname package
package="$1"
pathname="./${package##*/}"
curl -L -o "${pathname}" "${package}"\
|| failwith 'Cannot download package \047%s\047' "${package}"
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${macports_prefix}"
sudo installer -pkg "${pathname}" -target /
sudo chown -R $(id -u -n):$(id -g -n) "${macports_prefix}"
}
install_from_source()
{
local srcdir
srcdir='/opt/local/src'
sudo install -d -o $(id -u -n) -g $(id -g -n) -m 755 "${srcdir}"
(
cd "${srcdir}"
git clone https://github.com/macports/macports-base.git
cd macports-base
git checkout "v${macports_version}"
./configure --enable-readline --prefix="${macports_prefix}"
make
sudo make install
)
sudo rm -Rf "${srcdir}"
sudo port -v selfupdate
}
install_ports()
{
ports_document "$1" | xargs -J '%' sudo port install '%'
}
experimental()
{
:
}
main()
{
local OPTIND OPTION OPTARG
local macos package action
ensure_macos
action='install'
OPTIND=1
while getopts 'x' OPTION; do
case ${OPTION} in
x)
action='experimental'
;;
*)
usage '\047%s\047 Unsupported option.' "${OPTION}"
;;
esac
done
shift $(expr ${OPTIND} - 1)
case "$#" in
0)
:
;;
esac
if [ "${action}" = 'experimental' ]; then
experimental "$@"
exit 0
fi
with_group_presentation\
'Configuration Summary'\
configuration_summary
if [ "${macports_prefix}" = '/opt/local' ]; then
fetch_and_install_package "$(make_package)"
else
install_from_source
fi
install_ports "${macports_prefix}/etc/setup-macports.yaml"
}
main "$@"
# End of file `install_macports'