devbox icon indicating copy to clipboard operation
devbox copied to clipboard

[Feature]: allow for "doas" instead of "sudo" for the install script

Open markjoshwel opened this issue 2 years ago • 0 comments

Is your feature request related to a problem you're trying to solve? Please describe. Although admittedly niche, “doas” is an alternative privilege escalation tool to “sudo” for users who want a lighter and easier-to-configure version of sudo. I've been using it on my distributions for a long time. As such, installation scripts that hard require sudo can be a pain point especially when trying to quickly set up systems.

Describe the solution you'd like Perhaps check for sudo or doas and use whatever's available? I've added the necessary code and a potential implementation as a diff below:

if command -v sudo; then
	SUDO="sudo"
elif command -v doas; then
	SUDO="doas"
fi
--- devbox-original
+++ devbox
@@ -170,6 +170,15 @@
        return $rc
 }
 
+# ======================
+# Check for sudo or doas
+# ======================
+if command -v sudo; then
+       SUDO="sudo"
+elif command -v doas; then
+       SUDO="doas"
+fi
+
 # ==============
 # Implementation
 # ==============
@@ -184,7 +193,7 @@
 }
 
 install_flow() {
-       confirm "Install ${GREEN}${BIN}${NO_COLOR} to ${GREEN}${INSTALL_DIR}${NO_COLOR} (requires sudo)?"
+       confirm "Install ${GREEN}${BIN}${NO_COLOR} to ${GREEN}${INSTALL_DIR}${NO_COLOR} (requires ${SUDO})?"
        printf "\n"
        header "Downloading and Installing"
 
@@ -194,9 +203,9 @@
        delay
        end_task "Downloading ${BIN} binary"
 
-       start_task "Installing in ${INSTALL_DIR}/${BIN} (requires sudo)"
+       start_task "Installing in ${INSTALL_DIR}/${BIN} (requires ${SUDO})"
        chmod +x "${tmp_file}"
-       $(command -v sudo || true) bash -c "mkdir -p ${INSTALL_DIR} && mv ${tmp_file} ${INSTALL_DIR}/${BIN}"
+       $(command -v ${SUDO} || true) bash -c "mkdir -p ${INSTALL_DIR} && mv ${tmp_file} ${INSTALL_DIR}/${BIN}"
        delay
        end_task "Installing in ${INSTALL_DIR}/${BIN}"
        delay
(surplus-py3.11) csp:~$ mv devbox devbox-doas
(surplus-py3.11) csp:~$ mv devbox-original devbox
(surplus-py3.11) csp:~$ diff devbox devbox-doas
--- devbox
+++ devbox-doas
@@ -170,6 +170,15 @@
        return $rc
 }
 
+# ======================
+# Check for sudo or doas
+# ======================
+if command -v sudo; then
+       SUDO="sudo"
+elif command -v doas; then
+       SUDO="doas"
+fi
+
 # ==============
 # Implementation
 # ==============
@@ -184,7 +193,7 @@
 }
 
 install_flow() {
-       confirm "Install ${GREEN}${BIN}${NO_COLOR} to ${GREEN}${INSTALL_DIR}${NO_COLOR} (requires sudo)?"
+       confirm "Install ${GREEN}${BIN}${NO_COLOR} to ${GREEN}${INSTALL_DIR}${NO_COLOR} (requires ${SUDO})?"
        printf "\n"
        header "Downloading and Installing"
 
@@ -194,9 +203,9 @@
        delay
        end_task "Downloading ${BIN} binary"
 
-       start_task "Installing in ${INSTALL_DIR}/${BIN} (requires sudo)"
+       start_task "Installing in ${INSTALL_DIR}/${BIN} (requires ${SUDO})"
        chmod +x "${tmp_file}"
-       $(command -v sudo || true) bash -c "mkdir -p ${INSTALL_DIR} && mv ${tmp_file} ${INSTALL_DIR}/${BIN}"
+       $(command -v ${SUDO} || true) bash -c "mkdir -p ${INSTALL_DIR} && mv ${tmp_file} ${INSTALL_DIR}/${BIN}"
        delay
        end_task "Installing in ${INSTALL_DIR}/${BIN}"
        delay

Describe alternatives you've considered I have tried setting an alias to no avail, and currently just Control+F and replace “sudo” with “doas” after curl-ing the installation script. (Still an inconvenience)

Additional context

csp:~$ sudo
/bin/ash: sudo: not found
csp:~$ doas
usage: doas [-Lns] [-C config] [-u user] command [args]
csp:~$ curl -fsSL https://get.jetpack.io/devbox | bash
Devbox 📦 by jetpack.io
  Instant and predictable development environments and containers.

  This script downloads and installs the latest devbox binary.

Confirm Installation Details
  Location:     /usr/local/bin/devbox
  Download URL: https://releases.jetpack.io/devbox

? Install devbox to /usr/local/bin (requires sudo)? [Y/n] y

Downloading and Installing
✓ Downloading devbox binary... [DONE]
→ Installing in /usr/local/bin/devbox (requires sudo)...
mv: can't rename '/tmp/tmp.pFLgEm': Permission denied

markjoshwel avatar Oct 14 '23 16:10 markjoshwel