-
Notifications
You must be signed in to change notification settings - Fork 5
/
recover.sh
executable file
·89 lines (73 loc) · 2.57 KB
/
recover.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
function yesno() {
local prompt="$1"
while true; do
read -rp "$prompt [y/n] " yn
case $yn in
[Yy]* ) echo "y"; return;;
[Nn]* ) echo "n"; return;;
* ) echo "Please answer yes or no.";;
esac
done
}
BOOTDISK=$(readlink -f /dev/disk/by-label/NIXBOOT)
reformat_boot=$(yesno "Reformat boot?")
if [[ $reformat_boot == "y" ]]; then
sudo mkfs.fat -F 32 "$BOOTDISK" -n NIXBOOT
fi
# -l prompts for passphrase if needed
echo "Importing zpool"
sudo zpool import -f -l zroot
reformat_nix=$(yesno "Reformat nix?")
if [[ $reformat_nix == "y" ]]; then
sudo zfs destroy -r zroot/nix
sudo zfs create -o mountpoint=legacy zroot/nix
sudo mkdir -p /mnt/nix
sudo mount -t zfs zroot/nix /mnt/nix
fi
echo "Mounting Disks"
sudo mount --mkdir -t zfs zroot/root /mnt
sudo mount --mkdir "$BOOTDISK" /mnt/boot
sudo mount --mkdir -t zfs zroot/nix /mnt/nix
sudo mount --mkdir -t zfs zroot/tmp /mnt/tmp
sudo mount --mkdir -t zfs zroot/persist /mnt/persist
sudo mount --mkdir -t zfs zroot/cache /mnt/cache
# Get repo to install from
read -rp "Enter flake URL (default: github:iynaix/dotfiles): " repo
repo="${repo:-github:iynaix/dotfiles}"
# qol for iynaix os
if [[ $repo == "github:iynaix/dotfiles" ]]; then
hosts=("desktop" "framework" "xps" "vm" "vm-hyprland")
echo "Available hosts:"
for i in "${!hosts[@]}"; do
printf "%d) %s\n" $((i+1)) "${hosts[i]}"
done
while true; do
echo ""
read -rp "Enter the number of the host to install: " selection
if [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -ge 1 ] && [ "$selection" -le ${#hosts[@]} ]; then
host="${hosts[$selection-1]}"
break
else
echo "Invalid selection. Please enter a number between 1 and ${#hosts[@]}."
fi
done
else
read -rp "Which host to install?" host
fi
# Get git rev
read -rp "Enter git rev for flake (default: main): " git_rev
echo "Re-installing NixOS"
# nixos minimal iso does not have git for whatever fucking stupid reason???
if [[ $repo == "github:iynaix/dotfiles" ]]; then
# root password is irrelevant if initialPassword is set in the config
nix-shell -p git nixFlakes --command \
"sudo nixos-install --no-root-password --flake \"$repo/${git_rev:-main}#$host\" --option tarball-ttl 0"
else
nix-shell -p git nixFlakes --command \
"sudo nixos-install --flake \"$repo/${git_rev:-main}#$host\" --option tarball-ttl 0"
fi
echo "Installation complete. It is now safe to reboot."