Skip to content

Commit 388a13d

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

File tree

2 files changed

+172
-0
lines changed

2 files changed

+172
-0
lines changed

Diff for: 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+

Diff for: tools/modules/system/module_partitioner.sh

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

0 commit comments

Comments
 (0)