about summary refs log tree commit diff stats
path: root/bootstrap
diff options
context:
space:
mode:
authorene <ene@sils.li>2023-02-19 23:45:08 +0100
committerene <ene@sils.li>2023-02-19 23:45:08 +0100
commit508f70b7f66d5da17c8381545f5b67894fcbd576 (patch)
treee623806384d9f996080c569a98decf756bfec0c6 /bootstrap
parentFix(bootstrap): Allow to run the installer multiple times (diff)
downloadnixos-config-508f70b7f66d5da17c8381545f5b67894fcbd576.tar.gz
nixos-config-508f70b7f66d5da17c8381545f5b67894fcbd576.zip
Fix(bootstrap): Fix nasty grep bug
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/default.nix2
-rwxr-xr-xbootstrap/install.old65
-rwxr-xr-xbootstrap/install.sh (renamed from bootstrap/install)11
3 files changed, 6 insertions, 72 deletions
diff --git a/bootstrap/default.nix b/bootstrap/default.nix
index 8cd7b394..6fab9a2d 100644
--- a/bootstrap/default.nix
+++ b/bootstrap/default.nix
@@ -6,7 +6,7 @@
 }: let
   dependencies = with pkgs; [jq dash];
   name = "install";
-  script = ./install;
+  script = ./install.sh;
   lib = import ../lib {inherit pkgs shell-library;};
 in
   lib.makeShellScriptWithLibrary {inherit dependencies name script;}
diff --git a/bootstrap/install.old b/bootstrap/install.old
deleted file mode 100755
index 013a1287..00000000
--- a/bootstrap/install.old
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/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
diff --git a/bootstrap/install b/bootstrap/install.sh
index 81829019..37a5e758 100755
--- a/bootstrap/install
+++ b/bootstrap/install.sh
@@ -99,9 +99,9 @@ case $result in
         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;
+        awk -F "." '/nixosConfiguration/{print $2}' "$(tmp 'curl https://git.sils.li/ene/nixos-config/raw/branch/prime/flake.nix 2> /dev/null')" | awk '{print $1}' > $hosts;
 
-        while ! grep "$host" "$hosts" > /dev/null && [ "$host" == "" ]; do
+        while ! grep "$host" "$hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do
             i=1;
             while read -r ho ; do
                 printf "%4s) %s \n" "$i" "$ho";
@@ -110,10 +110,9 @@ case $result in
             printf "%4s) Exit\n" "q"
             readp  "Enter a option: " host
 
-            [ $host = "q" ] && exit 1
-            if grep "$host" "$hosts" > /dev/null && [ "$host" != "" ]; then
-                host=$(awk -v i="$host" '{if (NR==i) {print $0}}' "$hosts");
-            else
+            [ "$host" = "q" ] && exit 1
+            host=$(awk -v i="$host" '{if (NR==i) {print $0}}' "$hosts");
+            if ! grep "$host" "$hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; then
                 warning "No host selected. Select a host to continue.\n"
             fi
         done