-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Module partitioner: frontend for new armbian-install
- Loading branch information
1 parent
5bfd0a7
commit 5ac8464
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
|
||
declare -A module_options | ||
module_options+=( | ||
["module_partitioner,author"]="@Tearran" | ||
["module_partitioner,feature"]="module_partitioner" | ||
["module_partitioner,example"]="new run create help" | ||
["module_partitioner,desc"]="Partitioner manager TUI" | ||
["module_partitioner,status"]="review" | ||
) | ||
|
||
function module_partitioner() { | ||
local title="Partitioner" | ||
local condition=$(which "$title" 2>/dev/null) | ||
|
||
# Convert the example string to an array | ||
local commands | ||
IFS=' ' read -r -a commands <<< "${module_options["module_partitioner,example"]}" | ||
|
||
case "$1" in | ||
"${commands[0]}") | ||
echo "New partition $2" | ||
exit | ||
;; | ||
"${commands[1]}") | ||
while true; do | ||
list=() | ||
local json=$(lsblk -Alnp -io NAME,SIZE,FSUSED,MAJ:MIN,TYPE,FSTYPE -e 252 --json) | ||
local partitions=$(echo $json | jq -r '.[] | .[].name ') | ||
echo "Reading storage devices and partitions " | ||
for part in $partitions; do | ||
echo -en "." | ||
local size=$(printf "%14s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .size')") | ||
local type=$(printf "%4s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .type')") | ||
local fstype=$(printf "%8s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .fstype' | sed 's/null//g')") | ||
|
||
# smartctl reading | ||
#if [[ $part == /dev/nvme* ]]; then | ||
#local driveinfo=$(smartctl -ij $part | jq -r '.model_name') | ||
#mapfile -t array < <(smartctl -ija $part | jq -r '.model_name, .nvme_total_capacity, .nvme_smart_health_information_log.data_units_written, .temperature.current') | ||
#capacity=$(echo ${array[1]} | awk '{ printf "%.2f\n", $1/1024/1024/1024; }')" GB" | ||
#tbw=$(echo ${array[2]} | awk '{ printf "%.2f\n", $1*500/1024/1024/1024; }')"" | ||
#temperature=$(echo ${array[3]})"℃" | ||
#fi | ||
#if [[ -n "${temperature}" ]]; then | ||
# driveinfo="Model: ${array[0]} | Capacity: ${capacity} | TBW: ${tbw} | Temperature: ${temperature}" | ||
#fi | ||
if [[ ${type} == disk ]]; then | ||
driveinfo=$(udevadm info --query=all --name=$part | grep 'ID_MODEL=' | cut -d"=" -f2 | sed "s/_//g") | ||
else | ||
unset driveinfo | ||
fi | ||
list+=("${part}" "$(printf "%-20s" "$part") $type ${size} $fstype" "$driveinfo") | ||
done | ||
|
||
list_length=${#list[@]} | ||
partitioner=$(dialog \ | ||
--notags \ | ||
--cancel-label "Cancel" \ | ||
--defaultno \ | ||
--ok-label "New" \ | ||
--erase-on-exit \ | ||
--extra-button \ | ||
--help-button \ | ||
--help-label "Select" \ | ||
--item-help \ | ||
--extra-label "Delete" \ | ||
--title "$title" --menu "\nStorage device Type Size FS type" $((${list_length} + 5)) 56 $((${list_length} + 1)) "${list[@]}" 3>&1 1>&2 2>&3) | ||
exitstatus=$? | ||
echo "$partitioner $exitstatus" | ||
|
||
if [[ ${exitstatus} -eq 1 ]]; then break; fi | ||
|
||
${module_options["module_partitioner,feature"]} ${commands[${exitstatus}]} $partitioner | ||
|
||
done | ||
;; | ||
"${commands[2]}") | ||
echo "Select $3" | ||
exit | ||
;; | ||
"${commands[3]}") | ||
echo "Delete $2" | ||
exit | ||
# Removal logic here | ||
;; | ||
"${commands[4]}") | ||
echo -e "\nUsage: ${module_options["module_partitioner,feature"]} <command>" | ||
echo -e "Commands: ${module_options["module_partitioner,example"]}" | ||
echo "Available commands:" | ||
echo -e "\trun\t- Run $title." | ||
echo | ||
;; | ||
*) | ||
${module_options["module_partitioner,feature"]} ${commands[4]} | ||
;; | ||
esac | ||
} | ||
|
||
# uncomment to test the module | ||
module_partitioner "$1" | ||
|
||
|
||
|
||
|