From 3649c233b73d03370779a8f58c6613a412979e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 8 Aug 2022 10:13:19 +0200 Subject: Improve devices and few more machines --- install.sh | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) mode change 100644 => 100755 install.sh (limited to 'install.sh') diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index a707ed4..a0ec3b7 --- a/install.sh +++ b/install.sh @@ -1,11 +1,15 @@ #!/bin/sh set -eu hostname="${1:-$(hostname)}" +root="${2:-}" -if [ "$(id -u)" -ne 0 ]; then - echo "Please run as root!" >&2 - exit 1 -fi +_sudo() { + if [ "$(id -u)" -ne 0 ]; then + "$@" + else + sudo -p 'Sudo password: ' -- "$@" + fi +} if [ "$hostname" = "nixos" ]; then echo "The hostname is the default one, that is not right for sure." >&2 @@ -13,19 +17,21 @@ if [ "$hostname" = "nixos" ]; then exit 1 fi -if [ ! -s /.personal-secrets.key ]; then +if [ ! -s "$root/.personal-secrets.key" ]; then echo "Please paste the personal secret key (terminate using ^D)" >&2 - cat >/.personal-secrets.key + sudo tee "$root/.personal-secrets.key" >/dev/null fi -mkdir -p ~/.ssh -cat >~/.ssh/config <&2 -cat >~/.ssh/nixos-secret-access -trap "rm -f ~/.ssh/nixos-secret-access" EXIT +ssh-add - +trap 'kill "$SSH_AGENT_PID"' EXIT -nix-shell -p git --command \ - "nixos-rebuild switch --flake 'git+https://git.cynerd.cz/nixos-personal#$hostname' --fast" +flake="git+https://git.cynerd.cz/nixos-personal#$hostname" +if [ -z "$root" ]; then + nix shell nixpkgs\#git --command \ + "_sudo \"\$(command -v nixos-rebuild)\" switch --flake '$flake' --fast" +else + nix shell nixpkgs\#git nixpkgs\#nixos-install-tools --command \ + "_sudo \"\$(command -v nixos-install)\" --flake '$flake' --root '$root'" +fi -- cgit v1.2.3