deploy: Colorize steps
This commit is contained in:
parent
50abb95e4c
commit
875ea5d137
|
@ -4,20 +4,34 @@ verb="$2"
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
# Helpers
|
||||||
|
error() {
|
||||||
|
echo -e '\033[1;31m'"$*"'\033[0m'
|
||||||
|
}
|
||||||
|
warn() {
|
||||||
|
echo -e '\033[1;33m'"$*"'\033[0m'
|
||||||
|
}
|
||||||
|
info() {
|
||||||
|
echo -e '\033[1;34m'"$*"'\033[0m'
|
||||||
|
}
|
||||||
|
debug() {
|
||||||
|
[ ! -v DEBUG ] || echo -e '\033[1;35m'"$*"'\033[0m'
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$verb" != "build" ] && [ "$verb" != "test" ] && [ "$verb" != "boot" ] && [ "$verb" != "switch" ] && [ "$verb" != "confirm" ]
|
if [ "$verb" != "build" ] && [ "$verb" != "test" ] && [ "$verb" != "boot" ] && [ "$verb" != "switch" ] && [ "$verb" != "confirm" ]
|
||||||
then
|
then
|
||||||
echo "Action should be one of: build, test, boot, switch, confirm"
|
error "Action should be one of: build, test, boot, switch, confirm"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build, looking nice
|
info "Building"
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
# sudo so the eval cache is shared with nixos-rebuild
|
# sudo so the eval cache is shared with nixos-rebuild
|
||||||
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
|
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
|
||||||
toplevel="$(readlink -f "$tmpdir/toplevel")"
|
toplevel="$(readlink -f "$tmpdir/toplevel")"
|
||||||
rm -rf "$tmpdir"
|
rm -rf "$tmpdir"
|
||||||
|
|
||||||
# Show diff
|
info "Showing diff"
|
||||||
nvd diff "$(readlink -f /nix/var/nix/profiles/system)" "$toplevel"
|
nvd diff "$(readlink -f /nix/var/nix/profiles/system)" "$toplevel"
|
||||||
|
|
||||||
# Figure out specialisation
|
# Figure out specialisation
|
||||||
|
@ -27,15 +41,17 @@ while read -r specialisation
|
||||||
do
|
do
|
||||||
if [ "$(readlink -f "/nix/var/nix/profiles/system/specialisation/$specialisation")" = "$currentSystem" ]
|
if [ "$(readlink -f "/nix/var/nix/profiles/system/specialisation/$specialisation")" = "$currentSystem" ]
|
||||||
then
|
then
|
||||||
|
debug "Using specialisation: $specialisation"
|
||||||
specialisationArgs=("--specialisation" "$specialisation")
|
specialisationArgs=("--specialisation" "$specialisation")
|
||||||
fi
|
fi
|
||||||
done <<< "$(ls /nix/var/nix/profiles/system/specialisation)"
|
done <<< "$(ls /nix/var/nix/profiles/system/specialisation)"
|
||||||
|
|
||||||
# Apply
|
# Apply
|
||||||
|
info "Applying"
|
||||||
confirm="n"
|
confirm="n"
|
||||||
if [ "$verb" = "confirm" ]
|
if [ "$verb" = "confirm" ]
|
||||||
then
|
then
|
||||||
echo "Apply configuration? [y/N]"
|
warning "Apply configuration? [y/N]"
|
||||||
read -r confirm
|
read -r confirm
|
||||||
fi
|
fi
|
||||||
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||||
|
@ -47,7 +63,7 @@ fi
|
||||||
# Set as boot
|
# Set as boot
|
||||||
if [ "$verb" = "confirm" ]
|
if [ "$verb" = "confirm" ]
|
||||||
then
|
then
|
||||||
echo "Set configuration as boot? [y/N]"
|
warning "Set configuration as boot? [y/N]"
|
||||||
read -r confirm
|
read -r confirm
|
||||||
fi
|
fi
|
||||||
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||||
|
|
Loading…
Reference in a new issue