refactor: deploy: update logs

This commit is contained in:
2026-02-20 12:04:15 +00:00
parent 26bdecb8e0
commit 9010b2678e
2 changed files with 27 additions and 23 deletions

View File

@@ -9,12 +9,15 @@ let
deploy = hectic.writeShellApplication { deploy = hectic.writeShellApplication {
inherit shell bashOptions; inherit shell bashOptions;
name = "deploy"; name = "deploy";
runtimeInputs = [ runtimeInputs = [
ssh-to-age ssh-to-age
inputs.nixos-anywhere.packages.${system}.nixos-anywhere inputs.nixos-anywhere.packages.${system}.nixos-anywhere
]; ];
text = builtins.readFile ./deploy.sh; text = ''
${builtins.readFile hectic.helpers.posix-shell.log}
${builtins.readFile ./deploy.sh}
'';
}; };
in in
symlinkJoin { symlinkJoin {

View File

@@ -1,7 +1,7 @@
#!/bin/dash
# requirements: ssh-to-age nixos-anywhere # requirements: ssh-to-age nixos-anywhere
HECTIC_NAMESPACE="deploy"
# ssh proxydoe 'cat /etc/os-release 2>/dev/null || echo "no /etc/os-release"' | grep '^NAME=NixOS$' # ssh proxydoe 'cat /etc/os-release 2>/dev/null || echo "no /etc/os-release"' | grep '^NAME=NixOS$'
# NAME=NixOS # NAME=NixOS
@@ -27,8 +27,8 @@ while [ $# -gt 0 ]; do
push) push)
if [ ${founded_command+x} ]; then if [ ${founded_command+x} ]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'ambiguous subcommand `%s` and `%s`\n' "$1" "$founded_command" log error 'ambiguous subcommand `%s` and `%s`' "$1" "$founded_command"
exit 1 exit 2
fi fi
push_deploy=1 push_deploy=1
@@ -38,8 +38,8 @@ while [ $# -gt 0 ]; do
rollback) rollback)
if [ ${founded_command+x} ]; then if [ ${founded_command+x} ]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'ambiguous subcommand `%s` and `%s`\n' "$1" "$founded_command" log error 'ambiguous subcommand `%s` and `%s`' "$1" "$founded_command"
exit 1 exit 2
fi fi
rollback_deploy=1 rollback_deploy=1
@@ -49,8 +49,8 @@ while [ $# -gt 0 ]; do
history) history)
if [ ${founded_command+x} ]; then if [ ${founded_command+x} ]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'ambiguous subcommand `%s` and `%s`\n' "$1" "$founded_command" log error 'ambiguous subcommand `%s` and `%s`' "$1" "$founded_command"
exit 1 exit 2
fi fi
server_history=1 server_history=1
@@ -81,15 +81,15 @@ while [ $# -gt 0 ]; do
if [ ${push_deploy+x} ]; then if [ ${push_deploy+x} ]; then
server_init=1 server_init=1
else else
printf 'illegal %s\n' "$1" log warn 'illegal %s' "$1"
fi fi
shift shift
;; ;;
--to) --to)
if [ ${rollback_deploy+x} ]; then if [ ${rollback_deploy+x} ]; then
rollback_to="$2" rollback_to="$2"
else else
printf 'illegal %s\n' "$1" log warn 'illegal %s' "$1"
fi fi
shift 2 shift 2
;; ;;
@@ -113,8 +113,8 @@ while [ $# -gt 0 ]; do
case $1 in case $1 in
--target-host) --target-host)
if [ "${target_host+x}" ] && [ "$target_host" != "$2" ]; then if [ "${target_host+x}" ] && [ "$target_host" != "$2" ]; then
printf 'you specified 2 ambiguous target hosts %s and %s\n' "$target_host" "$2" log error 'you specified 2 ambiguous target hosts %s and %s' "$target_host" "$2"
exit 1 exit 2
fi fi
target_host="$2" target_host="$2"
@@ -132,8 +132,8 @@ done
set -- $saved_nix_args set -- $saved_nix_args
if ! [ ${target_host+x} ]; then if ! [ ${target_host+x} ]; then
printf '%s not set, but required\n' '--target-host' log error '%s not set, but required' '--target-host'
exit 1 exit 3
fi fi
if puressh "$target_host" 'cat /etc/os-release 2>/dev/null || echo "no /etc/os-release"' \ if puressh "$target_host" 'cat /etc/os-release 2>/dev/null || echo "no /etc/os-release"' \
@@ -157,7 +157,7 @@ if [ "${rollback_deploy+x}" ]; then
if [ -z "$rollback_to" ]; then if [ -z "$rollback_to" ]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'no profile version older than the current `%s` exists\n' "$current_gen" log error 'no profile version older than the current `%s` exists' "$current_gen"
exit exit
fi fi
@@ -166,7 +166,7 @@ if [ "${rollback_deploy+x}" ]; then
| grep -oP '(?<=system-)'"$rollback_to"'(?=-link)' > /dev/null | grep -oP '(?<=system-)'"$rollback_to"'(?=-link)' > /dev/null
then then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'no profile version `%s` exists\n' "$rollback_to" log error 'no profile version `%s` exists' "$rollback_to"
exit exit
fi fi
fi fi
@@ -186,7 +186,8 @@ fi
if [ "${push_deploy+x}" ]; then if [ "${push_deploy+x}" ]; then
if [ "${server_init+x}" ]; then if [ "${server_init+x}" ]; then
if [ "$is_target_host_nixos" -eq 1 ]; then if [ "$is_target_host_nixos" -eq 1 ]; then
printf 'target host already is nixos, are you realy want to reinstall nixos?\nThis may delete all data [y/N]\n' log warn 'target host already is nixos, are you really want to reinstall nixos?'
printf 'This may delete all data [y/N]\n'
read -r CONTINUE read -r CONTINUE
if [ "$CONTINUE" != "y" ]; then if [ "$CONTINUE" != "y" ]; then
exit 0 exit 0
@@ -199,11 +200,11 @@ if [ "${push_deploy+x}" ]; then
server_public_age_key=$(puressh "$target_host" cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age) server_public_age_key=$(puressh "$target_host" cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age)
# shellcheck disable=SC2016 # shellcheck disable=SC2016
printf 'server'"'"'s public age key is `%s` use it in sops file and run regular deploys\n' "$server_public_age_key" log info 'server'"'"'s public age key is `%s` use it in sops file and run regular deploys' "$server_public_age_key"
else else
if [ "$is_target_host_nixos" -ne 1 ]; then if [ "$is_target_host_nixos" -ne 1 ]; then
printf 'remote system not nixos\n' log error 'remote system not nixos'
exit 1 exit 1
fi fi
# shellcheck disable=SC2068 # shellcheck disable=SC2068