Skip to content

Commit

Permalink
Module partitioner: frontend for new armbian-install
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Jan 20, 2025
1 parent 5bfd0a7 commit fcb1d9f
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tools/modules/system/module_partitioner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@


declare -A module_options
module_options+=(
["module_partitioner,author"]="@Tearran"
["module_partitioner,feature"]="module_partitioner"
["module_partitioner,example"]="run 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]}")

list=()
local json=$(lsblk -Alnp -io NAME,SIZE,FSUSED,MAJ:MIN,TYPE,FSTYPE -e 252 --json)
local partitions=$(echo $json | jq -r '.[] | .[].name ')
for part in $partitions; do
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

driveinfo=$(udevadm info --query=all --name=$part | grep 'ID_MODEL=' | cut -d"=" -f2)
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"
;;
"${commands[1]}")
echo "Removing $title..."
# Removal logic here
;;
"${commands[2]}")
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[2]}
;;
esac
}

# uncomment to test the module
module_partitioner "$1"




0 comments on commit fcb1d9f

Please sign in to comment.