diff --git a/script/install.d/00-os.sh b/script/install.d/00-os.sh index e36f5c1..761729e 100644 --- a/script/install.d/00-os.sh +++ b/script/install.d/00-os.sh @@ -2,13 +2,36 @@ # ----------------------------------------------------------------------------- # Description: -# Print operating system information. +# Print operating system information and hint which installer path will run. # if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS info sw_vers + log_info "Detected macOS (OSTYPE=$OSTYPE)" + log_info "Package manager: Homebrew (brew)" + log_info "Code path: macOS-only brew scripts will run; Linux package scripts are skipped." + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - cat /etc/os-release + # Linux info + if [[ -r /etc/os-release ]]; then + cat /etc/os-release + # shellcheck source=/dev/null + . /etc/os-release + fi + + log_info "Detected Linux (OSTYPE=$OSTYPE, ID=${ID:-unknown}, ID_LIKE=${ID_LIKE:-n/a}, NAME=${NAME:-n/a}, VERSION_ID=${VERSION_ID:-n/a})" + + if command -v apt-get >/dev/null 2>&1; then + log_info "Package manager detected: apt-get" + export DOTS_PKG_MGR=apt + elif command -v pacman >/dev/null 2>&1; then + log_info "Package manager detected: pacman" + export DOTS_PKG_MGR=pacman + else + log_warn "No known package manager (apt-get/pacman) found on Linux." + fi + else log_error "Unknown OS: $OSTYPE" fi diff --git a/script/install.d/03-pacman.sh b/script/install.d/03-pacman.sh new file mode 100644 index 0000000..b4d5ca7 --- /dev/null +++ b/script/install.d/03-pacman.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# ----------------------------------------------------------------------------- +# Description: +# (distros with pacman only) Install core pacman packages. +# + +if command -v pacman &> /dev/null; then + pacman_packages=( + ca-certificates + curl + gnupg + wget + base-devel + ) + + sudo pacman -Sy --noconfirm + sudo pacman -S --noconfirm --needed "${pacman_packages[@]}" + + unset pacman_packages + + pacman --version +else + log_warn "Skipping: pacman not found" +fi diff --git a/script/install.d/04-git.sh b/script/install.d/04-git.sh index 47569d3..26e7e30 100644 --- a/script/install.d/04-git.sh +++ b/script/install.d/04-git.sh @@ -7,7 +7,13 @@ if ! command -v git &> /dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq git + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq git + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm git + else + log_warn "Skipping git install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install git fi diff --git a/script/install.d/05-zsh.sh b/script/install.d/05-zsh.sh index 2e4ae2b..a832347 100644 --- a/script/install.d/05-zsh.sh +++ b/script/install.d/05-zsh.sh @@ -8,7 +8,13 @@ # install zsh if ! command -v zsh &> /dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq zsh + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq zsh + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm zsh + else + log_warn "Skipping zsh install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install zsh fi diff --git a/script/install.d/06-stow.sh b/script/install.d/06-stow.sh index 8a909c4..39ef12f 100644 --- a/script/install.d/06-stow.sh +++ b/script/install.d/06-stow.sh @@ -7,7 +7,13 @@ if ! command -v stow &> /dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq stow + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq stow + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm stow + else + log_warn "Skipping stow install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install stow fi diff --git a/script/install.d/10-pyenv.sh b/script/install.d/10-pyenv.sh index b117408..dc5bd62 100644 --- a/script/install.d/10-pyenv.sh +++ b/script/install.d/10-pyenv.sh @@ -11,15 +11,25 @@ if ! echo "$PATH" | grep -q "$PYENV_ROOT"; then fi if ! command -v pyenv &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - # https://github.com/pyenv/pyenv/wiki#suggested-build-environment - sudo apt-get install -qq build-essential libssl-dev zlib1g-dev \ - libbz2-dev libreadline-dev libsqlite3-dev curl \ - libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev + if command -v apt-get >/dev/null 2>&1; then + # https://github.com/pyenv/pyenv/wiki#suggested-build-environment + sudo apt-get install -qq build-essential libssl-dev zlib1g-dev \ + libbz2-dev libreadline-dev libsqlite3-dev curl \ + libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev - # see https://github.com/pyenv/pyenv-installer - bash -c "$(curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer)" - - unset pyenv_packages + # see https://github.com/pyenv/pyenv-installer + bash -c "$(curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer)" + elif command -v pacman >/dev/null 2>&1; then + # Prefer native packages if available; otherwise install build deps then use installer + if ! sudo pacman -Qi pyenv >/dev/null 2>&1; then + sudo pacman -S --noconfirm --needed base-devel openssl zlib bzip2 readline sqlite xz tk libffi curl + bash -c "$(curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer)" + else + sudo pacman -S --noconfirm --needed pyenv pyenv-virtualenv + fi + else + log_warn "Skipping pyenv install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install pyenv brew install pyenv-virtualenv diff --git a/script/install.d/11-python.sh b/script/install.d/11-python.sh index 62f26e8..6fc3eff 100644 --- a/script/install.d/11-python.sh +++ b/script/install.d/11-python.sh @@ -40,7 +40,13 @@ unset local_bin_path if ! command -v pipx &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq pipx + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq pipx + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm python-pipx + else + log_warn "Skipping pipx install: no apt-get or pacman found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install pipx fi diff --git a/script/install.d/20-docker.sh b/script/install.d/20-docker.sh index aad327d..4cc79df 100644 --- a/script/install.d/20-docker.sh +++ b/script/install.d/20-docker.sh @@ -27,17 +27,23 @@ fi if [[ -z "$SKIP_DOCKER_CONFIG" ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then if ! command -v docker &> /dev/null; then - sudo install -m 0755 -d /etc/apt/keyrings - sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc - sudo chmod a+r /etc/apt/keyrings/docker.asc + if command -v apt-get >/dev/null 2>&1; then + sudo install -m 0755 -d /etc/apt/keyrings + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + sudo chmod a+r /etc/apt/keyrings/docker.asc - echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - sudo apt-get update + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update - sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm --needed docker docker-buildx docker-compose + else + log_warn "Skipping Docker install: no supported package manager found" + fi fi readonly docker_group="docker" diff --git a/script/install.d/21-gh.sh b/script/install.d/21-gh.sh index a40174e..fd7f338 100644 --- a/script/install.d/21-gh.sh +++ b/script/install.d/21-gh.sh @@ -7,12 +7,18 @@ if ! command -v gh &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - # https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt - sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null && - sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null && - sudo apt-get update -qq && - sudo apt-get install -qq gh + if command -v apt-get >/dev/null 2>&1; then + # https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt + sudo mkdir -p -m 755 /etc/apt/keyrings && wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null && + sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null && + sudo apt-get update -qq && + sudo apt-get install -qq gh + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm github-cli + else + log_warn "Skipping GitHub CLI install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install gh fi diff --git a/script/install.d/22-azure.sh b/script/install.d/22-azure.sh index 02a8d2e..9081289 100644 --- a/script/install.d/22-azure.sh +++ b/script/install.d/22-azure.sh @@ -7,8 +7,18 @@ if ! command -v az &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - # https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + if command -v apt-get >/dev/null 2>&1; then + # https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt + curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + elif command -v pacman >/dev/null 2>&1; then + if command -v yay >/dev/null 2>&1; then + yay -S --noconfirm azure-cli-bin || log_warn "AUR install failed for azure-cli-bin" + else + log_warn "Skipping Azure CLI: no AUR helper found" + fi + else + log_warn "Skipping Azure CLI install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install azure-cli fi diff --git a/script/install.d/25-terraform.sh b/script/install.d/25-terraform.sh index 32797dd..e46bb2d 100644 --- a/script/install.d/25-terraform.sh +++ b/script/install.d/25-terraform.sh @@ -7,15 +7,21 @@ if ! command -v terraform &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - terraform_keyring_path="/usr/share/keyrings/hashicorp-archive-keyring.gpg" - if [[ ! -f "$terraform_keyring_path" ]]; then - curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o "$terraform_keyring_path" + if command -v apt-get >/dev/null 2>&1; then + terraform_keyring_path="/usr/share/keyrings/hashicorp-archive-keyring.gpg" + if [[ ! -f "$terraform_keyring_path" ]]; then + curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o "$terraform_keyring_path" + fi + echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \ + https://apt.releases.hashicorp.com $(lsb_release -cs) main" | + sudo tee /etc/apt/sources.list.d/hashicorp.list + sudo apt-get update -qq && + sudo apt-get install -qq terraform + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm terraform + else + log_warn "Skipping Terraform install: no supported package manager found" fi - echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \ - https://apt.releases.hashicorp.com $(lsb_release -cs) main" | - sudo tee /etc/apt/sources.list.d/hashicorp.list - sudo apt-get update -qq && - sudo apt-get install -qq terraform elif [[ "$OSTYPE" == "darwin"* ]]; then brew tap hashicorp/tap brew install hashicorp/tap/terraform diff --git a/script/install.d/50-redis.sh b/script/install.d/50-redis.sh index 1bf3a3a..ab07c26 100644 --- a/script/install.d/50-redis.sh +++ b/script/install.d/50-redis.sh @@ -7,13 +7,19 @@ if ! command -v redis-cli &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - redis_keyring_path="/usr/share/keyrings/redis-archive-keyring.gpg" - if [[ ! -f "$redis_keyring_path" ]]; then - curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o "$redis_keyring_path" + if command -v apt-get >/dev/null 2>&1; then + redis_keyring_path="/usr/share/keyrings/redis-archive-keyring.gpg" + if [[ ! -f "$redis_keyring_path" ]]; then + curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o "$redis_keyring_path" + fi + echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" \ + | sudo tee /etc/apt/sources.list.d/redis.list > /dev/null + sudo apt-get install -qq redis + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm redis + else + log_warn "Skipping Redis install: no supported package manager found" fi - echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" \ - | sudo tee /etc/apt/sources.list.d/redis.list > /dev/null - sudo apt-get install -qq redis elif [[ "$OSTYPE" == "darwin"* ]]; then brew install redis fi diff --git a/script/install.d/80-neofetch.sh b/script/install.d/80-neofetch.sh index 499170c..c0c33e9 100644 --- a/script/install.d/80-neofetch.sh +++ b/script/install.d/80-neofetch.sh @@ -7,7 +7,13 @@ if ! command -v neofetch &>/dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq neofetch &>/dev/null + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq neofetch &>/dev/null + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm neofetch &>/dev/null + else + log_warn "Skipping neofetch install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install neofetch fi diff --git a/script/install.d/81-cmatrix.sh b/script/install.d/81-cmatrix.sh index c7ed4fd..6f26ead 100644 --- a/script/install.d/81-cmatrix.sh +++ b/script/install.d/81-cmatrix.sh @@ -14,7 +14,13 @@ fi if [[ -z "$SKIP_CMATRIX_CONFIG" ]]; then if ! command -v cmatrix &> /dev/null; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get install -qq cmatrix &>/dev/null + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get install -qq cmatrix &>/dev/null + elif command -v pacman >/dev/null 2>&1; then + sudo pacman -S --noconfirm cmatrix &>/dev/null + else + log_warn "Skipping cmatrix install: no supported package manager found" + fi elif [[ "$OSTYPE" == "darwin"* ]]; then brew install cmatrix fi diff --git a/script/install.d/98-clean.sh b/script/install.d/98-clean.sh index be65f11..789f182 100644 --- a/script/install.d/98-clean.sh +++ b/script/install.d/98-clean.sh @@ -8,8 +8,19 @@ if [[ "$OSTYPE" == "darwin"* ]]; then brew cleanup elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - sudo apt-get autoremove -qq - sudo apt-get clean -qq + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get autoremove -qq + sudo apt-get clean -qq + elif command -v pacman >/dev/null 2>&1; then + # Remove orphans if any (ignore error if none) + if pacman -Qtdq >/dev/null 2>&1; then + sudo pacman -Rns --noconfirm $(pacman -Qtdq) || true + fi + # Clear package cache without interactive prompt + yes | sudo pacman -Scc >/dev/null 2>&1 || true + else + log_warn "Skipping cleanup: no supported package manager found" + fi fi log_pass "Cleanup completed successfully!"