diff options
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap/01_activate.sh | 8 | ||||
-rwxr-xr-x | bootstrap/01_install.sh | 67 | ||||
-rwxr-xr-x | bootstrap/02_setup.sh | 8 | ||||
-rwxr-xr-x | bootstrap/99_ensure_config_variables.sh | 93 |
4 files changed, 89 insertions, 87 deletions
diff --git a/bootstrap/01_activate.sh b/bootstrap/01_activate.sh index 82e45761..ccfdd644 100755 --- a/bootstrap/01_activate.sh +++ b/bootstrap/01_activate.sh @@ -10,10 +10,10 @@ nix run github:nix-community/disko --experimental-features 'nix-command flakes' msg "Finished mounting" case "$ACTIVATE_TO_SETUP" in - "yes") - nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes' - ;; - *) ;; +"yes") + nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes' + ;; +*) ;; esac # vim: ft=sh diff --git a/bootstrap/01_install.sh b/bootstrap/01_install.sh index e4581b6d..bf49af60 100755 --- a/bootstrap/01_install.sh +++ b/bootstrap/01_install.sh @@ -11,13 +11,14 @@ warning "This information needs to be entered in the host configuration BEFORE r info_applied=false while [ "$info_applied" = false ]; do readp "Have you updated your chosen host with the choose disk id? [N/y]: " result + # shellcheck disable=SC2154 case $result in - [Yy]) - info_applied=true - ;; - *) - warning "You won't be able to boot, if you don't update it!" - ;; + [Yy]) + info_applied=true + ;; + *) + warning "You won't be able to boot, if you don't update it!" + ;; esac done @@ -38,44 +39,44 @@ info_applied=false while [ "$info_applied" = false ]; do readp "Have you updated your chosen host with this information? [N/y]: " result case $result in - [Yy]) - info_applied=true - ;; - *) - warning "You won't be able to boot, if you don't update it!" - ;; + [Yy]) + info_applied=true + ;; + *) + warning "You won't be able to boot, if you don't update it!" + ;; esac done msg "Checking for incompatibilities..." ssd_or_hdd="$(cat /sys/block/"$(basename "$(readlink -f "/dev/disk/by-id/$NIX_DISK")" | tr -d '\n')"/queue/rotational)" case "$ssd_or_hdd" in - 0) - msg2 "You seem to use a ssd." - trim_support=$(lsblk --bytes --json --discard | jq --arg name "$(basename "$(readlink -f "/dev/disk/by-id/$NIX_DISK")" | tr -d '\n')" '.blockdevices | .[] | select(.name == $name) | (.["disc-gran"] + .["disc-max"]) != 0') - case $trim_support in - "true") - msg2 "Yay, your ssd supports trim, go on and activate it" - ;; - "false") - msg2 "Nay, your ssd doesn't support trim" - ;; - *) - warning "Your ssd doesn't seem to exists, if this bothers you please open an issue." - ;; - esac +0) + msg2 "You seem to use a ssd." + trim_support=$(lsblk --bytes --json --discard | jq --arg name "$(basename "$(readlink -f "/dev/disk/by-id/$NIX_DISK")" | tr -d '\n')" '.blockdevices | .[] | select(.name == $name) | (.["disc-gran"] + .["disc-max"]) != 0') + case $trim_support in + "true") + msg2 "Yay, your ssd supports trim, go on and activate it" ;; - 1) - msg2 "You seem to use a hdd there is nothing you have to do" + "false") + msg2 "Nay, your ssd doesn't support trim" ;; *) - warning "There is no indicator, which shows, which drive your are using.\n This means, that you have to check yourself, which optimizations you should activate." + warning "Your ssd doesn't seem to exists, if this bothers you please open an issue." ;; + esac + ;; +1) + msg2 "You seem to use a hdd there is nothing you have to do" + ;; +*) + warning "There is no indicator, which shows, which drive your are using.\n This means, that you have to check yourself, which optimizations you should activate." + ;; esac case "$INSTALL_TO_SETUP" in - "yes") - nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes' - ;; - *) ;; +"yes") + nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes' + ;; +*) ;; esac diff --git a/bootstrap/02_setup.sh b/bootstrap/02_setup.sh index 44368f69..7b539c52 100755 --- a/bootstrap/02_setup.sh +++ b/bootstrap/02_setup.sh @@ -16,8 +16,8 @@ chown 1000:100 --recursive /mnt/srv/home chmod 700 /mnt/srv/home case "$SETUP_TO_CONFIG_SETUP" in - "yes") - nix run "git+https://codeberg.org/soispha/nixos-config#config_setup" --experimental-features 'nix-command flakes' - ;; - *) ;; +"yes") + nix run "git+https://codeberg.org/soispha/nixos-config#config_setup" --experimental-features 'nix-command flakes' + ;; +*) ;; esac diff --git a/bootstrap/99_ensure_config_variables.sh b/bootstrap/99_ensure_config_variables.sh index ce8ffa0f..ba7d0a58 100755 --- a/bootstrap/99_ensure_config_variables.sh +++ b/bootstrap/99_ensure_config_variables.sh @@ -7,20 +7,20 @@ if ! [ "$NIX_ENVIRONMENT_VARIABLES_SET" ]; then if ! [ "$NIX_HOST" ]; then msg "Select a host:" _hosts=$(mktmp) - curl https://codeberg.org/soispha/nixos-config/raw/branch/prime/flake/nixosConfigurations/default.nix 2> /dev/null | awk -F '"' '/hosts = /{for (i=2;i<NF;i+=2) {print $i}}' > "$_hosts" + curl https://codeberg.org/soispha/nixos-config/raw/branch/prime/flake/nixosConfigurations/default.nix 2>/dev/null | awk -F '"' '/hosts = /{for (i=2;i<NF;i+=2) {print $i}}' >"$_hosts" - while ! grep "$host" "$_hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do + while ! grep "$host" "$_hosts" >/dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do i=1 while read -r host_read; do printf "%4s) %s \n" "$i" "$host_read" i=$((i + 1)) - done < "$_hosts" + done <"$_hosts" printf "%4s) Exit\n" "q" readp "Enter a option: " host [ "$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 + 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 @@ -29,16 +29,16 @@ if ! [ "$NIX_ENVIRONMENT_VARIABLES_SET" ]; then fi if ! [ "$NIX_DISK" ] && [ "$INSTALL" ]; then available_disks="$(mktmp)" - lsblk -J | jq '.[] | map(.name) | [foreach .[] as $item ({item: null, index: -1}; {$item, index: (.index + 1)})]' > "$available_disks" + 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:" i=9999 # nobody will have so many disks attached - while ! jq -e --argjson i "$i" '.[$i]' "$available_disks" > /dev/null 2>&1; do + 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 "\"")" + 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 @@ -48,9 +48,9 @@ if ! [ "$NIX_ENVIRONMENT_VARIABLES_SET" ]; then else i="$_disk" fi - if jq -e --argjson i "$i" 'nth($i)' "$available_disks" > /dev/null 2>&1; then + 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" + jq -e --argjson i "$i" 'nth($i)' "$available_disks" >"$_disk" else warning "No disk selected. Select a disk to continue.\n" fi @@ -58,65 +58,66 @@ if ! [ "$NIX_ENVIRONMENT_VARIABLES_SET" ]; then warn "All data on disk $(jq '.item' "$_disk") will be deleted." readp "Continue with this disk? [N/y]: " result + # shellcheck disable=SC2154 case "$result" in - [Yy]) - msg "Great, continuing..." - _disk="$(jq '.item' "$_disk" | tr -d "\"")" - _disk_serial="$(udevadm info --query=all --name="$_disk" | grep ID_SERIAL= | awk 'BEGIN{FS="="}{print $2}')" - case "$_disk" in - "nvme"*) - _nix_disk="nvme-$_disk_serial" - ;; - "sd"*) - _nix_disk="ata-$_disk_serial" - ;; - *) - die "Disk with name '$_disk' and serial '$_disk_serial' not yet supported!" - ;; - esac - export NIX_DISK="$_nix_disk" + [Yy]) + msg "Great, continuing..." + _disk="$(jq '.item' "$_disk" | tr -d '"')" + _disk_serial="$(udevadm info --query=all --name="$_disk" | grep ID_SERIAL= | awk 'BEGIN{FS="="}{print $2}')" + case "$_disk" in + "nvme"*) + _nix_disk="nvme-$_disk_serial" + ;; + "sd"*) + _nix_disk="ata-$_disk_serial" ;; *) - msg "Sure, keep your data" - exit 1 + die "Disk with name '$_disk' and serial '$_disk_serial' not yet supported!" ;; + esac + export NIX_DISK="$_nix_disk" + ;; + *) + msg "Sure, keep your data" + exit 1 + ;; esac fi if ! [ "$ACTIVATE_TO_SETUP" ] && ! [ "$INSTALL" ]; then readp "Do you want to continue with nixos-install after activation? [N/y]: " result case $result in - [Yy]) - export ACTIVATE_TO_SETUP=yes - ;; - *) - export ACTIVATE_TO_SETUP=no - ;; + [Yy]) + export ACTIVATE_TO_SETUP=yes + ;; + *) + export ACTIVATE_TO_SETUP=no + ;; esac fi if ! [ "$INSTALL_TO_SETUP" ] && [ "$INSTALL" ]; then readp "Do you want to continue with nixos-install after disk formatting? [N/y]: " result case $result in - [Yy]) - export INSTALL_TO_SETUP=yes - ;; - *) - export INSTALL_TO_SETUP=no - ;; + [Yy]) + export INSTALL_TO_SETUP=yes + ;; + *) + export INSTALL_TO_SETUP=no + ;; esac fi if ! [ "$SETUP_TO_CONFIG_SETUP" ]; then readp "Do you want to continue with the user configuration setup after setup? [N/y]: " result case $result in - [Yy]) - export SETUP_TO_CONFIG_SETUP=yes - ;; - *) - export SETUP_TO_CONFIG_SETUP=no - ;; + [Yy]) + export SETUP_TO_CONFIG_SETUP=yes + ;; + *) + export SETUP_TO_CONFIG_SETUP=no + ;; esac fi - export NIX_ENVIRONMENT_VARIABLES_SET="set"; + export NIX_ENVIRONMENT_VARIABLES_SET="set" fi # vim: ft=sh |