diff --git a/install.sh b/install.sh index 2e96783..84143e3 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. @@ -62,8 +62,9 @@ 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) echo "x86_64-unknown-linux-musl" @@ -87,7 +88,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 @@ -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!" @@ -203,10 +206,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 +428,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 +448,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 +470,19 @@ 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 - + + # 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 '' >> ~/.bashrc cat >> ~/.bashrc <> ~/.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 '' >> ~/.bashrc cat >> ~/.bashrc <