add better error handling for install script, add --yes flag.
This commit is contained in:
parent
9e1bc68a32
commit
1658e9527a
168
install.sh
168
install.sh
|
|
@ -1,4 +1,17 @@
|
||||||
#!/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
trap 'log WARN "Interrupted by user"; exit 130' INT
|
||||||
|
|
||||||
|
INSTALL_STATUS="none" # none | partial | complete | failed
|
||||||
|
AUTO_YES=0
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--yes|--ci|--non-interactive)
|
||||||
|
AUTO_YES=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
local level="$1"
|
local level="$1"
|
||||||
|
|
@ -51,8 +64,8 @@ choose_packages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_style() {
|
prompt_style() {
|
||||||
gum style --border rounded \
|
gum style \
|
||||||
--border double \
|
--border rounded \
|
||||||
--padding "0 1" \
|
--padding "0 1" \
|
||||||
"$1"
|
"$1"
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +75,22 @@ gum_warn(){
|
||||||
}
|
}
|
||||||
|
|
||||||
gum_to_array() {
|
gum_to_array() {
|
||||||
mapfile -t "$1"
|
local -n arr="$1"
|
||||||
|
mapfile -t arr
|
||||||
|
local cleaned=()
|
||||||
|
for item in "${arr[@]}"; do
|
||||||
|
[[ -n "$item" ]] && cleaned+=("$item")
|
||||||
|
done
|
||||||
|
arr=("${cleaned[@]}")
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm() {
|
||||||
|
local msg="$1"
|
||||||
|
if ((AUTO_YES)); then
|
||||||
|
log INFO "[auto] $msg → yes"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
gum confirm --default=false "$msg"
|
||||||
}
|
}
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|
@ -92,7 +120,7 @@ You are STRONGLY ADVISED to back up:
|
||||||
Proceed at your OWN RISK."
|
Proceed at your OWN RISK."
|
||||||
)
|
)
|
||||||
|
|
||||||
gum confirm --default=false "$DISCLAIMER
|
confirm "$DISCLAIMER
|
||||||
|
|
||||||
Do you understand the risks and want to continue?" || exit 1
|
Do you understand the risks and want to continue?" || exit 1
|
||||||
|
|
||||||
|
|
@ -102,7 +130,11 @@ Do you understand the risks and want to continue?" || exit 1
|
||||||
###########
|
###########
|
||||||
source "$currentDir/packages/pkg_utils.sh"
|
source "$currentDir/packages/pkg_utils.sh"
|
||||||
prompt_style "Important utilities (Most likely go with defaults)"
|
prompt_style "Important utilities (Most likely go with defaults)"
|
||||||
gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
|
if ((AUTO_YES)); then
|
||||||
|
DEV_PKGS=("${pkg_utils[@]}")
|
||||||
|
else
|
||||||
|
gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
###############
|
###############
|
||||||
|
|
@ -110,7 +142,12 @@ gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
|
||||||
###############
|
###############
|
||||||
source "$currentDir/packages/pkg_dev_tools.sh"
|
source "$currentDir/packages/pkg_dev_tools.sh"
|
||||||
prompt_style "Select Development Tools"
|
prompt_style "Select Development Tools"
|
||||||
gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
|
if ((AUTO_YES)); then
|
||||||
|
DEV_PKGS=("${pkg_dev_tools[@]}")
|
||||||
|
else
|
||||||
|
gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
|
@ -118,7 +155,12 @@ gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
|
||||||
#######################
|
#######################
|
||||||
source "$currentDir/packages/pkg_optional.sh"
|
source "$currentDir/packages/pkg_optional.sh"
|
||||||
prompt_style "Select Optional Desktop Packages"
|
prompt_style "Select Optional Desktop Packages"
|
||||||
gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
|
if ((AUTO_YES)); then
|
||||||
|
OPTIONAL_PKGS=("${pkg_optional[@]}")
|
||||||
|
else
|
||||||
|
gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|
@ -126,7 +168,12 @@ gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
|
||||||
#################
|
#################
|
||||||
source "$currentDir/packages/pkg_gpu.sh"
|
source "$currentDir/packages/pkg_gpu.sh"
|
||||||
prompt_style "Select GPU drivers"
|
prompt_style "Select GPU drivers"
|
||||||
gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
|
if ((AUTO_YES)); then
|
||||||
|
GPU_PKGS=("${pkg_gpu[@]}")
|
||||||
|
else
|
||||||
|
gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
## Configure Everything ##
|
## Configure Everything ##
|
||||||
|
|
@ -139,9 +186,9 @@ WARNING=$(gum style \
|
||||||
"⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
|
"⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
|
||||||
Make sure you have already backed up all your existing config files (~/.config)")
|
Make sure you have already backed up all your existing config files (~/.config)")
|
||||||
|
|
||||||
if gum confirm --default=false "$WARNING
|
if confirm "$WARNING
|
||||||
|
|
||||||
Proceed with system configuration (stow, nvim, shell, keyd)?"; then
|
Proceed with system configuration (stow, shell)?"; then
|
||||||
###################
|
###################
|
||||||
## Stow dotfiles ##
|
## Stow dotfiles ##
|
||||||
###################
|
###################
|
||||||
|
|
@ -159,12 +206,13 @@ Proceed with system configuration (stow, nvim, shell, keyd)?"; then
|
||||||
printf ' %s\n' $conflicts
|
printf ' %s\n' $conflicts
|
||||||
read -rp "Proceed with deleting these files? (y/N): " ok
|
read -rp "Proceed with deleting these files? (y/N): " ok
|
||||||
if [[ ! "$ok" =~ ^[Yy]$ ]]; then
|
if [[ ! "$ok" =~ ^[Yy]$ ]]; then
|
||||||
echo "Aborted."
|
log WARN "Aborted."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove conflicts relative to $HOME
|
# Remove conflicts relative to $HOME
|
||||||
for path in $conflicts; do
|
for path in $conflicts; do
|
||||||
rm -rf "$HOME/$path" && log INFO "Removed $HOME/$path"
|
[[ -n "$path" && "$path" != "/" ]] && rm -rf "$HOME/$path" && log INFO "Deleted $path"
|
||||||
done
|
done
|
||||||
|
|
||||||
log INFO "Running stow..."
|
log INFO "Running stow..."
|
||||||
|
|
@ -173,22 +221,11 @@ Proceed with system configuration (stow, nvim, shell, keyd)?"; then
|
||||||
|| log ERROR "Stow failed"
|
|| log ERROR "Stow failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###########################
|
|
||||||
## Setup neovim dotfiles ##
|
|
||||||
###########################
|
|
||||||
log INFO "Setting up neovim configuration"
|
|
||||||
log INFO "Taking backup of neovim config (if already exists)"
|
|
||||||
mv ~/.config/nvim{,.bak}
|
|
||||||
mv ~/.local/share/nvim{,.bak}
|
|
||||||
mv ~/.local/state/nvim{,.bak}
|
|
||||||
mv ~/.cache/nvim{,.bak}
|
|
||||||
git clone --depth=1 https://github.com/krolyxon/nvim.git ~/.config/nvim
|
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
## Change default shell to zsh ##
|
## Change default shell to zsh ##
|
||||||
#################################
|
#################################
|
||||||
log INFO "Changing the default shell to ZSH"
|
log INFO "Changing the default shell to ZSH"
|
||||||
if [[ "$SHELL" != "$(which zsh)" ]]; then
|
if [[ "$SHELL" != "$(command -v zsh)" ]]; then
|
||||||
chsh -s $(which zsh) \
|
chsh -s $(which zsh) \
|
||||||
&& log SUCCESS "Default shell successfully set to zsh" \
|
&& log SUCCESS "Default shell successfully set to zsh" \
|
||||||
|| log ERROR "Default shell could not be set to zsh"
|
|| log ERROR "Default shell could not be set to zsh"
|
||||||
|
|
@ -205,26 +242,23 @@ fi
|
||||||
##################
|
##################
|
||||||
source "$currentDir/packages/pkg_aur.sh"
|
source "$currentDir/packages/pkg_aur.sh"
|
||||||
prompt_style "Select AUR packages"
|
prompt_style "Select AUR packages"
|
||||||
gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
|
|
||||||
if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
|
if ((AUTO_YES)); then
|
||||||
log WARN "No AUR packages selected"
|
AUR_PKGS=("${pkg_aur[@]}")
|
||||||
else
|
else
|
||||||
|
gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ((${#AUR_PKGS[@]})); then
|
||||||
if ! command -v paru >/dev/null 2>&1; then
|
if ! command -v paru >/dev/null 2>&1; then
|
||||||
log INFO "Installing Paru (AUR package manager)"
|
log INFO "Installing Paru (AUR package manager)"
|
||||||
git clone https://aur.archlinux.org/paru.git
|
git clone https://aur.archlinux.org/paru.git
|
||||||
cd paru
|
(cd paru && makepkg -sri)
|
||||||
makepkg -sri
|
|
||||||
cd ..
|
|
||||||
rm -rf paru
|
rm -rf paru
|
||||||
else
|
|
||||||
log INFO "Paru already in PATH, Skipping...."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
|
|
||||||
log WARN "No AUR packages selected, Skipping...."
|
|
||||||
else
|
|
||||||
paru -S --needed "${AUR_PKGS[@]}"
|
paru -S --needed "${AUR_PKGS[@]}"
|
||||||
fi
|
else
|
||||||
|
log WARN "No AUR packages selected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -232,7 +266,7 @@ fi
|
||||||
## Setup Keyd ##
|
## Setup Keyd ##
|
||||||
############################
|
############################
|
||||||
if command -v keyd >/dev/null 2>&1; then
|
if command -v keyd >/dev/null 2>&1; then
|
||||||
if gum confirm --default=false "Configure and enable keyd? "; then
|
if confirm "Configure and enable keyd? "; then
|
||||||
log INFO "Copying keyd configuration to /etc/keyd/default.conf"
|
log INFO "Copying keyd configuration to /etc/keyd/default.conf"
|
||||||
sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
|
sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
|
||||||
sudo systemctl enable --now keyd.service \
|
sudo systemctl enable --now keyd.service \
|
||||||
|
|
@ -253,23 +287,59 @@ ALL_PKGS=(
|
||||||
"${pkg_desktop[@]}"
|
"${pkg_desktop[@]}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ ${#ALL_PKGS[@]} -eq 0 ]]; then
|
if ((${#ALL_PKGS[@]})); then
|
||||||
log WARN "No packages selected."
|
if confirm "Install all the selected packages?"; then
|
||||||
else
|
|
||||||
if gum confirm --default=false "Install all the selected packages?"; then
|
|
||||||
log INFO "Installing selected packages..."
|
log INFO "Installing selected packages..."
|
||||||
sudo pacman -Sy --needed "${ALL_PKGS[@]}"
|
if sudo pacman -Syu --needed "${ALL_PKGS[@]}"; then
|
||||||
|
INSTALL_STATUS="complete"
|
||||||
|
else
|
||||||
|
INSTALL_STATUS="failed"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
log WARN "Package installation skipped by user"
|
||||||
|
INSTALL_STATUS="partial"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log WARN "No packages selected"
|
||||||
|
INSTALL_STATUS="partial"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
gum style \
|
case "$INSTALL_STATUS" in
|
||||||
|
complete)
|
||||||
|
gum style \
|
||||||
--border rounded \
|
--border rounded \
|
||||||
|
--border-foreground 42 \
|
||||||
--padding "1 2" \
|
--padding "1 2" \
|
||||||
--bold \
|
--bold \
|
||||||
--foreground 42 \
|
"✔ Installation Complete!
|
||||||
"🎉 Installation Complete!
|
|
||||||
|
|
||||||
Your system has been successfully configured.
|
|
||||||
|
|
||||||
|
All selected packages were installed successfully.
|
||||||
You may now reboot the system for all the changes to apply."
|
You may now reboot the system for all the changes to apply."
|
||||||
|
;;
|
||||||
|
partial)
|
||||||
|
gum style \
|
||||||
|
--border rounded \
|
||||||
|
--border-foreground 220 \
|
||||||
|
--padding "1 2" \
|
||||||
|
--bold \
|
||||||
|
"⚠ Setup Finished (Partial)
|
||||||
|
|
||||||
|
Some steps were skipped by user choice.
|
||||||
|
Your system was NOT fully configured."
|
||||||
|
;;
|
||||||
|
failed)
|
||||||
|
gum style \
|
||||||
|
--border rounded \
|
||||||
|
--border-foreground 196 \
|
||||||
|
--padding "1 2" \
|
||||||
|
--bold \
|
||||||
|
"❌ Installation Failed
|
||||||
|
|
||||||
|
One or more steps did not complete successfully.
|
||||||
|
Check the logs above."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
gum style --bold "Finished."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue