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 21, 2025
1 parent 5bfd0a7 commit 0379211
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/modules/system/a
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
t=0
while IFS== read key value; do
echo "$key=$value $t"
t=$(( t + 1 ))
done < <(lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE -e 252 --json | jq '.blockdevices[]? | select((.type | test ("disk")) and (.name | test ("boot")) | not)' | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]')


132 changes: 132 additions & 0 deletions tools/modules/system/module_partitioner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@


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]}")
list=()
periodic=1
while IFS== read key value; do
#echo "$periodic $key $value"
case "$key" in
"name") name="$value" ;;
"size") size=$(printf "%14s" "$value") ;;
"type") type=$(printf "%4s" "$value") ;;
"fsused") fsused="$value" ;;
"fstype") fstype=$(printf "%8s" "$value") ;;
"mountpoint") mountpoint="$value" ;;
esac
if [ "$(($periodic % 6))" -eq 0 ]; then
if [[ "$mountpoint" != "/" ]]; then
echo "$periodic $name $size $type $fsused $fstype $mountpoint"
list+=("${name}" "$(printf "%-20s" "$name") $type ${size} $fstype" "$driveinfo")
fi
fi
periodic=$(($periodic + 1))

done < <( \
lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE,MOUNTPOINT -e 252 --json \
| jq '.blockdevices[]? | select((.type | test ("disk") | not) and (.name | test ("mtdblock0|nvme|mmcblk|sd")))' \
| jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' \
)
#exit

while true; do
#list=()
#local json=$(lsblk -Alnp -io NAME,SIZE,FSUSED,MAJ:MIN,TYPE,FSTYPE -e 252 --json | jq '.blockdevices[]? | select(.name | test ("lock4") | not)')
#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"




0 comments on commit 0379211

Please sign in to comment.