aboutsummaryrefslogtreecommitdiff
path: root/install.sh
blob: a0ec3b717ec5ef75ef858d289b6d182c0043840b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
set -eu
hostname="${1:-$(hostname)}"
root="${2:-}"

_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
	echo "Please specify the correct hostname as the first argument!" >&2
	exit 1
fi

if [ ! -s "$root/.personal-secrets.key" ]; then
	echo "Please paste the personal secret key (terminate using ^D)" >&2
	sudo tee "$root/.personal-secrets.key" >/dev/null
fi

eval "$(ssh-agent)"
echo "Please paste the SSH access key now (terminate using ^D):" >&2
ssh-add -
trap 'kill "$SSH_AGENT_PID"' EXIT

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