Add Ansible configuration and remove NixOS
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 39s
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 39s
This commit is contained in:
@@ -1,229 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
# check if --verbose was passed
|
||||
if [ "$2" = "--verbose" ]; then
|
||||
export verbose=true
|
||||
printfe "%s\n" "yellow" "Verbose mode enabled"
|
||||
help() {
|
||||
printfe "%s\n" "green" "Usage: upgrade.sh [options]"
|
||||
printfe "%s\n" "green" "Options:"
|
||||
printfe "%s\n" "green" " --ha, -H Upgrade Home Manager packages."
|
||||
printfe "%s\n" "green" " --nix, -X Upgrade NixOS packages."
|
||||
printfe "%s\n" "green" " --full-speed, -F Upgrade packages and use all available cores for compilation. (Default: 8 cores)"
|
||||
printfe "%s\n" "green" " --help, -h Display this help message."
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--ha|-H) RUN_HA=true ;;
|
||||
--nix|-X) RUN_NIX=true ;;
|
||||
--ansible|-A) RUN_ANSIBLE=true ;;
|
||||
--full-speed|-F) FULL_SPEED=true ;;
|
||||
--help|-h) help ;;
|
||||
*) echo "Unknown parameter passed: $1";
|
||||
help ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z "$RUN_HA" && -z "$RUN_NIX" && -z "$RUN_ANSIBLE" ]]; then
|
||||
RUN_HA=true
|
||||
RUN_NIX=true
|
||||
RUN_ANSIBLE=true
|
||||
fi
|
||||
|
||||
# Check if --full-speed flag is passed, otherwise use --cores 8 -j 1
|
||||
if [[ "$FULL_SPEED" == true ]]; then
|
||||
CORES=$(nproc)
|
||||
JOBS=$(nproc)
|
||||
else
|
||||
export verbose=false
|
||||
CORES=8
|
||||
JOBS=1
|
||||
fi
|
||||
|
||||
# Check if we have shyaml since that's required for the script to function
|
||||
if [ ! -x "$(command -v shyaml)" ]; then
|
||||
printfe "%s\n" "red" "shyaml is not installed, installing it..."
|
||||
pipx install shyaml
|
||||
fi
|
||||
printfe "%s\n" "cyan" "Limiting to $CORES cores with $JOBS jobs."
|
||||
|
||||
ensure_symlink() {
|
||||
local source
|
||||
local target
|
||||
|
||||
# Fetch target from YAML
|
||||
target=$(shyaml get-value "config.symlinks.$1.target" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
|
||||
# Fetch source from YAML based on OS
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Check for WSL2
|
||||
if [[ $(uname -a) == *"microsoft-standard-WSL2"* ]]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.wsl" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
else
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.linux" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.macos" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Fall back to generic source if OS-specific source is empty
|
||||
if [ -z "$source" ]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.source" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Attempt to use the hostname of the machine if source is still empty
|
||||
if [ -z "$source" ]; then
|
||||
source=$(shyaml get-value "config.symlinks.$1.sources.$(hostname)" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
fi
|
||||
|
||||
# Error out if source is still empty
|
||||
if [ -z "$source" ]; then
|
||||
printfe "%s\n" "red" " - No valid source defined for $1"
|
||||
return
|
||||
fi
|
||||
|
||||
# Expand ~ with $HOME
|
||||
source="${source/#\~/$HOME}"
|
||||
target="${target/#\~/$HOME}"
|
||||
|
||||
# Call the function to check or make the symlink
|
||||
check_or_make_symlink "$source" "$target"
|
||||
|
||||
# Check if there is a chmod defined for the target file
|
||||
desired_chmod=$(shyaml get-value "config.symlinks.$1.chmod" < "$HOME/dotfiles/config/config.yaml" 2>/dev/null)
|
||||
|
||||
if [ -n "$desired_chmod" ]; then
|
||||
# Resolve the target if it is a symlink
|
||||
resolved_target=$(readlink -f "$target")
|
||||
|
||||
# If readlink fails, fall back to the original target
|
||||
if [ -z "$resolved_target" ]; then
|
||||
resolved_target="$target"
|
||||
fi
|
||||
|
||||
current_chmod=$(stat -c %a "$resolved_target" 2>/dev/null)
|
||||
if [ "$current_chmod" != "$desired_chmod" ]; then
|
||||
printfe "%s\n" "yellow" " - Changing chmod of $resolved_target to $desired_chmod"
|
||||
chmod "$desired_chmod" "$resolved_target"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
symlinks() {
|
||||
####################################################################################################
|
||||
# Update symlinks
|
||||
####################################################################################################
|
||||
|
||||
# Load symlinks from config file
|
||||
symlinks=($(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.symlinks))
|
||||
printfe "%s\n" "cyan" "Updating symlinks..."
|
||||
|
||||
for symlink in "${symlinks[@]}"; do
|
||||
ensure_symlink $symlink
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
####################################################################################################
|
||||
# Update packages
|
||||
####################################################################################################
|
||||
|
||||
sys_packages() {
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
printfe "%s\n" "cyan" "Updating brew packages..."
|
||||
brew update
|
||||
brew upgrade
|
||||
brew cleanup
|
||||
else
|
||||
if [ -x "$(command -v nixos-version)" ]; then
|
||||
printfe "%s\n" "cyan" "Updating nix channels..."
|
||||
printfe "%s" "cyan" "System channels: "
|
||||
sudo -i nix-channel --update
|
||||
|
||||
printfe "%s" "cyan" "User channels: "
|
||||
nix-channel --update
|
||||
|
||||
printfe "%s\n" "cyan" "Updating nixos flake..."
|
||||
cd $HOME/dotfiles/config/nixos && nix --extra-experimental-features nix-command --extra-experimental-features flakes flake update
|
||||
|
||||
# Exit if this failed
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -x "$(command -v apt)" ]; then
|
||||
printfe "%s\n" "cyan" "Updating apt packages..."
|
||||
sudo nala upgrade -y
|
||||
sudo nala autoremove -y --purge
|
||||
fi
|
||||
|
||||
if [ -x "$(command -v yum)" ]; then
|
||||
printfe "%s\n" "cyan" "Updating yum packages..."
|
||||
sudo yum update -y
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cargopkgs() {
|
||||
printfe "%s\n" "cyan" "Ensuring Cargo packages are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/cargo_packages.sh
|
||||
ensure_cargo_packages_installed
|
||||
}
|
||||
|
||||
pipxpkgs() {
|
||||
if [ ! -x "$(command -v pipx)" ]; then
|
||||
printfe "%s\n" "yellow" "pipx is not available, skipping pipx packages."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring pipx packages are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/pipx_packages.sh
|
||||
ensure_pipx_packages_installed
|
||||
}
|
||||
|
||||
flatpakpkgs() {
|
||||
if [ ! -x "$(command -v flatpak)" ]; then
|
||||
printfe "%s\n" "yellow" "Flatpak is not available, skipping Flatpak."
|
||||
return
|
||||
fi
|
||||
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping Flatpak."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring Flatpak packages are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/flatpak_packages.sh
|
||||
ensure_flatpak_packages_installed
|
||||
}
|
||||
|
||||
homemanager() {
|
||||
if [[ "$RUN_NIX" == true ]]; then
|
||||
printfe "%s\n" "cyan" "Updating Home Manager flake..."
|
||||
cd $HOME/dotfiles/config/home-manager && nix --extra-experimental-features nix-command --extra-experimental-features flakes flake update
|
||||
}
|
||||
|
||||
####################################################################################################
|
||||
# Parse arguments
|
||||
####################################################################################################
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
printfe "%s\n" "yellow" "No options passed, running full update..."
|
||||
|
||||
symlinks
|
||||
sys_packages
|
||||
homemanager
|
||||
cargopkgs
|
||||
pipxpkgs
|
||||
flatpakpkgs
|
||||
dotf secrets encrypt
|
||||
else
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--nixos|nixos|nix|nixos-rebuild)
|
||||
sys_packages
|
||||
;;
|
||||
--home-manager|--homemanager|ha|hm|home)
|
||||
homemanager
|
||||
;;
|
||||
--nix)
|
||||
sys_packages
|
||||
homemanager
|
||||
;;
|
||||
--symlinks)
|
||||
symlinks
|
||||
;;
|
||||
--packages)
|
||||
sys_packages
|
||||
cargopkgs
|
||||
pipxpkgs
|
||||
flatpakpkgs
|
||||
;;
|
||||
--pipx)
|
||||
pipxpkgs
|
||||
;;
|
||||
--cargo)
|
||||
cargopkgs
|
||||
;;
|
||||
--flatpak)
|
||||
flatpakpkgs
|
||||
;;
|
||||
*)
|
||||
printfe "%s\n" "red" "Unknown option: $arg"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
echo ""
|
||||
printfe "%s\n" "blue" "Done!"
|
||||
if [[ "$RUN_HA" == true ]]; then
|
||||
if command -v home-manager &> /dev/null; then
|
||||
printfe "%s\n" "cyan" "Cleaning old backup files..."
|
||||
rm -rf $HOME/.config/mimeapps.list.backup
|
||||
|
||||
printfe "%s\n" "cyan" "Upgrading Home Manager packages..."
|
||||
cd $HOME/dotfiles/config/home-manager && NIXPKGS_ALLOW_UNFREE=1 home-manager --extra-experimental-features nix-command --extra-experimental-features flakes switch -b backup --flake .#$DOTF_HOSTNAME --impure --cores $CORES -j $JOBS
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
printfe "%s\n" "red" "Failed to upgrade Home Manager packages."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "red" "Home Manager is not installed."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$RUN_ANSIBLE" == true ]]; then
|
||||
if command -v ansible-playbook &> /dev/null; then
|
||||
printfe "%s\n" "cyan" "Upgrading Ansible packages..."
|
||||
cd $HOME/dotfiles/config/ansible && ansible-playbook -i $HOME/dotfiles/config/ansible/inventory.ini $HOME/dotfiles/config/ansible/main.yml --extra-vars "hostname=$DOTF_HOSTNAME" --limit $DOTF_HOSTNAME
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
printfe "%s\n" "red" "Failed to upgrade Ansible packages."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "red" "Ansible is not installed."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
@@ -1,72 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
help() {
|
||||
printfe "%s\n" "green" "Usage: upgrade.sh [options]"
|
||||
printfe "%s\n" "green" "Options:"
|
||||
printfe "%s\n" "green" " --ha, -H Upgrade Home Manager packages."
|
||||
printfe "%s\n" "green" " --nix, -X Upgrade NixOS packages."
|
||||
printfe "%s\n" "green" " --full-speed, -F Upgrade packages and use all available cores for compilation. (Default: 8 cores)"
|
||||
printfe "%s\n" "green" " --help, -h Display this help message."
|
||||
exit 0
|
||||
}
|
||||
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--ha|-H) RUN_HA=true ;;
|
||||
--nix|-X) RUN_NIX=true ;;
|
||||
--full-speed|-F) FULL_SPEED=true ;;
|
||||
--help|-h) help ;;
|
||||
*) echo "Unknown parameter passed: $1";
|
||||
help ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ -z "$RUN_HA" && -z "$RUN_NIX" ]]; then
|
||||
RUN_HA=true
|
||||
RUN_NIX=true
|
||||
fi
|
||||
|
||||
# Check if --full-speed flag is passed, otherwise use --cores 8 -j 1
|
||||
if [[ "$FULL_SPEED" == true ]]; then
|
||||
CORES=$(nproc)
|
||||
JOBS=$(nproc)
|
||||
else
|
||||
CORES=8
|
||||
JOBS=1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Limiting to $CORES cores with $JOBS jobs."
|
||||
|
||||
if [[ "$RUN_NIX" == true ]]; then
|
||||
if command -v nixos-rebuild &> /dev/null; then
|
||||
printfe "%s\n" "cyan" "Upgrading NixOS packages..."
|
||||
cd $HOME/dotfiles/config/nixos && sudo nixos-rebuild switch --upgrade --flake .#$DOTF_HOSTNAME --impure --cores $CORES -j $JOBS
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
printfe "%s\n" "red" "Failed to upgrade NixOS packages."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "red" "Skipping nixos-rebuild, NixOS is not installed."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$RUN_HA" == true ]]; then
|
||||
if command -v home-manager &> /dev/null; then
|
||||
printfe "%s\n" "cyan" "Cleaning old backup files..."
|
||||
rm -rf $HOME/.config/mimeapps.list.backup
|
||||
|
||||
printfe "%s\n" "cyan" "Upgrading Home Manager packages..."
|
||||
cd $HOME/dotfiles/config/home-manager && NIXPKGS_ALLOW_UNFREE=1 home-manager --extra-experimental-features nix-command --extra-experimental-features flakes switch -b backup --flake .#$DOTF_HOSTNAME --impure --cores $CORES -j $JOBS
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
printfe "%s\n" "red" "Failed to upgrade Home Manager packages."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
printfe "%s\n" "red" "Home Manager is not installed."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
Reference in New Issue
Block a user