Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit b27319b

Browse files
authored
Add debugging options to override the url (#15)
Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
1 parent 2f2a54f commit b27319b

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
### Added
1515

1616
- Look up latest version if no version was specified (#7)
17+
- Add debugging options to override the url (#15)
1718

1819
### Changed
1920

install.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ main () {
131131
echo "--no-update-shell-config Never update the shell config (e.g. .bashrc)"
132132
echo "--shell-config PATH Use this file as your shell config when updating the shell config"
133133
echo "--shell SHELL One of: bash, zsh, fish, sh. Installer will treat this as your shell. Use 'sh' for minimal posix shells such as ash"
134+
echo "--debug-override-url URL Download dune tarball from given url (debugging only)"
135+
echo "--debug-tarball-dir DIR Name of root directory inside tarball (debugging only)"
134136
}
135137

136138
install_root=""
@@ -184,6 +186,20 @@ main () {
184186
;;
185187
esac
186188
;;
189+
--debug-override-url)
190+
if [ "$#" -eq "0" ]; then
191+
error "--debug-override-url must be passed an argument"
192+
fi
193+
debug_override_url="$1"
194+
shift
195+
;;
196+
--debug-tarball-dir)
197+
if [ "$#" -eq "0" ]; then
198+
error "--debug-tarball-dir must be passed an argument"
199+
fi
200+
debug_tarball_dir="$1"
201+
shift
202+
;;
187203
-*)
188204
print_error "Unknown option: $arg"
189205
usage
@@ -227,9 +243,9 @@ main () {
227243
error "The Dune installation script does not currently support $(uname -ms)."
228244
esac
229245
tarball="dune-$version-$target.tar.gz"
230-
tar_uri="$dune_bin_git_url/releases/download/$version/$tarball"
246+
tar_uri=${debug_override_url:-"$dune_bin_git_url/releases/download/$version/$tarball"}
231247
# The tarball is expected to contain a single directory with this name:
232-
tarball_dir="dune-$version-$target"
248+
tarball_dir=${debug_tarball_dir:-"dune-$version-$target"}
233249

234250
ensure_command "tar"
235251
ensure_command "gzip"
@@ -309,8 +325,14 @@ main () {
309325
fi
310326
tmp_tar="$tmp_dir/$tarball"
311327

328+
if [ -z "${debug_override_url+x}" ]; then
329+
curl_proto="=https"
330+
else
331+
# When using a debugging url the tarball might not be served with https.
332+
curl_proto="all"
333+
fi
312334
curl --fail --location --progress-bar \
313-
--proto '=https' --tlsv1.2 \
335+
--proto "$curl_proto" --tlsv1.2 \
314336
--output "$tmp_tar" "$tar_uri" ||
315337
error_download_failed "$tar_uri" "$version"
316338

test.dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,29 @@ RUN $SHELL -c 'test $(which dune) = "/home/user/.local/bin/dune"'
253253

254254

255255

256+
###############################################################################
257+
# Test the options to override the tarball url and directory name. These flags
258+
# can be used to install dune from a tarball at an arbitrary url, so just point
259+
# them at the official release anyway as this will still exercise the logic for
260+
# downloading dune from a url passed on the command-line.
261+
FROM base AS test10
262+
RUN apk update && apk add curl
263+
ENV DUNE_VERSION="3.19.1"
264+
265+
# Install dune system-wide using the install script:
266+
RUN ./install.sh $DUNE_VERSION --install-root /usr --no-update-shell-config \
267+
--debug-override-url https://github.com/ocaml-dune/dune-bin/releases/download/3.19.1/dune-3.19.1-x86_64-unknown-linux-musl.tar.gz \
268+
--debug-tarball-dir dune-3.19.1-x86_64-unknown-linux-musl
269+
270+
# Test that dune was installed to the expected location:
271+
RUN test $(which dune) = "/usr/bin/dune"
272+
273+
# Test that the installed dune can be executed and that it reports being the
274+
# expected version:
275+
RUN test $(dune --version) = "$DUNE_VERSION"
276+
277+
278+
256279
###############################################################################
257280
# Final stage that copies the install scripts from the previous stage to force
258281
# them to be rerun after the script changes. Docker won't rerun stages which
@@ -267,3 +290,4 @@ COPY --from=test6 /install.sh .
267290
COPY --from=test7 /install.sh .
268291
COPY --from=test8 /install.sh .
269292
COPY --from=test9 /install.sh .
293+
COPY --from=test10 /install.sh .

test_errors.expected_output

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Options:
1515
--no-update-shell-config Never update the shell config (e.g. .bashrc)
1616
--shell-config PATH Use this file as your shell config when updating the shell config
1717
--shell SHELL One of: bash, zsh, fish, sh. Installer will treat this as your shell. Use 'sh' for minimal posix shells such as ash
18+
--debug-override-url URL Download dune tarball from given url (debugging only)
19+
--debug-tarball-dir DIR Name of root directory inside tarball (debugging only)
1820

1921

2022
Test that omitting the argument to --install-root is an error:
@@ -35,3 +37,11 @@ Test that --shell requires an argument:
3537

3638
Test that --shell validates its argument:
3739
error: --shell must be passed one of bash, zsh, fish, sh. Got foo.
40+
41+
42+
Test that --debug-override-url requires an argument:
43+
error: --debug-override-url must be passed an argument
44+
45+
46+
Test that --debug-tarball-dir requires an argument:
47+
error: --debug-tarball-dir must be passed an argument

test_errors.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ main() {
3838

3939
test_title "Test that --shell validates its argument:"
4040
install 3.19.1 --shell foo
41+
42+
test_title "Test that --debug-override-url requires an argument:"
43+
install 3.19.1 --debug-override-url
44+
45+
test_title "Test that --debug-tarball-dir requires an argument:"
46+
install 3.19.1 --debug-tarball-dir
4147
}
4248

4349
main "$@" 2>&1

0 commit comments

Comments
 (0)