From 93114e794920f287958f3065f47e48e16cece138 Mon Sep 17 00:00:00 2001 From: Dylan Northrup Date: Wed, 14 May 2025 08:37:37 -0400 Subject: [PATCH 1/7] Remove end of line spaces --- install.sh | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/install.sh b/install.sh index 2e96783..b8b76ab 100644 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ set -euo pipefail # Rootless-DevBox Installer -# +# # This script automates the installation of DevBox in a rootless environment # using nix-user-chroot without requiring root privileges. # @@ -45,7 +45,7 @@ print_error() { check_user_namespace_support() { print_step "Checking system compatibility" echo "Verifying if your system supports unprivileged user namespaces (required for nix-user-chroot)..." - + if ! unshare --user --pid echo "YES" &>/dev/null; then print_error "Your system does not support unprivileged user namespaces, which is required for nix-user-chroot to work. @@ -63,7 +63,7 @@ For more information, see: https://github.com/nix-community/nix-user-chroot" # Detect system architecture get_architecture() { local arch=$(uname -m) - + case "$arch" in x86_64) echo "x86_64-unknown-linux-musl" @@ -87,7 +87,7 @@ get_architecture() { download_file() { local url="$1" local output_file="$2" - + if command -v curl &>/dev/null; then curl -fsSL "$url" -o "$output_file" || return 1 elif command -v wget &>/dev/null; then @@ -203,10 +203,10 @@ EOF # Step 6: Continue with DevBox installation process print_step "Preparing DevBox installation" - + local devbox_install_script="${temp_dir}/devbox_install_user.sh" - local permanent_devbox_install_script="${HOME}/devbox_install_user.sh" - + local permanent_devbox_install_script="${HOME}/devbox_install_user.sh" + cat > "$devbox_install_script" <<'EOF' #!/bin/bash # @@ -425,16 +425,16 @@ main() { main "$@" EOF - + chmod +x "$devbox_install_script" cp "$devbox_install_script" "$permanent_devbox_install_script" chmod +x "$permanent_devbox_install_script" print_success "Created DevBox installation script: ${devbox_install_script}" print_success "Created permanent backup at: ${permanent_devbox_install_script}" - + # Step 7: Set Nix mirror if needed set_nix_mirror_if_needed - + echo "" echo_color "$BOLD" "Next: Activate Nix Environment and Install DevBox" echo_color "$BOLD" "⚠️ IMPORTANT: Installation requires TWO steps! ⚠️" @@ -445,16 +445,16 @@ EOF echo "" echo "Would you like this script to attempt to run '${local_bin_dir}/nix-chroot' for you now? [Y/n]" echo_color "$GREY" "(If you choose yes, after nix-chroot starts, you MUST MANUALLY run the second command shown above)" - + if [ -t 0 ]; then read -r response else response="y" echo "Non-interactive mode detected. Defaulting to 'y'." fi - + response=${response:-y} - + if [[ "$response" =~ ^[Yy] ]]; then echo "" echo_color "$CYAN" "Attempting to start ${local_bin_dir}/nix-chroot..." @@ -467,16 +467,16 @@ EOF if [ ! -x "${local_bin_dir}/nix-chroot" ]; then print_error "${local_bin_dir}/nix-chroot not found or not executable. Please check previous steps." fi - + if ! grep -qF 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' ~/.bashrc; then echo '' >> ~/.bashrc echo '# Added by Rootless-DevBox installer' >> ~/.bashrc echo 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' >> ~/.bashrc echo "Added ~/.local/bin to PATH in ~/.bashrc" fi - + if ! grep -qF '# Rootless-DevBox nix-chroot environment indicator' ~/.bashrc; then - echo '' >> ~/.bashrc + echo '' >> ~/.bashrc cat >> ~/.bashrc <> ~/.bashrc @@ -521,9 +521,9 @@ EOF else echo "~/.local/bin PATH entry by Rootless-DevBox already in ~/.bashrc." fi - + if ! grep -qF '# Rootless-DevBox nix-chroot environment indicator' ~/.bashrc; then - echo '' >> ~/.bashrc + echo '' >> ~/.bashrc cat >> ~/.bashrc < Date: Wed, 14 May 2025 08:41:38 -0400 Subject: [PATCH 2/7] Silence single quote warnings where interpolation is intentionally disabled --- install.sh | 2 ++ uninstall.sh | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b8b76ab..fa78569 100644 --- a/install.sh +++ b/install.sh @@ -468,6 +468,7 @@ EOF print_error "${local_bin_dir}/nix-chroot not found or not executable. Please check previous steps." fi + # shellcheck disable=2016 if ! grep -qF 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' ~/.bashrc; then echo '' >> ~/.bashrc echo '# Added by Rootless-DevBox installer' >> ~/.bashrc @@ -512,6 +513,7 @@ EOF print_step "Configuring environment variables in ~/.bashrc" local bashrc_modified_count=0 + # shellcheck disable=2016 if ! grep -qF 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' ~/.bashrc; then echo '' >> ~/.bashrc echo '# Added by Rootless-DevBox installer' >> ~/.bashrc diff --git a/uninstall.sh b/uninstall.sh index fff42c4..ff77a2e 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -80,6 +80,7 @@ main() { local nix_user_chroot_path="${local_bin_dir}/nix-user-chroot" # Check if any component is installed + # shellcheck disable=2016 if [ ! -f "$devbox_path" ] && \ [ ! -f "$nix_chroot_path" ] && \ [ ! -f "$nix_user_chroot_path" ] && \ @@ -205,4 +206,4 @@ main() { # Run the main function main "$@" -exit 0 \ No newline at end of file +exit 0 From 34cfbd6fff28a154e0f6d03d46306f566e8dc2df Mon Sep 17 00:00:00 2001 From: Dylan Northrup Date: Wed, 14 May 2025 08:42:54 -0400 Subject: [PATCH 3/7] Commenting out unused "GREY" variable in uninstall script --- uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.sh b/uninstall.sh index ff77a2e..a0cf7fe 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -13,7 +13,7 @@ BLUE="\033[0;34m" YELLOW="\033[0;33m" RED="\033[0;31m" RESET="\033[0m" -GREY="\033[90m" +# GREY="\033[90m" CYAN="\033[0;36m" # Echo with color From 5812c7c2c527bceeb21713deaf9a692fbd2b2cd5 Mon Sep 17 00:00:00 2001 From: Dylan Northrup Date: Wed, 14 May 2025 08:44:52 -0400 Subject: [PATCH 4/7] SC2129: Favor using redirection of multiple lines vs multiple redirections of single lines --- install.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index fa78569..01e7f7d 100644 --- a/install.sh +++ b/install.sh @@ -470,9 +470,11 @@ EOF # shellcheck disable=2016 if ! grep -qF 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' ~/.bashrc; then - echo '' >> ~/.bashrc - echo '# Added by Rootless-DevBox installer' >> ~/.bashrc - echo 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' >> ~/.bashrc + cat >> "${HOME}/.bashrc" <> ~/.bashrc - echo '# Added by Rootless-DevBox installer' >> ~/.bashrc - echo 'export PATH="$HOME/.local/bin:$PATH" # Added by Rootless-DevBox' >> ~/.bashrc + cat >> "${HOME}/.bashrc" < Date: Wed, 14 May 2025 08:52:06 -0400 Subject: [PATCH 5/7] Silence single quote warnings where they are intentional --- uninstall.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/uninstall.sh b/uninstall.sh index a0cf7fe..5fbdff1 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -111,6 +111,7 @@ main() { if [ ! -f "$bashrc_file" ]; then print_warning "${bashrc_file} not found. Skipping .bashrc modifications." else + # shellcheck disable=SC2016 if grep -qE '(# Added by Rootless-DevBox installer|export PATH="\$HOME/\.local/bin:\$PATH" # Added by Rootless-DevBox|# Rootless-DevBox nix-chroot environment indicator)' "$bashrc_file"; then local bashrc_backup="${HOME}/.bashrc.devbox_uninstall_$(date +%Y%m%d%H%M%S).bak" echo "Modifying ${bashrc_file} to remove Rootless-DevBox configurations." From 75751fb45c023e5d0f51f5c9beb3855e23150ee1 Mon Sep 17 00:00:00 2001 From: Dylan Northrup Date: Wed, 14 May 2025 08:52:35 -0400 Subject: [PATCH 6/7] SC2088: Add disable lines for warning on user output lines --- install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.sh b/install.sh index 01e7f7d..84c870b 100644 --- a/install.sh +++ b/install.sh @@ -525,6 +525,7 @@ EOF echo "Added ~/.local/bin to PATH in ~/.bashrc" ((bashrc_modified_count++)) else + # shellcheck disable=SC2088 echo "~/.local/bin PATH entry by Rootless-DevBox already in ~/.bashrc." fi @@ -539,6 +540,7 @@ EOF echo "Added nix-chroot environment indicator to ~/.bashrc" ((bashrc_modified_count++)) else + # shellcheck disable=SC2088 echo "nix-chroot environment indicator already in ~/.bashrc." fi @@ -546,6 +548,7 @@ EOF print_success "Configuration changes applied to ~/.bashrc." echo "Please run 'source ~/.bashrc' or open a new terminal for these changes to take full effect." else + # shellcheck disable=SC2088 print_success "~/.bashrc already contains the necessary configurations or no changes were made." fi echo "" From 1d43df17fc7d9ea77f189e063fa93f1534c20699 Mon Sep 17 00:00:00 2001 From: Dylan Northrup Date: Wed, 14 May 2025 08:53:42 -0400 Subject: [PATCH 7/7] SC2155: Declare and assign separately to avoid masking return values --- install.sh | 9 ++++++--- uninstall.sh | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 84c870b..84143e3 100644 --- a/install.sh +++ b/install.sh @@ -62,7 +62,8 @@ For more information, see: https://github.com/nix-community/nix-user-chroot" # Detect system architecture get_architecture() { - local arch=$(uname -m) + local arch + arch=$(uname -m) case "$arch" in x86_64) @@ -130,8 +131,10 @@ main() { local nix_user_chroot_path="${local_bin_dir}/nix-user-chroot" local nix_dir="${HOME}/.nix" local nix_user_chroot_version="1.2.2" - local arch=$(get_architecture) - local temp_dir=$(create_temp_dir) + local arch + local temp_dir + arch=$(get_architecture) + temp_dir=$(create_temp_dir) if [ -x "$devbox_path" ] && [ -x "$nix_chroot_path" ] && [ -x "$nix_user_chroot_path" ]; then echo_color "$GREEN" "All components are already installed!" diff --git a/uninstall.sh b/uninstall.sh index 5fbdff1..f0b863e 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -113,7 +113,8 @@ main() { else # shellcheck disable=SC2016 if grep -qE '(# Added by Rootless-DevBox installer|export PATH="\$HOME/\.local/bin:\$PATH" # Added by Rootless-DevBox|# Rootless-DevBox nix-chroot environment indicator)' "$bashrc_file"; then - local bashrc_backup="${HOME}/.bashrc.devbox_uninstall_$(date +%Y%m%d%H%M%S).bak" + local bashrc_backup + bashrc_backup="${HOME}/.bashrc.devbox_uninstall_$(date +%Y%m%d%H%M%S).bak" echo "Modifying ${bashrc_file} to remove Rootless-DevBox configurations." echo "Backing up current ${bashrc_file} to ${bashrc_backup}" if cp "${bashrc_file}" "${bashrc_backup}"; then