Repository navigation
install.sh: fall back to wget and to other zip extractors #43643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a317253
9abdbd5
79a4949
0b50c54
bd23996
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,8 +53,27 @@ success() { | |
| echo -e "${Green}$@ ${Color_Off}" | ||
| } | ||
|
|
||
| command -v unzip >/dev/null || | ||
| error 'unzip is required to install bun' | ||
| if command -v curl >/dev/null; then | ||
| download_cmd=curl | ||
| elif command -v wget >/dev/null; then | ||
| download_cmd=wget | ||
| else | ||
| error 'curl or wget is required to install bun' | ||
| fi | ||
|
|
||
| unzip_cmd='' | ||
| for cmd in unzip busybox 7z 7zz 7za bsdtar python3; do | ||
| command -v "$cmd" >/dev/null || continue | ||
| # A busybox build can leave out the unzip applet. | ||
| if [[ $cmd = busybox ]] && ! busybox --list 2>/dev/null | grep -x unzip >/dev/null; then | ||
| continue | ||
| fi | ||
| unzip_cmd=$cmd | ||
| break | ||
| done | ||
|
|
||
| [[ $unzip_cmd ]] || | ||
| error 'unzip is required to install bun (7z, busybox, bsdtar, python3 supported)' | ||
|
|
||
| if [[ $# -gt 2 ]]; then | ||
| error 'Too many arguments, only 2 are allowed. The first can be a specific tag of bun to install. (e.g. "bun-v0.1.4") The second can be a build variant of bun to install. (e.g. "debug-info")' | ||
|
|
@@ -146,11 +165,33 @@ if [[ ! -d $bin_dir ]]; then | |
| error "Failed to create install directory \"$bin_dir\"" | ||
| fi | ||
|
|
||
| curl --fail --location --progress-bar --output "$exe.zip" "$bun_uri" || | ||
| error "Failed to download bun from \"$bun_uri\"" | ||
| case $download_cmd in | ||
| curl) | ||
| curl --fail --location --progress-bar --output "$exe.zip" "$bun_uri" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 nit (optional): users installing with the new wget fallback are left with an empty Extended reasoning...install.sh:56-62 picks wget when curl is absent. install.sh:170 runs Verification: nit. Trigger: host without |
||
| ;; | ||
| wget) | ||
| wget -q -O "$exe.zip" "$bun_uri" | ||
| ;; | ||
| esac || error "Failed to download bun from \"$bun_uri\"" | ||
|
|
||
| unzip -oqd "$bin_dir" "$exe.zip" || | ||
| error 'Failed to extract bun' | ||
| # python3's zipfile does not restore the file mode; the chmod below covers it. | ||
| case $unzip_cmd in | ||
| unzip) | ||
| unzip -oqd "$bin_dir" "$exe.zip" | ||
| ;; | ||
| busybox) | ||
| busybox unzip -oq "$exe.zip" -d "$bin_dir" | ||
| ;; | ||
| 7z | 7zz | 7za) | ||
| "$unzip_cmd" x -y -o"$bin_dir" "$exe.zip" >/dev/null | ||
| ;; | ||
| bsdtar) | ||
| bsdtar --no-same-owner -xf "$exe.zip" -C "$bin_dir" | ||
| ;; | ||
| python3) | ||
| python3 -m zipfile -e "$exe.zip" "$bin_dir" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 nit (optional) (security hardening): on hosts that fall back to python3, the installer now imports Python modules from whatever directory the user happens to run it in. install.sh:192 runs Extended reasoning...The base branch never spawns python3. This PR makes Verification: nit (security hardening, narrow trigger) — triggers when a host has none of unzip/busybox-with-unzip/7z/7zz/7za/bsdtar but has python3, and the user runs |
||
| ;; | ||
| esac || error 'Failed to extract bun' | ||
|
|
||
| mv "$bin_dir/bun-$target/$exe_name" "$exe" || | ||
| error 'Failed to move extracted bun to destination' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,96 @@ fn argv_contains(target: &[u8]) -> bool { | |
| bun_core::argv().iter().any(|a| a == target) | ||
| } | ||
|
|
||
| /// A program that can extract the release zip on POSIX into the current | ||
| /// directory. `before` and `after` are the arguments around the archive path. | ||
|
Comment on lines
+66
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| #[cfg(unix)] | ||
| struct UnzipProgram { | ||
| bin: &'static [u8], | ||
| before: &'static [&'static [u8]], | ||
| after: &'static [&'static [u8]], | ||
| } | ||
|
|
||
| /// Probe order. Must match the `for cmd in ...` loop in `install.sh`. | ||
| /// The vendored libarchive has no zip reader, so an external program extracts it. | ||
|
Comment on lines
+77
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| #[cfg(unix)] | ||
| const UNZIP_PROGRAMS: &[UnzipProgram] = &[ | ||
| UnzipProgram { | ||
| bin: b"unzip", | ||
| before: &[b"-q", b"-o"], | ||
| after: &[], | ||
| }, | ||
| UnzipProgram { | ||
| bin: b"busybox", | ||
| before: &[b"unzip", b"-q", b"-o"], | ||
| after: &[], | ||
| }, | ||
| UnzipProgram { | ||
| bin: b"7z", | ||
| before: &[b"x", b"-y"], | ||
| after: &[], | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }, | ||
| UnzipProgram { | ||
| bin: b"7zz", | ||
| before: &[b"x", b"-y"], | ||
| after: &[], | ||
| }, | ||
| UnzipProgram { | ||
| bin: b"7za", | ||
| before: &[b"x", b"-y"], | ||
| after: &[], | ||
| }, | ||
| UnzipProgram { | ||
| bin: b"bsdtar", | ||
| before: &[b"--no-same-owner", b"-xf"], | ||
| after: &[], | ||
| }, | ||
| UnzipProgram { | ||
| bin: b"python3", | ||
| before: &[b"-m", b"zipfile", b"-e"], | ||
| after: &[b"."], | ||
| }, | ||
| ]; | ||
|
|
||
| /// A busybox build can leave out the unzip applet. `busybox --list` prints one | ||
| /// applet name per line. | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| #[cfg(unix)] | ||
| fn busybox_has_unzip(busybox: &[u8]) -> bool { | ||
| let argv: [&[u8]; 2] = [busybox, b"--list"]; | ||
| let Ok(Ok(result)) = spawn_sync::spawn(&spawn_sync::Options { | ||
| argv: build_argv(&argv), | ||
| envp: None, | ||
| stdin: spawn_sync::SyncStdio::Ignore, | ||
| stdout: spawn_sync::SyncStdio::Buffer, | ||
| stderr: spawn_sync::SyncStdio::Ignore, | ||
| ..Default::default() | ||
| }) else { | ||
| return false; | ||
| }; | ||
| result.status.is_ok() | ||
| && strings::split(result.stdout.as_slice(), b"\n").any(|line| line == b"unzip") | ||
| } | ||
|
|
||
| /// Returns the argv of the first entry of `UNZIP_PROGRAMS` found in `path`. | ||
| #[cfg(unix)] | ||
| fn find_unzip_argv(path: &[u8], cwd: &[u8], archive: &[u8]) -> Option<Vec<Box<[u8]>>> { | ||
| let mut buf = bun_paths::path_buffer_pool::get(); | ||
| for program in UNZIP_PROGRAMS { | ||
| let Some(exe) = which(&mut buf, path, cwd, program.bin) else { | ||
| continue; | ||
| }; | ||
| if program.bin == b"busybox" && !busybox_has_unzip(exe.as_bytes()) { | ||
| continue; | ||
| } | ||
| let mut argv = Vec::with_capacity(program.before.len() + program.after.len() + 2); | ||
| argv.push(Box::<[u8]>::from(exe.as_bytes())); | ||
| argv.extend(program.before.iter().map(|a| Box::<[u8]>::from(*a))); | ||
| argv.push(Box::<[u8]>::from(archive)); | ||
| argv.extend(program.after.iter().map(|a| Box::<[u8]>::from(*a))); | ||
| return Some(argv); | ||
| } | ||
| None | ||
| } | ||
|
|
||
| // ────────────────────────────────────────────────────────────────────────── | ||
|
|
||
| pub struct Version { | ||
|
|
@@ -816,29 +906,20 @@ impl UpgradeCommand { | |
|
|
||
| #[cfg(unix)] | ||
| { | ||
| let mut unzip_path_buf = bun_paths::path_buffer_pool::get(); | ||
| let Some(unzip_exe) = which( | ||
| &mut unzip_path_buf, | ||
| let Some(unzip_argv) = find_unzip_argv( | ||
| env_loader.map.get(b"PATH").unwrap_or(b""), | ||
| filesystem.top_level_dir, | ||
| b"unzip", | ||
| tmpname.as_bytes(), | ||
| ) else { | ||
| let _ = sys::unlinkat(&save_dir, tmpname); | ||
| bun_core::pretty_errorln!( | ||
| "<r><red>error:<r> Failed to locate \"unzip\" in PATH. bun upgrade needs \"unzip\" to work." | ||
| "<r><red>error:<r> Failed to locate \"unzip\" in PATH. bun upgrade needs \"unzip\" to work (7z, busybox, bsdtar, python3 supported)." | ||
| ); | ||
| Global::exit(1); | ||
| }; | ||
|
|
||
| // We could just embed libz2 | ||
| // however, we want to be sure that xattrs are preserved | ||
| // xattrs are used for codesigning | ||
| // it'd be easy to mess that up | ||
| let unzip_argv: [&[u8]; 4] = | ||
| [unzip_exe.as_bytes(), b"-q", b"-o", tmpname.as_bytes()]; | ||
|
|
||
| let unzip_result = match spawn_sync::spawn(&spawn_sync::Options { | ||
| argv: build_argv(&unzip_argv), | ||
| argv: unzip_argv, | ||
| envp: None, | ||
| cwd: Box::<[u8]>::from(&tmpdir_path_buf[..tmpdir_path_len]), | ||
| stdin: spawn_sync::SyncStdio::Inherit, | ||
|
Comment on lines
937
to
941
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 nit (optional): users whose only extractor is 7z/7zz/7za see 7-Zip's banner and file listing in the middle of Extended reasoning...UNZIP_PROGRAMS rows for 7z, 7zz and 7za (upgrade_command.rs:90-104) pass only Verification: nit — triggers when |
||
|
|
@@ -883,6 +964,25 @@ impl UpgradeCommand { | |
| Global::exit(1); | ||
| } | ||
| } | ||
|
|
||
| // `python3 -m zipfile` does not restore the file mode, and | ||
| // some busybox builds do not either. | ||
|
Comment on lines
+991
to
+992
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| let exe_z: &ZStr = ZStr::from_static(if use_profile { | ||
| const_format::concatcp!(UpgradeCommand::PROFILE_EXE_SUBPATH, "\0") | ||
| .as_bytes() | ||
| } else { | ||
| const_format::concatcp!(UpgradeCommand::EXE_SUBPATH, "\0").as_bytes() | ||
| }); | ||
| if let Err(err) = sys::fchmodat(&save_dir, exe_z, 0o755, 0) { | ||
| let _ = sys::unlinkat(&save_dir, tmpname); | ||
| let _ = save_dir_.delete_tree(&version_name); | ||
| bun_core::pretty_errorln!( | ||
| "<r><red>error:<r> Failed to set permissions on {} due to {}.", | ||
| bstr::BStr::new(exe), | ||
| bstr::BStr::new(err.name()) | ||
| ); | ||
| Global::exit(1); | ||
| } | ||
| } | ||
| #[cfg(windows)] | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.