Add installation and backup scripts
This commit is contained in:
parent
3442b6e57e
commit
644b06f2bb
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
wifi_backup() {
|
||||
zip /tmp/iwd-networks.zip /var/lib/iwd
|
||||
scp /tmp/iwd-networks.zip zion:/vault/backups/panacea/iwd
|
||||
}
|
||||
|
||||
wifi_backup
|
|
@ -0,0 +1,96 @@
|
|||
#!/bin/sh
|
||||
|
||||
partition_disk() {
|
||||
parted "$DISK" -- mklabel gpt
|
||||
parted "$DISK" -- mkpart ESP fat32 1MiB 512MiB
|
||||
parted "$DISK" -- mkpart primary 512MiB 100%
|
||||
parted "$DISK" -- set 1 boot on
|
||||
mkfs.fat -F32 -n BOOT "$DISK"p1
|
||||
}
|
||||
|
||||
create_directories() {
|
||||
mkdir /mnt
|
||||
mkdir -p /mnt/boot
|
||||
mkdir -p /mnt/home/coolneng
|
||||
mkdir -p /mnt/home/coolneng/Downloads
|
||||
mkdir -p /mnt/nix
|
||||
mkdir -p /mnt/tmp
|
||||
}
|
||||
|
||||
zfs_setup() {
|
||||
zpool create -f -o ashift=13 -O acltype=posixacl -O relatime=on \
|
||||
-O xattr=sa -O dnodesize=legacy -O normalization=formD -O mountpoint=none \
|
||||
-O canmount=off -O devices=off -R /mnt -O compression=zstd -O encryption=aes-256-gcm \
|
||||
-O keyformat=passphrase -O keylocation=prompt syscea "$DISK"p2
|
||||
zfs create -o mountpoint=none syscea
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/ephemeral
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/ephemeral/nix
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false -o sync=disabled -o setuid=off syscea/ephemeral/tmp
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=true syscea/stateful/home
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful/home/downloads
|
||||
zfs create -o mountpoint=legacy -o com.sun:auto-snapshot=false syscea/stateful/root
|
||||
zfs create -V 6G -b "$(getconf PAGESIZE)" -o compression=zle -o logbias=throughput -o sync=always \
|
||||
-o primarycache=metadata -o secondarycache=none -o com.sun:auto-snapshot=false syscea/ephemeral/swap
|
||||
mkswap -f /dev/zvol/syscea/swap && swapon /dev/zvol/syscea/swap
|
||||
}
|
||||
|
||||
mount_datasets() {
|
||||
mount "$DISK"p1 /mnt/boot
|
||||
mount -t zfs syscea/stateful/root /mnt
|
||||
mount -t zfs syscea/stateful/home /mnt/home/coolneng
|
||||
mount -t zfs syscea/stateful/home/downloads /mnt/home/coolneng/Downloads
|
||||
mount -t zfs syscea/ephemeral/nix /mnt/nix
|
||||
mount -t zfs syscea/ephemeral/tmp /mnt/tmp
|
||||
}
|
||||
|
||||
install_system() {
|
||||
nix-shell -p git nixFlakes --command "nixos-install --root /mnt --flake ."
|
||||
passwd
|
||||
passwd coolneng
|
||||
}
|
||||
|
||||
deploy_dotfiles() {
|
||||
chown -R coolneng:users /mnt/home/coolneng
|
||||
git clone https://git.coolneng.duckdns.org/coolneng/dotfiles /mnt/home/coolneng/.dotfiles
|
||||
git clone https://git.coolneng.duckdns.org/coolneng/doom.d /mnt/home/coolneng/.doom.d
|
||||
git clone https://git.coolneng.duckdns.org/coolneng/pass /mnt/home/coolneng/.password-store
|
||||
cd /mnt/home/coolneng/.dotfiles || exit
|
||||
nix-shell -p stow --command "stow ."
|
||||
}
|
||||
|
||||
restore_files() {
|
||||
mkdir /tmp/iwd
|
||||
scp zion:/vault/backups/panacea/iwd/iwd-networks.zip /tmp/iwd
|
||||
cd /tmp/iwd || exit
|
||||
unzip iwd-networks.zip
|
||||
mv ./* /mnt/var/lib/iwd
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: install.sh <disk>"
|
||||
echo "disk: full path to the disk (e.g. /dev/sda)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
DISK="$1"
|
||||
|
||||
echo "Let's start by partitioning the disk"
|
||||
partition_disk
|
||||
echo "Now we're creating the directories for the installation"
|
||||
create_directories
|
||||
echo "Starting up the ZFS machinery"
|
||||
zfs_setup
|
||||
echo "Mounting the horse"
|
||||
mount_datasets
|
||||
echo "Lift off to the NixOS planet"
|
||||
install_system
|
||||
echo "Adding pictures of Stallman"
|
||||
deploy_dotfiles
|
||||
echo "I'd just like to interject for a moment..."
|
||||
restore_files
|
||||
echo "All ready, time to rejoice"
|
Loading…
Reference in New Issue