diff --git a/.installer/packages b/.installer/packages index cd93f07..6b309c7 100644 --- a/.installer/packages +++ b/.installer/packages @@ -2,7 +2,7 @@ pacman-base:acpi wget curl # Required for setup_system.sh pacman-any:i3-gaps feh i3status network-manager-applet pasystray xautolock inotify-tools xss-lock noto-fonts-emoji pacman-any:zsh tmux code vim ufw scrot dunst arandr ranger thunar flameshot pacman-any:gst-libav phonon-qt5-gstreamer gst-plugins-good qt5-quickcontrols qt5-graphicaleffects qt5-multimedia -pacman-laptop:brightnessctl +pacman-type-hasbattery:brightnessctl aur-any:picom-git sddm-theme-aerial-git apt-base:acpi wget curl # Required for setup_system.sh @@ -13,11 +13,11 @@ apt-any:python3 python3-pip apt-any:sddm gstreamer1.0-libav phonon4qt5-backend-gstreamer gstreamer1.0-plugins-good qml-module-qtquick-controls qml-module-qtgraphicaleffects qml-module-qtmultimedia apt-any:cargo cmake pkg-config libfreetype6-dev libfontconfig1-dev libxcb-xfixes0-dev libxkbcommon-dev python3 apt-any:libxcb-render0-dev libffi-dev python3-dev python3-cffi -apt-any:libpam-u2f -apt-laptop:brightnessctl +apt-any:libpam-u2f # For YubiKey +apt-type-hasbattery:brightnessctl pip-any:flashfocus -brew-any:azure-cli +brew-host-5cg9521pyj:azure-cli brew-any:kubectl helm shellcheck velero azure/kubelogin/kubelogin derailed/k9s/k9s fluxcd/tap/flux weaveworks/tap/gitops # Kubernetes related brew-any:zsh-autosuggestions zsh-history-substring-search zsh-syntax-highlighting # ZSH related diff --git a/setup_system.sh b/setup_system.sh index dc12b63..30dcdbf 100755 --- a/setup_system.sh +++ b/setup_system.sh @@ -48,11 +48,11 @@ function _acpib() { acpi -b | grep -Fv ' 0%' } -function is_laptop() { +function has_battery() { [[ $(_acpib | wc -l) -gt 0 ]] && return 0 || return 1 } -# Returns a comma-separated list of packages for one or more targets. +# Returns a list of packages for one or more targets. # The packages file may contain multiple rows with the same target name. function get_packages() { local pkg_file="$script_dir/.installer/packages" @@ -66,6 +66,21 @@ function get_packages() { done } +# Return a list of targets for a given package manager +function construct_target_list() { + local package_manager=${1:?package_manager not set} targets=() + + targets+=("$package_manager-any") + targets+=("$package_manager-host-$(hostname | cut -d. -f1)") + has_battery && targets+=("$package_manager-type-hasbattery") + echo "${targets[@],,}" # Return lowercase +} + +function setup_pip_packages() { + # shellcheck disable=SC2046 + sudo pip3 install $(get_packages $(construct_target_list pip)) --no-input || return 1 +} + function install_sddm_aerial_theme() { local theme_dir="/usr/share/sddm/themes/aerial" @@ -148,11 +163,10 @@ function setup_homebrew() { } function setup_brew_formulas() { - local targets=("brew-any") - brew update || return 1 - for package in $(get_packages "${targets[@]}"); do + # shellcheck disable=SC2046 + for package in $(get_packages $(construct_target_list brew)); do if brew list --full-name | grep -Eq "(^| )$package($| )" >/dev/null; then if $upgrade_packages; then echo "Package '$package' will be upgraded." @@ -188,7 +202,8 @@ function setup_krew_plugins() { return 1 fi - for package in $(get_packages "${targets[@]}"); do + # shellcheck disable=SC2046 + for package in $(get_packages $(construct_target_list krew)); do if kubectl-krew list | grep -q "^$package$" >/dev/null; then if $upgrade_packages; then echo "Package '$package' will be upgraded." @@ -231,19 +246,13 @@ function prepare_arch() { } function setup_arch_with_pamac() { - local targets=("pacman-any") packages - is_laptop && targets+=("pacman-laptop") - - packages="$(get_packages "${targets[@]}")" - # shellcheck disable=SC2086 - sudo pamac install $packages --no-confirm || return 1 + # shellcheck disable=SC2046 + sudo pamac install $(get_packages $(construct_target_list pacman)) --no-confirm || return 1 } function setup_arch_with_yay() { - local targets=("aur-any") packages - is_laptop && targets+=("aur-laptop") - - for package in $(get_packages "${targets[@]}"); do + # shellcheck disable=SC2046 + for package in $(get_packages $(construct_target_list aur)); do if pacman -Qs "^$package$" >/dev/null; then if $upgrade_packages; then echo "Package '$package' will be upgraded." @@ -259,19 +268,11 @@ function setup_arch_with_yay() { done } -function setup_arch_with_pip() { - local targets=("pip-any") packages - - packages="$(get_packages "${targets[@]}")" - # shellcheck disable=SC2086 - sudo pip3 install $packages --no-input || return 1 -} - function setup_arch() { prepare_arch || return 1 setup_arch_with_pamac || return 2 setup_arch_with_yay || return 3 - setup_arch_with_pip || return 4 + setup_pip_packages || return 4 configure_sddm || return 5 configure_ufw || return 6 setup_homebrew || return 7 @@ -295,44 +296,28 @@ function setup_debian_repo_vscodium() { } function setup_debian_base_with_apt() { - local targets packages - - targets=("apt-base") - packages="$(get_packages "${targets[@]}")" sudo apt-get update - # shellcheck disable=SC2086 - sudo apt-get install $packages -y || return 1 + # shellcheck disable=SC2046 + sudo apt-get install $(get_packages apt-base) -y || return 1 } function setup_debian_with_apt() { - local targets packages - - targets=("apt-any") - is_laptop && targets+=("apt-laptop") - packages="$(get_packages "${targets[@]}")" sudo apt-get update - # shellcheck disable=SC2086 - sudo apt-get install $packages -y || return 2 -} - -function setup_debian_with_pip() { - local targets=("pip-any") packages - - packages="$(get_packages "${targets[@]}")" - # shellcheck disable=SC2086 - sudo pip3 install $packages --no-input || return 1 + # shellcheck disable=SC2046 + sudo apt-get install $(get_packages $(construct_target_list apt)) -y || return 2 } function setup_debian_with_git() { install_picom || return 1 install_sddm_aerial_theme || return 2 + build_alacritty || return 3 } function setup_debian() { setup_debian_base_with_apt || return 1 setup_debian_repo_vscodium || return 2 setup_debian_with_apt || return 3 - setup_debian_with_pip || return 4 + setup_pip_packages || return 4 setup_debian_with_git || return 5 configure_sddm || return 6 configure_ufw || return 7 @@ -340,8 +325,7 @@ function setup_debian() { setup_brew_formulas || return 9 setup_krew || return 10 setup_krew_plugins || return 11 - build_alacritty || return 12 - change_shell || return 13 + change_shell || return 12 } if [ "$EUID" -eq 0 ]; then