From 5f3748df43e6b6e49cc0a23557a378ef37952483 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 1 Jun 2025 22:09:53 +0200 Subject: [PATCH] New option --and-reboot to immediately reboot host after applying config --- README.md | 12 ++++++++++++ bij.sh | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README.md b/README.md index dca1b84..7479154 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,18 @@ Apply change during next boot: bij apply astatine --on-next-boot ``` +Reboot host after applying config: + +``` +bij apply astatine --and-reboot +``` + +Combine activation and reboot: + +``` +bij apply astatine --on-next-boot --and-reboot +``` + Sometimes it is required to execute some commands on a host directly. ``` diff --git a/bij.sh b/bij.sh index a476ea0..0d6d573 100755 --- a/bij.sh +++ b/bij.sh @@ -7,6 +7,7 @@ TARGET= ON_NEXT_BOOT= USE_SUBSTITUTES="1" USE_REMOTE_SUDO="1" +AND_REBOOT= ARGS=() OPTS=() @@ -43,6 +44,10 @@ while [[ $# -gt 0 ]]; do USE_REMOTE_SUDO="" shift ;; + --and-reboot) + AND_REBOOT="1" + shift + ;; --) shift OPTS=( "$@" ) @@ -106,9 +111,20 @@ if [[ -n "${ON_NEXT_BOOT}" ]]; then APPLY_OPERATION="boot" fi +REBOOT_OPTS=() + +if [[ -n "${USE_REMOTE_SUDO}" ]]; then + REBOOT_OPTS+=("sudo") +fi + +REBOOT_OPTS+=("reboot") + case "${COMMAND}" in apply) nixos-rebuild "${APPLY_OPERATION}" --flake "${FLAKE_STORE_PATH}#${HOST}" --target-host "${TARGET}" "${APPLY_OPTS[@]}" + if [[ -n "${AND_REBOOT}" ]]; then + ssh -t "${TARGET}" "${REBOOT_OPTS[@]}" + fi ;; build) nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}"