diff --git a/build b/build index 0d5eceaf..0dc5aed2 100755 --- a/build +++ b/build @@ -7,16 +7,6 @@ TARGET="${1:-default}" # See https://nixos.wiki/wiki/FAQ/How_can_I_install_a_proprietary_or_unfree_package%3F export NIXPKGS_ALLOW_UNFREE=1 -function ensure_branch { - CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - if [ "$CURRENT_BRANCH" != "$1" ]; then - echo - echo "You should be on branch '$1', but you are currently on branch '$CURRENT_BRANCH'." - echo "Aborting." - exit 1 - fi -} - if [ "$TARGET" == "vm" ]; then (set -x; nix-build \ @@ -42,7 +32,8 @@ You can switch virtual consoles in the guest via QEMU monitor (ctrl-alt-2), send elif [ "$TARGET" == "develop" ]; then - ensure_branch "develop" + scripts/info-branch-commit + scripts/confirm-or-abort (set -x; nix-build \ --arg updateCert ./pki/develop/cert.pem \ @@ -56,7 +47,8 @@ elif [ "$TARGET" == "develop" ]; then elif [ "$TARGET" == "validation" ]; then - ensure_branch "validation" + scripts/info-branch-commit + scripts/confirm-or-abort (set -x; nix-build \ --arg updateCert ./pki/validation/cert.pem \ @@ -70,7 +62,8 @@ elif [ "$TARGET" == "validation" ]; then elif [ "$TARGET" == "master" ]; then - ensure_branch "master" + scripts/info-branch-commit + scripts/confirm-or-abort (set -x; nix-build \ --arg updateCert ./pki/master/cert.pem \ @@ -82,12 +75,18 @@ elif [ "$TARGET" == "master" ]; then echo echo "Run ./result/bin/deploy-update to deploy." -# Create a stuck system that will not self-update -# usage: ./build stuck https://url-for-kiosk elif [ "$TARGET" == "stuck" ]; then + echo "Creating a stuck system that will not self-update." + echo + + printf "Kiosk URL? " + read KIOSK_URL + + KIOSK_URL=$(echo "$KIOSK_URL" | xargs) # Trim + (set -x; nix-build \ - --arg kioskUrl "$2" \ + --arg kioskUrl "$KIOSK_URL" \ --arg buildBundle false \ --arg buildDisk false) diff --git a/scripts/confirm-or-abort b/scripts/confirm-or-abort new file mode 100755 index 00000000..e77fe512 --- /dev/null +++ b/scripts/confirm-or-abort @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail +cd $(dirname "$0") + +if [ -n "${1:-}" ]; then + + QUESTION="$1" + +else + + QUESTION="Confirm?" + +fi + +./yes-no-question "$QUESTION" || (echo "Aborting." && exit 1) diff --git a/scripts/info-branch-commit b/scripts/info-branch-commit new file mode 100755 index 00000000..d576c34c --- /dev/null +++ b/scripts/info-branch-commit @@ -0,0 +1,11 @@ +#! /usr/bin/env bash +set -euo pipefail + +echo "On branch:" +echo +echo " $(git rev-parse --abbrev-ref HEAD)" +echo +echo "With last commit:" +echo +echo " $(git log -1 --pretty="%h %s")" +echo diff --git a/scripts/yes-no-question b/scripts/yes-no-question new file mode 100755 index 00000000..4eaeeaed --- /dev/null +++ b/scripts/yes-no-question @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +QUESTION="$1" + +while true; do + + printf "$QUESTION [y/n] " + read ANSWER + + if [ "$ANSWER" == "y" ]; then + + exit 0 + + elif [ "$ANSWER" == "n" ]; then + + exit 1 + + fi + +done