Skip to content

Commit

Permalink
Use lazy loading package description
Browse files Browse the repository at this point in the history
  • Loading branch information
tiopex committed Oct 30, 2024
1 parent f148000 commit 90d7705
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 56 deletions.
84 changes: 42 additions & 42 deletions board/miyoo/boot/firstboot
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ default_console_func(){

#Test-prompt dialogs fo various scenarios
test_image_func(){
dialog --no-shadow --defaultno --ok-label NO --cancel-label Inverted --stdout --title " Test Image" \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --defaultno --ok-label NO --cancel-label Inverted --stdout --title " Test Image" \
--colors --pause "\n\n \Z5Are your colors Inverted?\Zn\n\nSelect an option & press START" 12 34 10

echo $? > $TEMP
Expand All @@ -171,7 +171,7 @@ test_image_func(){
# "NO" choice for Test_Image msgbox DIALOG_OK exit code
## thus we have valid version and simply continue
if test $CHOICE -eq 0; then
dialog --no-shadow --timeout 2 --msgbox "Colors are correct, proceed with flashing" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Colors are correct, proceed with flashing" 0 0
# "INVERTED" choice for Test_Iamge msgbox DIALOG_CANCEL exit code and -1/255
## thus correct "invert" colors parameter on video driver
else
Expand All @@ -182,7 +182,7 @@ test_image_func(){
}

test_video_func(){
dialog --no-shadow --defaultno --ok-label NO --cancel-label "Flipped!" --extra-button --extra-label YES --stdout --title " Test Video" \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --defaultno --ok-label NO --cancel-label "Flipped!" --extra-button --extra-label YES --stdout --title " Test Video" \
--colors --pause "\n\n \Z5Can you see this message?\Zn\n\nSelect an option & press START" 12 34 10

echo $? > $TEMP
Expand All @@ -204,13 +204,13 @@ test_video_func(){
safe_reboot_func
# Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255
else
dialog --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
sleep 1.5
fi
}

test_video2_func(){
dialog --no-shadow --defaultno --ok-label NO --cancel-label YES --stdout --title " Test Video'2" \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --defaultno --ok-label NO --cancel-label YES --stdout --title " Test Video'2" \
--colors --pause "\n\n \Z5Can you see this message?\Zn\n\nSelect an option & press START" 12 34 10

echo $? > $TEMP
Expand All @@ -229,7 +229,7 @@ test_video2_func(){
}

test_keyboard_func(){
dialog --no-shadow --ok-label NO --cancel-label YES --stdout --title " Test Keyboard" \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --ok-label NO --cancel-label YES --stdout --title " Test Keyboard" \
--colors --pause "\n\n \Z5Does D-pad works correctly?\Zn\n\nSelect an option & press START" 12 34 10

echo $? > $TEMP
Expand Down Expand Up @@ -266,13 +266,13 @@ test_keyboard_func(){
safe_reboot_func
# Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255
else
dialog --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
sleep 1.5
fi
}

test_variant_func(){
dialog --no-shadow --defaultno --ok-label NO --cancel-label YES --stdout --title " Test Variant" \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --defaultno --ok-label NO --cancel-label YES --stdout --title " Test Variant" \
--colors --pause "Does this device match yours?" 0 0 15

echo $? > $TEMP
Expand All @@ -287,16 +287,16 @@ test_variant_func(){
}

test_flip_func(){
if (dialog --no-shadow --stdout --ok-label YES --cancel-label NO --title "Test Flip" --pause " \n Flipped? \n\nAre you sure?!" 12 15 10); then
if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --stdout --ok-label YES --cancel-label NO --title "Test Flip" --pause " \n Flipped? \n\nAre you sure?!" 12 15 10); then
# Correct variant for bittboy3.5 (non forced) and display info about flipped image
echo "CONSOLE_VARIANT=bittboy3" > ${MOUNTDIR}/console.cfg
dialog --no-shadow --timeout 2 --msgbox "Image flipped! correct&reboot" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Image flipped! correct&reboot" 0 0
sleep 1.5
#TODO: use special Unicode characters to draw text upside-down e.g.:
## dialog --no-shadow --timeout 2 --msgbox "ƃuᴉʇooqǝɹ⅋uᴉʇɔǝɹɹoɔ 'pǝddᴉןɟ ǝƃɐɯᴉ \n\n image flipped, correcting&rebooting" 0 0
## dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "ƃuᴉʇooqǝɹ⅋uᴉʇɔǝɹɹoɔ 'pǝddᴉןɟ ǝƃɐɯᴉ \n\n image flipped, correcting&rebooting" 0 0
safe_reboot_func
else
dialog --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
sleep 1.5
fi
}
Expand All @@ -311,7 +311,7 @@ fi
detect_console_func
if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
if (grep -q "$DETECTED_1" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_1" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_1" 0 0
# Test_Video-prompt if proper miyoo video's version driver was loaded:
## Loop Test_Video until correct selection has been performed (CHOICE=0/3)
### former CHOICE=1 meant safe_reboot if correct and shouldn't reach to this point
Expand All @@ -322,10 +322,10 @@ if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
fi
done
elif (grep -q "$DETECTED_2" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_2" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_2" 0 0
echo "CONSOLE_VARIANT=m3" > ${MOUNTDIR}/console.cfg
elif (grep -q "$DETECTED_3" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_3" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_3" 0 0
echo "CONSOLE_VARIANT=m3_r61520" > ${MOUNTDIR}/console.cfg
# Test_Image-prompt if proper "invert" colors parameter was loaded:
INVERSION=0 #applied only if colors are inverted
Expand All @@ -334,19 +334,19 @@ if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
## DETECTED_4 - bittboy
## DETECTED_5 - bittboy3/2
elif (grep -q "$DETECTED_6" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_6" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_6" 0 0
echo "CONSOLE_VARIANT=m3_rm68090" > ${MOUNTDIR}/console.cfg
elif (grep -q "$DETECTED_7" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_7" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_7" 0 0
#echo "CONSOLE_VARIANT=r61520" > ${MOUNTDIR}/console.cfg
elif (grep -q "$DETECTED_8" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_8" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_8" 0 0
#echo "CONSOLE_VARIANT=r61505w" > ${MOUNTDIR}/console.cfg
elif (grep -q "$DETECTED_9" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_9" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_9" 0 0
echo "CONSOLE_VARIANT=m3_hx8347d" > ${MOUNTDIR}/console.cfg
elif (grep -q "$DETECTED_10" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_10" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_10" 0 0
#echo "CONSOLE_VARIANT=unknown-error" > ${MOUNTDIR}/console.cfg
fi
# Overwrite CONSOLE_VARIANT from new entry
Expand All @@ -362,7 +362,7 @@ detect_console_func
if ! $FOUND_CONSOLE && $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
# show selection menu for ST7789S devices
if (test "$CONSOLE_VARIANT" == "st7789s" && grep -q "$DETECTED_1" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --clear --timeout 60 --title "Select your device:" --menu " " 15 40 5 \
dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --timeout 60 --title "Select your device:" --menu " " 15 40 5 \
1 "Powkiddy Q20" \
2 "Powkiddy Q90" \
3 "Powkiddy V90" \
Expand Down Expand Up @@ -395,16 +395,16 @@ if ! $FOUND_CONSOLE && $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
cp ${MOUNTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${MOUNTDIR}/suniv-f1c100s-miyoo.dtb
;;
*)
dialog --no-shadow --timeout 4 --msgbox "Invalid choice. Exiting and selecting default device from autodetection." 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 4 --msgbox "Invalid choice. Exiting and selecting default device from autodetection." 0 0
default_console_func
sleep 0.1
;;
esac
elif (((test "$CONSOLE_VARIANT" == "bittboy2" || test "$CONSOLE_VARIANT" == "bittboy3") && grep -q "$DETECTED_5" "${MOUNTDIR}/uEnv.txt") || ((test "$CONSOLE_VARIANT" == "xyc" || test "$CONSOLE_VARIANT" == "m3") && grep -q "$DETECTED_2" "${MOUNTDIR}/uEnv.txt")); then
if (grep -q "$DETECTED_5" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_5" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_5" 0 0
elif (grep -q "$DETECTED_2" "${MOUNTDIR}/uEnv.txt"); then
dialog --no-shadow --timeout 4 --msgbox "Correcting $DETECTED_2 - wait for further instructions" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 4 --msgbox "Correcting $DETECTED_2 - wait for further instructions" 0 0
fi
# Test_Keyboard-prompt if proper miyoo.kbd version was loaded:
## Loop Test_Keyboard until correct selection has been performed (CHOICE=0/1)
Expand All @@ -415,7 +415,7 @@ if ! $FOUND_CONSOLE && $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
fi
done
elif (test "$CONSOLE_VARIANT" == "bittboy" && grep -q "$DETECTED_4" "${MOUNTDIR}/uEnv.txt") ; then
dialog --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_4" 0 0
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_4" 0 0
# Test_Video'2-prompt if proper miyoo video's version driver was loaded:
test_video2_func
fi
Expand All @@ -429,69 +429,69 @@ if $FOUND_CONSOLE; then
# Info_Box about selected/edited device in console.cfg
case $CONSOLE_VARIANT in
bittboy2x_v1)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy2x v1" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy2x v1" 5 18
BITTBOY_CONFIG=true
;;
bittboy2x_v2)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy2x v2" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy2x v2" 5 18
BITTBOY_CONFIG=true
;;
bittboy3.5)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy3.5" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy3.5" 5 18
BITTBOY_CONFIG=true
;;
q20)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q20" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q20" 5 18
MIYOO_CONFIG=true
;;
q90)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q90" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q90" 5 18
MIYOO_CONFIG=true
;;
v90)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy V90" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy V90" 5 18
MIYOO_CONFIG=true
;;
pocketgo)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " PocketGo" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " PocketGo" 5 18
MIYOO_CONFIG=true
;;
pocketgo_TE)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " PocketGo+TE" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " PocketGo+TE" 5 18
MIYOO_CONFIG=true
;;
xyc_gc9306)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " XYC Q8" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " XYC Q8" 5 18
MIYOO_CONFIG=true
;;
m3_r61520)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n (controller of r61520fb)" 6 29
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n (controller of r61520fb)" 6 29
MIYOO_CONFIG=true
;;
m3_rm68090)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(RM68090 controller)" 6 24
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(RM68090 controller)" 6 24
MIYOO_CONFIG=true
;;
m3_hx8347d)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(HX8347D controller)" 6 24
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(HX8347D controller)" 6 24
MIYOO_CONFIG=true
;;
m3_gc9306)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(GC9306 controller)" 6 24
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " SUP M3\n(GC9306 controller)" 6 24
MIYOO_CONFIG=true
;;
*)
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox "\Zb\Z1 Unknown-Error\Zn" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox "\Zb\Z1 Unknown-Error\Zn" 5 18
esac
# Test_Variant-prompt if correct CONSOLE_VARIANT has been written to console.cfg
test_variant_func
else
dialog --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox "\Zb\Z1 Unknown\Zn" 5 18
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox "\Zb\Z1 Unknown\Zn" 5 18
console_unknown_func
fi

# License_agreement-prompt
if (dialog --no-shadow --clear --ok-label NO --cancel-label YES --stdout --title " License agreement" \
if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --ok-label NO --cancel-label YES --stdout --title " License agreement" \
--colors --pause "\n \ZbMiyooCFW\Zn\n$LICENSE" 22 60 30 || test $? -eq 255); then
echo -en " We understand. Have a nice day!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
sleep 1
Expand Down Expand Up @@ -527,7 +527,7 @@ SD_MAX_AVAIL_SIZE_IN_KiB=$((SD_MAX_AVAIL_SIZE * 512 / 1024))

# Expand_MAIN_Partition-prompt for fatresize the p4 partition if requested
RESIZE_COMMENCED=false
if (dialog --no-shadow --clear --stdout --ok-label YES --cancel-label NO --title " AUTO-RESIZE" \
if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --stdout --ok-label YES --cancel-label NO --title " AUTO-RESIZE" \
--colors --pause "\n\n \Z5Expand MAIN partition?\Zn\n\n Select an option & press START
\n\n \ZbWARNING:\Zn\n After 10s auto-resize\n of BTRFS partition will begin." 15 60 10); then
clear
Expand Down
47 changes: 33 additions & 14 deletions board/miyoo/boot/ipk_install.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
#!/bin/bash

export TERM=linux
ipk_directory="/mnt/ipk"
package_list=()

help_messages=()
index=1
for ipk_file in "$ipk_directory"/*.ipk; do
if [[ -f "$ipk_file" ]]; then
package_info=$(opkg info "$ipk_file")
package_name=$(echo "$package_info" | grep "^Package:" | cut -d' ' -f2)
package_description=$(echo "$package_info" | grep "^Description:" | cut -d' ' -f2-)

if [[ -n "$package_name" ]]; then
package_list+=("$package_name" "$package_description" "off")
fi
ipk_name=$(basename -s .ipk "$ipk_file")
package_list+=("$index" "$ipk_name" "off")
help_messages[$((2 * index))]="$index"
help_messages[$((2 * index + 1))]="$ipk_file"
((index++))
fi
done

if [[ ${#package_list[@]} -eq 0 ]]; then
echo "No packages to install."
exit 1
fi


selected_packages=$(dialog --no-shadow --clear --colors --visit-items --title "IPK Package manager" --checklist 'Press Y to select packages to install:' 20 80 15 "${package_list[@]}" 3>&1 1>&2 2>&3)
until selected_packages=$(dialog --backtitle "MiyooCFW 2.0" --title "IPK package manager" --no-shadow --help-button --help-status --checklist "Press Y to select packages to install:" 20 60 15 "${package_list[@]}" 3>&1 1>&2 2>&3); do
case $? in
(1) btn=Cancel && break;;
(2)
set -- $selected_packages
shift
index=$1
package_info=$(opkg info "${help_messages[$((2 * index + 1))]}")
package_name=$(echo "$package_info" | grep "^Package:" | cut -d' ' -f2)
package_description=$(echo "$package_info" | grep "^Description:" | cut -d' ' -f2-)
dialog --no-shadow --msgbox "$package_name: $package_description" 0 0
for ((i = 2; i < ${#package_list[@]}; i += 3)); do
package_list[$i]="off"
done
shift
for selected in "$@"; do
package_list[$((3 * selected - 1))]="on"
done
esac
done

clear
if [[ $? -ne 0 || -z "$selected_packages" ]]; then
echo "No packages were selected."
exit 1
fi

for package in $selected_packages; do
ipk_package="${package}.ipk"
ipk_package="${help_messages[$((2 * package + 1))]}"
echo "Installing $ipk_package..."
if opkg install "$ipk_directory/$ipk_package" 2>/dev/null; then
echo "$ipk_package installed successfully."
if opkg install "$ipk_package" 2>/dev/null; then
echo "$ipk_package installed successfully."
else
echo "Failed to install $ipk_package."
echo "Failed to install $ipk_package."
fi
done

Expand Down

0 comments on commit 90d7705

Please sign in to comment.