Skip to content

Commit 9ef36ab

Browse files
committed
Module partitioner: frontend for new armbian-install
1 parent 5bfd0a7 commit 9ef36ab

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

tools/modules/system/a

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
t=0
3+
while IFS== read key value; do
4+
echo "$key=$value $t"
5+
t=$(( t + 1 ))
6+
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)")|.[]')
7+
8+
+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
2+
3+
declare -A module_options
4+
module_options+=(
5+
["module_partitioner,author"]="@Tearran"
6+
["module_partitioner,feature"]="module_partitioner"
7+
["module_partitioner,example"]="new run create help"
8+
["module_partitioner,desc"]="Partitioner manager TUI"
9+
["module_partitioner,status"]="review"
10+
)
11+
12+
function module_partitioner() {
13+
local title="Partitioner"
14+
local condition=$(which "$title" 2>/dev/null)
15+
16+
# Convert the example string to an array
17+
local commands
18+
IFS=' ' read -r -a commands <<< "${module_options["module_partitioner,example"]}"
19+
20+
case "$1" in
21+
"${commands[0]}")
22+
echo "New partition $2"
23+
exit
24+
;;
25+
"${commands[1]}")
26+
27+
devices=$(
28+
lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE,MOUNTPOINT -e 252 --json \
29+
| jq '.blockdevices[]? | select((.name | test ("boot") | not) and (.name | test ("mtdblock0|nvme|mmcblk|sd")))' \
30+
| jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]'
31+
)
32+
33+
list=()
34+
periodic=1
35+
while IFS== read key value; do
36+
#echo "$periodic $key $value"
37+
case "$key" in
38+
"name") name="$value" ;;
39+
"size") size=$(printf "%14s" "$value") ;;
40+
"type") type=$(printf "%4s" "$value") ;;
41+
"fsused") fsused="$value" ;;
42+
"fstype") fstype="$value" ;;
43+
"mountpoint") mountpoint="$value" ;;
44+
esac
45+
if [ "$(($periodic % 6))" -eq 0 ]; then
46+
47+
48+
49+
###
50+
if [[ $mountpoint ]]; then
51+
partitions=$(
52+
lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE,MOUNTPOINT -e 252 --json \
53+
| jq --arg name "$name" '.blockdevices[]? | select((.name | test ("disk") | not) and (.name | test ($name)))' \
54+
| jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]'
55+
)
56+
while IFS== read a b; do
57+
[[ $a == "mountpoint" ]] && echo ">>> $name $b"
58+
done <<< "$partitions"
59+
fi
60+
###
61+
62+
63+
64+
echo "$periodic $name $size $type $fsused $fstype $mountpoint"
65+
if [[ "$mountpoint" != "/" && "$type" == "disk" ]]; then
66+
echo "$periodic $name $size $type $fsused $fstype $mountpoint"
67+
list+=("${name}" "$(printf "%-20s" "$name") $type ${size} $fstype" "$driveinfo")
68+
fi
69+
fi
70+
periodic=$(($periodic + 1))
71+
done <<< "$devices"
72+
73+
#done < <( \
74+
# lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE,MOUNTPOINT -e 252 --json \
75+
# | jq '.blockdevices[]? | select((.name | test ("boot") | not) and (.name | test ("mtdblock0|nvme|mmcblk|sd")))' \
76+
# | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' \
77+
# )
78+
exit
79+
80+
#lsblk -Alnp -io NAME,SIZE,FSUSED,TYPE,FSTYPE,MOUNTPOINT -e 252 --json \
81+
#| jq '.blockdevices[]? | select((.type | test ("part") | not) and (.name | test ("mtdblock0|nvme|mmcblk|sd")))' \
82+
#| jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' \
83+
84+
while true; do
85+
#list=()
86+
#local json=$(lsblk -Alnp -io NAME,SIZE,FSUSED,MAJ:MIN,TYPE,FSTYPE -e 252 --json | jq '.blockdevices[]? | select(.name | test ("lock4") | not)')
87+
#local partitions=$(echo $json | jq -r '.[] | .[].name ')
88+
#echo "Reading storage devices and partitions "
89+
#for part in $partitions; do
90+
# echo -en "."
91+
# local size=$(printf "%14s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .size')")
92+
# local type=$(printf "%4s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .type')")
93+
# local fstype=$(printf "%8s" "$(echo $json | jq -r '.[]' | jq -r '.[] | select(.name == "'$part'") .fstype' | sed 's/null//g')")
94+
95+
# smartctl reading
96+
#if [[ $part == /dev/nvme* ]]; then
97+
#local driveinfo=$(smartctl -ij $part | jq -r '.model_name')
98+
#mapfile -t array < <(smartctl -ija $part | jq -r '.model_name, .nvme_total_capacity, .nvme_smart_health_information_log.data_units_written, .temperature.current')
99+
#capacity=$(echo ${array[1]} | awk '{ printf "%.2f\n", $1/1024/1024/1024; }')" GB"
100+
#tbw=$(echo ${array[2]} | awk '{ printf "%.2f\n", $1*500/1024/1024/1024; }')""
101+
#temperature=$(echo ${array[3]})"℃"
102+
#fi
103+
#if [[ -n "${temperature}" ]]; then
104+
# driveinfo="Model: ${array[0]} | Capacity: ${capacity} | TBW: ${tbw} | Temperature: ${temperature}"
105+
#fi
106+
# if [[ ${type} == disk ]]; then
107+
# driveinfo=$(udevadm info --query=all --name=$part | grep 'ID_MODEL=' | cut -d"=" -f2 | sed "s/_//g")
108+
# else
109+
# unset driveinfo
110+
# fi
111+
# list+=("${part}" "$(printf "%-20s" "$part") $type ${size} $fstype" "$driveinfo")
112+
#done
113+
114+
list_length=${#list[@]}
115+
partitioner=$(dialog \
116+
--notags \
117+
--cancel-label "Cancel" \
118+
--defaultno \
119+
--ok-label "New" \
120+
--erase-on-exit \
121+
--extra-button \
122+
--help-button \
123+
--help-label "Select" \
124+
--item-help \
125+
--extra-label "Delete" \
126+
--title "$title" --menu "\nStorage device Type Size FS type" $((${list_length} + 5)) 56 $((${list_length} + 1)) "${list[@]}" 3>&1 1>&2 2>&3)
127+
exitstatus=$?
128+
echo "$partitioner $exitstatus"
129+
130+
if [[ ${exitstatus} -eq 1 ]]; then break; fi
131+
132+
${module_options["module_partitioner,feature"]} ${commands[${exitstatus}]} $partitioner
133+
134+
done
135+
;;
136+
"${commands[2]}")
137+
echo "Select $3"
138+
exit
139+
;;
140+
"${commands[3]}")
141+
echo "Delete $2"
142+
exit
143+
# Removal logic here
144+
;;
145+
"${commands[4]}")
146+
echo -e "\nUsage: ${module_options["module_partitioner,feature"]} <command>"
147+
echo -e "Commands: ${module_options["module_partitioner,example"]}"
148+
echo "Available commands:"
149+
echo -e "\trun\t- Run $title."
150+
echo
151+
;;
152+
*)
153+
${module_options["module_partitioner,feature"]} ${commands[4]}
154+
;;
155+
esac
156+
}
157+
158+
# uncomment to test the module
159+
module_partitioner "$1"
160+
161+
162+
163+

0 commit comments

Comments
 (0)