Last active
July 10, 2020 19:37
-
-
Save ispanos/b671e8df58eae810d44ab17dc67f9d2f to your computer and use it in GitHub Desktop.
Some functions I was using on one of my scripts, but no longer use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# License: GNU GPLv3 | |
# setfont sun12x22 #HDPI | |
# dd bs=4M if=path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync | |
get_drive() { | |
# Sata and NVME drives array | |
drives=( $(/usr/bin/ls -1 /dev | grep -P "sd.$|nvme.*$" | grep -v "p.$") ) | |
# "NUM drive" for dialog prompt. Starts from 0 for compatibility with arrays | |
local -i n=0 | |
for i in "${drives[@]}" ; do | |
dialog_prompt="$dialog_prompt $n $i" | |
((n++)) | |
done | |
# Prompts user to select one of the available sda or nvme drives. | |
local dialogOUT | |
dialogOUT=$(dialog --title "Select your Hard-drive" \ | |
--menu "$(lsblk)" 0 0 0 $dialog_prompt 3>&1 1>&2 2>&3 3>&1 ) || exit | |
# Converts dialog output to the actuall name of the selected drive. | |
echo "/dev/${drives[$dialogOUT]}" | |
} | |
get_drive() { | |
# Asks user to select a /dev/sdX or /dev/nvme device and | |
# returns the selected device. | |
# Sata and NVME drives array | |
drives=( $(/usr/bin/ls -1 /dev | grep -P "sd.$|nvme.*$" | grep -v "p.$") ) | |
# Enumerates every drive like so: | |
# 1 /dev/sda 2 /dev/sdb 3 /dev/sdc 4 /dev/nvme0n1 ..... | |
local -i n=0 | |
for i in "${drives[@]}" ; do | |
dialog_prompt="$dialog_prompt $n $i" | |
((n++)) | |
done | |
# Prompts user to select one of the available sda or nvme drives. | |
local dialogOUT | |
dialogOUT=$(dialog --title "Select your Hard-drive" \ | |
--menu "$(lsblk)" 0 0 0 $dialog_prompt 3>&1 1>&2 2>&3 3>&1 ) || exit 1 | |
HARD_DRIVE="/dev/${drives[$dialogOUT]}" | |
[[ $HARD_DRIVE == *"nvme"* ]] && HARD_DRIVE="${HARD_DRIVE}p" | |
# Converts dialog output to the actuall name of the selected drive. | |
echo "$HARD_DRIVE" | |
} | |
dialog --yesno "Reboot computer?" 5 30 && reboot | |
dialog --yesno "Return to chroot environment?" 6 30 && arch-chroot /mnt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment