Skip to content

Commit 8f5d626

Browse files
authored
fix(install): add BusyBox compatibility fallback (#1032)
Fixes #1027 BusyBox's install command does not support -C (compare), -b (backup), or -S (backup suffix) flags. When these flags fail, fall back to: 1. Simple 'install -m 755' command 2. If install completely unavailable, use cp + chmod This allows croc to be installed in minimal Docker containers like debian:stable-slim, netshoot, alpine, etc. using the bash installer. Co-authored-by: Murat Aslan <[email protected]>
1 parent 281fe6e commit 8f5d626

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/install/default.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,12 @@ install_file_freebsd() {
417417
# NAME: install_file_linux
418418
# DESCRIPTION: Installs a file into a location using 'install'. If EUID not
419419
# 0, then attempt to use sudo (unless on android).
420+
# Falls back to cp/chmod for BusyBox compatibility.
420421
# PARAMETERS: $1 = file to install
421422
# $2 = location to install file into
422423
# RETURNS: 0 = File Installed
423424
# 1 = File not installed
424-
# 20 = Could not find install command
425+
# 20 = Could not find install or cp command
425426
# 21 = Could not find sudo command
426427
#-------------------------------------------------------------------------------
427428
install_file_linux() {
@@ -434,14 +435,31 @@ install_file_linux() {
434435

435436
if command -v install >/dev/null 2>&1; then
436437
if [[ "${EUID}" == "0" ]]; then
437-
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
438+
# Try GNU install first, fall back to simple install for BusyBox
439+
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}" 2>/dev/null || \
440+
install -m 755 "${file}" "${prefix}/"
438441
rcode="${?}"
439442
else
440443
if command -v sudo >/dev/null 2>&1; then
441-
sudo install -C -b -S '_old' -m 755 "${file}" "${prefix}"
444+
sudo install -C -b -S '_old' -m 755 "${file}" "${prefix}" 2>/dev/null || \
445+
sudo install -m 755 "${file}" "${prefix}/"
442446
rcode="${?}"
443447
elif [[ "${ANDROID_ROOT}" != "" ]]; then
444-
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}"
448+
install -C -b -S '_old' -m 755 -t "${prefix}" "${file}" 2>/dev/null || \
449+
install -m 755 "${file}" "${prefix}/"
450+
rcode="${?}"
451+
else
452+
rcode="21"
453+
fi
454+
fi
455+
elif command -v cp >/dev/null 2>&1; then
456+
# Fallback to cp/chmod if install is not available
457+
if [[ "${EUID}" == "0" ]]; then
458+
cp "${file}" "${prefix}/" && chmod 755 "${prefix}/$(basename "${file}")"
459+
rcode="${?}"
460+
else
461+
if command -v sudo >/dev/null 2>&1; then
462+
sudo cp "${file}" "${prefix}/" && sudo chmod 755 "${prefix}/$(basename "${file}")"
445463
rcode="${?}"
446464
else
447465
rcode="21"

0 commit comments

Comments
 (0)