about summary refs log tree commit diff stats
path: root/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bootstrap/default.nix2
-rwxr-xr-xbootstrap/install127
-rwxr-xr-xbootstrap/install.old65
3 files changed, 194 insertions, 0 deletions
diff --git a/bootstrap/default.nix b/bootstrap/default.nix
new file mode 100644
index 00000000..e88b3eb5
--- /dev/null
+++ b/bootstrap/default.nix
@@ -0,0 +1,2 @@
+{pkgs ? import <nixpkgs> {}, ...}:
+pkgs.writeShellScriptBin "install" builtins.readFile ./install.sh
diff --git a/bootstrap/install b/bootstrap/install
new file mode 100755
index 00000000..f281e1dc
--- /dev/null
+++ b/bootstrap/install
@@ -0,0 +1,127 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+export LIB_TEMP_DIR_FOR_SCRIPT="$(mktemp -d)"
+bsc() {
+    msg2 "$(btrfs subvolume create "$1" || dien "Creating of subvol $1")";
+}
+
+mne() {
+    mount --mkdir --options compress-force=zstd:15,subvol="$1" $DISK_ROOT "$2" || dien "Mounting of $1";
+}
+
+
+available_disks="$(mktmp)";
+lsblk -J | jq '.[] | map(.name) | [foreach .[] as $item ({item: null, index: -1}; {$item, index: (.index + 1)})]' > $available_disks;
+
+
+[ "$(jq '.[]' "$available_disks" | wc -l)" -eq 0 ] && die "No disks found"
+msg "Select a disk to format:\n"
+
+i=9999; # nobody will have so many disks attached
+
+while ! jq -e --argjson i "$i" '.[$i]' "$available_disks" > /dev/null 2>&1; do
+    for disk in $(jq -c '.[]' "$available_disks" ); do
+        printf "%4s) %s \n" "$(echo "$disk" | jq '.index')" "$(echo "$disk" | jq '.item' | tr -d "\"")";
+    done
+    printf "%4s) Exit\n" "q"
+    readp  "Enter a option: " disk
+
+    if [ $disk = "q" ];then
+        exit 1
+    else
+        i="$disk"
+    fi
+    if jq -e --argjson i "$i" 'nth($i)' "$available_disks"  > /dev/null 2>&1; then
+        disk=$(mktmp);
+        jq -e --argjson i "$i" 'nth($i)' "$available_disks" > "$disk";
+    else
+        warning "No disk selected. Select a disk to continue.\n"
+    fi
+done
+
+readp "Do you really want to delete all data on disk $(jq '.item' "$disk")? [N/y]: " result
+case $result in
+    [Yy])
+        msg "Great, deleting everything..."
+        disk="$(jq '.item' "$disk" | tr -d "\"")"
+        ;;
+    *)
+        msg "Sure, keep your data"
+        exit 1
+        ;;
+esac
+
+sgdisk -Z "/dev/${disk}" || dien "Zapping"
+
+sgdisk -n 1:0:+550M -n 2:0:"$ENDSECTOR" -t 1:ef00 -t 2:8300 "/dev/${disk}" || dien "Partitioning"
+
+case "$disk" in
+    "nvme"*)
+        export DISK_EFI="/dev/${disk}"p1
+        export DISK_ROOT="/dev/${disk}"p2
+        ;;
+    "sd"* |"vd"*)
+        export DISK_EFI="/dev/${disk}"1
+        export DISK_ROOT="/dev/${disk}"2
+        ;;
+    *)
+        die "The disk type: ${disk} is not yet supported!"
+        ;;
+esac
+
+msg "Started Formatting..."
+mkfs.fat -F32 "$DISK_EFI" || dien "Formatting(fat32)"
+mkfs.btrfs "$DISK_ROOT" || dien "Formatting(btrfs)"
+
+
+msg "Mounting..."
+mount -t btrfs $DISK_ROOT /mnt
+cd /mnt || die "(Bug): no /mnt"
+bsc nix-store
+bsc persistent-storage
+bsc storage/nixos-config
+cd /
+umount -R /mnt
+mount -t tmpfs none /mnt
+mount --mkdir "$DISK_EFI" /mnt/boot
+
+mne nix-store /mnt/nix
+mne persistent-storage /mnt/srv
+
+mount --mkdir --options bind /mnt/srv/nixos-config /mnt/etc/nixos
+
+msg "Finished mounting and generating btrfs subvolumes"
+readp "Do you want to continue with nixos-install? [N/y]: " result
+case $result in
+    [Yy])
+        msg "Great, select a host-config:"
+        hosts=$(mktmp);
+        host="";
+        awk -F "." '/nixosConfiguration/{print $2}' "$(tmp 'curl https://git.sils.li/ene/nixos-config/raw/branch/prime/flake.nix')" | awk '{print $1}' > $hosts;
+
+        while ! awk -v host $host '{$0 ~ host}' "$hosts" && [ "$host" != "" ]; do
+            i=1;
+            while read -r ho ; do
+                printf "%4s) %s \n" "$i" "$ho";
+                i=$((i+1));
+            done < "$hosts"
+            printf "%4s) Exit\n" "q"
+            readp  "Enter a option: " host
+
+            [ $host = "q" ] && exit 1
+            if awk -v host $host '{$0 ~ host}' "$hosts" && [ "$host" != "" ]; then
+                host=$(awk -v i $host 'NR==i' "$hosts");
+            else
+                warning "No disk selected. Select a disk to continue.\n"
+            fi
+        done
+        nixos-install --flake https://git.sils.li/ene/nixos-config#${host} --no-root-passwd
+        ;;
+    *)
+        msg "Sure, do it yourself"
+        exit 1
+        ;;
+esac
+if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi
diff --git a/bootstrap/install.old b/bootstrap/install.old
new file mode 100755
index 00000000..013a1287
--- /dev/null
+++ b/bootstrap/install.old
@@ -0,0 +1,65 @@
+#!/bin/sh
+# shellcheck disable=SC2086
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+
+#After partitioning /dev/vda1 as efi and /dev/vda2 as btrfs, installation is as simple as:
+
+available_disks="$(mktmp)";
+lsblk -J | jq '.[] | map(.name) | [foreach .[] as $item ({item: null, index: -1}; {$item, index: (.index + 1)})]' > $available_disks;
+#"$(lsblk -J | jq '.[]| .[]| {name: .name, children: (.children | map(.name))} | .name')"
+
+
+[ "$(jq '.[]' "$available_disks" | wc -l)" -eq 0 ] && die "No disks found"
+msg "Select a disk to format:\n"
+
+i=9999; # nobody will have so many disks attached
+
+while ! jq -e --argjson i "$i" '.[$i]' "$available_disks" > /dev/null ; do
+    for disk in $(jq -c '.[]' "$available_disks" ); do
+        printf "%4s) %s \n" "$(echo "$disk" | jq '.index')" "$(echo "$disk" | jq '.item' | tr -d "\"")";
+    done
+    printf "%4s) Exit\n" "q"
+    readp  "Enter a option: " disk
+
+    if [ $disk = "q" ];then
+        exit 1
+    else
+        i="$disk"
+    fi
+    jq -e --argjson i "$i" '.[$i]' "$available_disks" || warning "\nNo disk selected. Select a disk to continue.\n"
+done
+
+exit 0;
+#disk=$((disk-1))
+#read -p "Do you want to delete all in ${Disk_Array[$disk]}? [N/y]" -n 1 -r result
+#[[ $result =~ ^[Yy]$ ]] && echo || exit 1
+#sgdisk -Z "${Disk_Array[$disk]}" > /dev/null || dien "Zapping"
+#sgdisk -n 1:0:+300M -n 2:0:"$ENDSECTOR" -t 1:ef00 -t 2:8300 "${Disk_Array[$disk]}" > /dev/null || dien "Partitioning"
+#
+#if [[ ${Disk_Array[$disk]} == *"nvme"* ]];then
+#    export DISK_EFI=${Disk_Array[$disk]}p1 && echo "${Disk_Array[$disk]}p1" > /root/efi-disk
+#    export DISK_ROOT=${Disk_Array[$disk]}p2 && echo "${Disk_Array[$disk]}p2" > /root/root-disk
+#else
+#    export DISK_EFI=${Disk_Array[$disk]}1 && echo "${Disk_Array[$disk]}1" > /root/efi-disk
+#    export DISK_ROOT=${Disk_Array[$disk]}2 && echo "${Disk_Array[$disk]}2" > /root/root-disk
+#fi
+#
+#
+#mount -t btrfs /dev/vda2 /mnt
+#btrfs subvolume create /mnt/{nix,storage}
+#btrfs subvolume create /mnt/storage/{networkmanager,nixos-server}
+#umount /mnt
+#mount -t tmpfs none /mnt
+#mkdir -p /mnt/{nix,etc/nixos,etc/NetworkManager,srv,boot}
+#mount /dev/vda1 /mnt/boot
+#mount -t btrfs -o subvol=nix /dev/vda2 /mnt/nix
+#mount -t btrfs -o subvol=storage /dev/vda2 /mnt/srv
+#mount -o bind /mnt/srv/nixos-server /mnt/etc/nixos
+#mount -o bind /mnt/srv/networkmanager /mnt/etc/NetworkManager
+#nixos-generate-config --root /mnt
+#nixos-install --no-root-passwd
+#reboot
+#
+#
+#if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi