Files
buildroot/board/miyoo/boot/firstboot
T
Apaczer ba175a94f3 BOARD: allow FileSystem change for every present type (#175)
* BOARD: firstboot: use while loops instead of sleep

* BOARD: main: run `firstboot` simply in subshell

* firstboot: add SWAP label

* firstboot: allow to redo FS change for every type

* firsboot: rm roundup in BOOT_SIZE of gpt align

* firsboot: FAT32 is in fact vfat type

* add logs for parted cmd in p5 resize - also output LICENSE sign info

* add `FIRSTBOOT=1` opt to rerun flashing wizard
2025-06-08 22:06:39 +02:00

901 lines
37 KiB
Plaintext

#!/bin/busybox sh
export TERM=linux
# expect to be run from /boot, where the boot partition is mounted (readonly)
LOG=${HOME}/log_firstboot.txt
LOG_TEMP=$(mktemp)
export LOG
export LOG_TEMP
restore_temp_log_func(){
cat ${LOG_TEMP} >> ${LOG}
sleep 2
LOG_TEMP=$(mktemp)
}
restore_dmesg_log_func(){
echo -en "\nNew DMESG log:\n" >> ${HOME}/dmesg.txt
sleep 2
dmesg >> ${HOME}/dmesg.txt
}
# high brightness
echo '10' > /sys/devices/platform/backlight/backlight/backlight/brightness
#echo -e "\e[?3c"
#echo -e "\e[32m" # green
echo -en "\e[32mfirstboot script running...\e[0m" | tee -a ${LOG}
# run a custom script if present - could be used to fix u-boot and such
if test -r "${BOOTDIR}/firstboot.custom.sh"; then
echo "Running a specific firstboot script..." | tee -a ${LOG}
(cd "${BOOTDIR}" && sh firstboot.custom.sh) 2>&1 | tee -a ${LOG}
echo "Finished running a specific firstboot script." | tee -a ${LOG}
fi
echo " "
sleep 1
LICENSE="
The software provided is offered without \
any warranties or guarantees of any kind, either \
expressed or implied. The use of this software is \
entirely at your own risk. We shall not be held \
responsible for any damages, losses, or adverse \
consequences arising from the use or misuse of this software.
\n\n
\Z5Do you acknowledge and agree to these terms?\Zn
\n\n
Select an option & press START"
## Create temp file to store variable for menu choice
TEMP=$(mktemp)
## Access /boot directory
mount -o remount,rw "${BOOTDIR}" 2>&1 | tee -a ${LOG}
# list of available devices in u-boot Environment parameters' read from FORCE_VERSION
devices_ID="
bittboy2x_v1
bittboy2x_v2
bittboy3.5
q20
q90
v90
pocketgo
pocketgo_TE
xyc_gc9306
m3_r61520
m3_rm68090
m3_hx8347d
m3_gc9306
"
# list of available devices in u-boot Environment parameters' read from Auto-Detection method
devices_auto_ID="
st7789s
bittboy
bittboy2
bittboy3
xyc
m3
"
# list of available devices in this flashing procedure read from DETECTED_VERSION in u-boot Environment parameters'
DETECTED_1="V90/Q90/Q20/PocketGo ST7789S controller"
DETECTED_2="GC9306/GC9305 controller from gc9306fb"
DETECTED_3="SUP M3 unknown controller Works with R61520"
DETECTED_4="bittboy2x_v1 r61520fb controller"
DETECTED_5="bittboy3.5/bittboy2x_v2 ST7789S controller"
DETECTED_6="RM68090 controller"
DETECTED_7="R61520 controller"
DETECTED_8="R61505W controller"
DETECTED_9="HX8347-D controller"
DETECTED_10="UNKNOWN"
## Defaulting to "not found the console in string list"
FOUND_CONSOLE=false
FOUND_CONSOLE_AUTO=false
find_console_func(){
for i in $devices_ID; do
if test "$i" = "$CONSOLE_VARIANT"; then
FOUND_CONSOLE=true
break
fi
done
}
find_console_auto_func(){
for i in $devices_auto_ID; do
if test "$i" = "$CONSOLE_VARIANT"; then
FOUND_CONSOLE_AUTO=true
break
fi
done
}
# try to read what handheld we're on when calling func
console_var_func(){
if (test -r "${BOOTDIR}/console.cfg"); then
source "${BOOTDIR}/console.cfg"
else
export CONSOLE_VARIANT="unknown"
fi
}
detect_console_func(){
console_var_func
find_console_func
find_console_auto_func
}
# write logs, sync & unmount MAIN before reboot/poweroff
safe_shutdown_func(){
echo "please wait a few seconds for a ${SHUTDOWN}...." | tee -a ${LOG}
restore_dmesg_log_func
sync
while (pgrep "sync"); do
sleep 1
done
mount -o remount,ro "${BOOTDIR}" 2>&1 | tee -a ${LOG}
sleep 2
umount /dev/mmcblk0p4 2>&1 # | tee -a ${LOG} - logging here may brake unmouting
#umount /dev/mmcblk0p1 # this fails cuz we're running this script of /boot
while (pgrep "umount"); do
sleep 1
done
}
safe_reboot_func(){
SHUTDOWN=reboot
safe_shutdown_func
reboot
sleep 10000
}
safe_poweroff_func(){
SHUTDOWN=poweroff
safe_shutdown_func
poweroff
sleep 10000
}
console_unknown_func(){
echo "CONSOLE_VARIANT=unknown" | tee ${BOOTDIR}/console.cfg >> ${LOG}
echo "##DO_NOT_REMOVE_THIS_LINE##" >> ${BOOTDIR}/console.cfg
}
## Default CONSOLE_VARIANT for st7789s screens
default_console_func(){
echo "CONSOLE_VARIANT=pocketgo" | tee ${BOOTDIR}/console.cfg >> ${LOG}
cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb
# No need to overwrite uboot FORCE version for default so continue procedure
CONSOLE_OVERWRITE=false
}
#Test-prompt dialogs fo various scenarios
test_image_func(){
echo "Performing Image Color Test" >> ${LOG}
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
## Read the user's last choice from the tmp file
CHOICE=$(cat $TEMP)
# "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 --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Colors are correct, proceed with flashing" 0 0
echo "Colors are correct" >> ${LOG}
# "INVERTED" choice for Test_Iamge msgbox DIALOG_CANCEL exit code and -1/255
## thus correct "invert" colors parameter on video driver
else
#TODO - make "invert" flag overwriting less dependent
echo "Colors are inverted, changing..." | tee -a ${LOG}
sed -i '/^INVERT=/d' ${HOME}/options.cfg | tee -a ${LOG}
echo "INVERT=${INVERSION}" >> ${HOME}/options.cfg
safe_reboot_func
fi
}
test_video_func(){
echo "Performing Video Test" >> ${LOG}
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
## Read the user's first choice from the tmp file
CHOICE=$(cat $TEMP)
# "YES" choice for Test_Video msgbox DIALOG_EXTRA exit code
if test $CHOICE -eq 3; then
# Correct variant for st7789s (non forced)
echo "CONSOLE_VARIANT=st7789s" | tee ${BOOTDIR}/console.cfg >> ${LOG}
# "Flipped!" choice for Test_Video msgbox DIALOG_CANCEL exit code
elif test $CHOICE -eq 1; then
# Test_Flip-prompt double checks if user selected correct answer for 1'st video test
test_flip_func
# "NO" or timeout choice for Test_Video msgbox thus DIALOG_OK exit code
elif test $CHOICE -eq 0; then
# Correct variant for bittboy2x_v1 (non forced)
echo "CONSOLE_VARIANT=bittboy" | tee ${BOOTDIR}/console.cfg >> ${LOG}
safe_reboot_func
# Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255
else
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(){
echo "Performing Video Test-2 " >> ${LOG}
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
## Read the user's last choice from the tmp file
CHOICE=$(cat $TEMP)
# "YES" choice for Test_Video'2 msgbox DIALOG_CANCEL exit code
## thus we have valid version, just update to FORCE_VERSION and continue
if test $CHOICE -eq 1; then
echo "CONSOLE_VARIANT=bittboy2x_v1" | tee ${BOOTDIR}/console.cfg >> ${LOG}
# "NO" or timeout choice for Test_Video msgbox thus DIALOG_OK exit code 0 (or ERROR/ESCAPE with -1/255)
## correct variant to unknown and redo whole flashing_prd again
else
console_unknown_func
safe_reboot_func
fi
}
test_keyboard_func(){
echo "Performing Keyboard Test" >> ${LOG}
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
## Read the user's last choice from the tmp file
CHOICE=$(cat $TEMP)
# "YES" choice for Test_Keyboard msgbox DIALOG_CANCEL exit code
## thus we have valid version, just update to FORCE_VERSION and continue
if test $CHOICE -eq 1; then
if test "$CONSOLE_VARIANT" == "bittboy3"; then
echo "CONSOLE_VARIANT=bittboy3.5" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif test "$CONSOLE_VARIANT" == "bittboy2"; then
echo "CONSOLE_VARIANT=bittboy2x_v2" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif test "$CONSOLE_VARIANT" == "xyc"; then
echo "CONSOLE_VARIANT=xyc_gc9306" | tee ${BOOTDIR}/console.cfg >> ${LOG}
# Test_Image-prompt if proper "invert" colors parameter was loaded:
INVERSION=1 #applied only if colors are inverted
test_image_func
elif test "$CONSOLE_VARIANT" == "m3"; then
echo "CONSOLE_VARIANT=m3_gc9306" | tee ${BOOTDIR}/console.cfg >> ${LOG}
fi
# "NO" or timeout choice for Test_Keyboard msgbox DIALOG_OK exit code
## thus correct Auto-Detection variant and reboot
elif test $CHOICE -eq 0; then
if test "$CONSOLE_VARIANT" == "bittboy3"; then
echo "CONSOLE_VARIANT=bittboy2" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif test "$CONSOLE_VARIANT" == "bittboy2"; then
console_unknown_func
elif test "$CONSOLE_VARIANT" == "xyc"; then
console_unknown_func
elif test "$CONSOLE_VARIANT" == "m3"; then
echo "CONSOLE_VARIANT=xyc" | tee ${BOOTDIR}/console.cfg >> ${LOG}
fi
safe_reboot_func
# Error (DIALOG_ERROR) or ESCAPE button pressed (DIALOG_ESCAPE) thus exit code -1/255
else
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(){
echo "Performing Device-Variant Test" >> ${LOG}
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
## Read the user's last choice from the tmp file
CHOICE=$(cat $TEMP)
# Any choice different than "YES" from Test_Variant - that is 0/-1/255 exit code
## correct variant to unknown and redo whole flashing_prd again
if !(test $CHOICE -eq 1); then
console_unknown_func
safe_reboot_func
fi
}
test_flip_func(){
echo "Performing Confirmation Flip Test" >> ${LOG}
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" | tee ${BOOTDIR}/console.cfg >> ${LOG}
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 --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 --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Invalid choice, please redo the test!" 0 0
sleep 1.5
fi
}
#Checking if device at hand is operational within flashing procedure
CONSOLE_DETECTED=false
if (grep -qE "${DETECTED_1}|${DETECTED_2}|${DETECTED_3}|${DETECTED_4}|${DETECTED_5}|${DETECTED_6}|${DETECTED_7}|${DETECTED_8}|${DETECTED_9}|${DETECTED_10}" "${BOOTDIR}/uEnv.txt"); then
CONSOLE_DETECTED=true
fi
# I - Test_Block
echo "Starting I Block - Test" >> ${LOG}
detect_console_func
if ! $FOUND_CONSOLE && ! $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
echo "Auto-Detected Console's variant from uEnv" >> ${LOG}
if (grep -q "$DETECTED_1" "${BOOTDIR}/uEnv.txt"); then
echo "Auto-Detected $DETECTED_1" >> ${LOG}
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
while true; do
test_video_func
if !(test $CHOICE -eq -1 || test $CHOICE -eq 1 || test $CHOICE -eq 255); then
break
fi
done
elif (grep -q "$DETECTED_2" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_2" 0 0
echo "CONSOLE_VARIANT=m3" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif (grep -q "$DETECTED_3" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_3" 0 0
echo "CONSOLE_VARIANT=m3_r61520" | tee ${BOOTDIR}/console.cfg >> ${LOG}
# Test_Image-prompt if proper "invert" colors parameter was loaded:
INVERSION=0 #applied only if colors are inverted
test_image_func
# look in II Test block for following DETECTED versions as these imply devices_auto_ID variants:
## DETECTED_4 - bittboy
## DETECTED_5 - bittboy3/2
elif (grep -q "$DETECTED_6" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_6" 0 0
echo "CONSOLE_VARIANT=m3_rm68090" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif (grep -q "$DETECTED_7" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_7" 0 0
#echo "CONSOLE_VARIANT=r61520" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif (grep -q "$DETECTED_8" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_8" 0 0
#echo "CONSOLE_VARIANT=r61505w" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif (grep -q "$DETECTED_9" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_9" 0 0
echo "CONSOLE_VARIANT=m3_hx8347d" | tee ${BOOTDIR}/console.cfg >> ${LOG}
elif (grep -q "$DETECTED_10" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_10" 0 0
echo "Auto-Detected $DETECTED_10, so we have trouble finding correct drivers..." >> ${LOG}
#echo "CONSOLE_VARIANT=unknown-error" | tee ${BOOTDIR}/console.cfg >> ${LOG}
fi
# Overwrite CONSOLE_VARIANT from new entry
source "${BOOTDIR}/console.cfg"
fi
# II - Test_Block
echo "Starting II Block - Test" >> ${LOG}
## Defaulting to console overwriting inactive
CONSOLE_OVERWRITE=false
## Test if console have been found in devices_auto_ID
detect_console_func
## test if no device specified in console.cfg
if ! $FOUND_CONSOLE && $FOUND_CONSOLE_AUTO && $CONSOLE_DETECTED; then
# show selection menu for ST7789S devices
if (test "$CONSOLE_VARIANT" == "st7789s" && grep -q "$DETECTED_1" "${BOOTDIR}/uEnv.txt"); then
echo "Selecting device by end-user choice." >> ${LOG}
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" \
4 "PocketGO (default)" \
5 "PocketGO with TE pin" \
2> $TEMP
## Defaulting to console overwriting active
CONSOLE_OVERWRITE=true
## Read the user's choice from the file
CHOICE=$(cat $TEMP)
## Perform actions based on the user's choice
case $CHOICE in
1)
echo "CONSOLE_VARIANT=q20" | tee ${BOOTDIR}/console.cfg >> ${LOG}
cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb
;;
2)
echo "CONSOLE_VARIANT=q90" | tee ${BOOTDIR}/console.cfg >> ${LOG}
cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb
;;
3)
echo "CONSOLE_VARIANT=v90" | tee ${BOOTDIR}/console.cfg >> ${LOG}
cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb
;;
4)
default_console_func
;;
5)
echo "CONSOLE_VARIANT=pocketgo_TE" | tee ${BOOTDIR}/console.cfg >> ${LOG}
cp ${BOOTDIR}/suniv-f1c100s-miyoo-4bit.dtb ${BOOTDIR}/suniv-f1c100s-miyoo.dtb
;;
*)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 4 --msgbox "Invalid choice. Exiting and selecting default device from autodetection." 0 0
echo "Selecting default device from autodetection..." >> ${LOG}
default_console_func
sleep 0.1
;;
esac
elif (((test "$CONSOLE_VARIANT" == "bittboy2" || test "$CONSOLE_VARIANT" == "bittboy3") && grep -q "$DETECTED_5" "${BOOTDIR}/uEnv.txt") || ((test "$CONSOLE_VARIANT" == "xyc" || test "$CONSOLE_VARIANT" == "m3") && grep -q "$DETECTED_2" "${BOOTDIR}/uEnv.txt")); then
echo "Extra Auto-Detected Console's variant from uEnv" >> ${LOG}
if (grep -q "$DETECTED_5" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_5" 0 0
echo "Auto-Detected $DETECTED_5" >> ${LOG}
elif (grep -q "$DETECTED_2" "${BOOTDIR}/uEnv.txt"); then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 4 --msgbox "Correcting $DETECTED_2 - wait for further instructions" 0 0
echo "Auto-Detected $DETECTED_2" >> ${LOG}
fi
# Test_Keyboard-prompt if proper miyoo.kbd version was loaded:
## Loop Test_Keyboard until correct selection has been performed (CHOICE=0/1)
while true; do
test_keyboard_func
if !(test $CHOICE -eq -1 || test $CHOICE -eq 255); then
break
fi
done
elif (test "$CONSOLE_VARIANT" == "bittboy" && grep -q "$DETECTED_4" "${BOOTDIR}/uEnv.txt") ; then
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 3 --msgbox "Auto-Detected $DETECTED_4" 0 0
echo "Auto-Detected $DETECTED_4" >> ${LOG}
# Test_Video'2-prompt if proper miyoo video's version driver was loaded:
test_video2_func
fi
fi
# III - Test_Block
echo "Starting III Block - Test" >> ${LOG}
detect_console_func
BITTBOY_CONFIG=false
MIYOO_CONFIG=false
if $FOUND_CONSOLE; then
echo "Found console ${CONSOLE_VARIANT}" >> ${LOG}
# Info_Box about selected/edited device in console.cfg
case $CONSOLE_VARIANT in
bittboy2x_v1)
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 --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy2x v2" 5 18
BITTBOY_CONFIG=true
;;
bittboy3.5)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " BittBoy3.5" 5 18
BITTBOY_CONFIG=true
;;
q20)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q20" 5 18
MIYOO_CONFIG=true
;;
q90)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy Q90" 5 18
MIYOO_CONFIG=true
;;
v90)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " Powkiddy V90" 5 18
MIYOO_CONFIG=true
;;
pocketgo)
dialog --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " PocketGo" 5 18
MIYOO_CONFIG=true
;;
pocketgo_TE)
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 --backtitle "MiyooCFW 2.0" --no-shadow --colors --timeout 2 --ok-label " Your device " --msgbox " XYC Q8" 5 18
MIYOO_CONFIG=true
;;
m3_r61520)
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 --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 --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 --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 --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
echo "Didn't find correct console" >> ${LOG}
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
echo "License agreement signing" >> ${LOG}
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" | tee -a ${LOG}
echo "License not signed, exiting..." >> ${LOG}
sleep 1
console_unknown_func
safe_poweroff_func
else
echo "License signed, continuing..." >> ${LOG}
fi
# Format swap parition
echo "Formatting swap P3 partition" | tee -a ${LOG}
sleep 1
/sbin/swapoff -a 2>&1 | tee -a ${LOG} # unplug SWAP, otherwise if present it won't be recreated via mkswap
/sbin/mkswap -L SWAP /dev/mmcblk0p3 2>&1 | tee -a ${LOG}
/sbin/swapon /dev/mmcblk0p3 2>&1 | tee -a ${LOG}
echo -en "\n Available memory:\n" >> ${LOG}
free -m >> ${LOG}
sync
while (pgrep "sync"); do
sleep 1
done
mount -o remount,ro "${BOOTDIR}" 2>&1 | tee -a ${LOG}
#define primary partitions FS types
P1_FS_TYPE="$(lsblk -n --output=FSTYPE /dev/mmcblk0p1 | tr '[:lower:]' '[:upper:]')"
P2_FS_TYPE="$(lsblk -n --output=FSTYPE /dev/mmcblk0p2 | tr '[:lower:]' '[:upper:]')"
#P3_FS_TYPE="$(lsblk -n --output=FSTYPE /dev/mmcblk0p3 | tr '[:lower:]' '[:upper:]')"
P4_FS_TYPE="$(lsblk -n --output=FSTYPE /dev/mmcblk0p4 | tr '[:lower:]' '[:upper:]')"
P5_FS_TYPE="$(lsblk -n --output=FSTYPE /dev/mmcblk0p5 | tr '[:lower:]' '[:upper:]')"
#define primary partitions LABELS
P1_LABEL="$(lsblk -n --output=LABEL /dev/mmcblk0p1)" # BOOT
P2_LABEL="$(lsblk -n --output=LABEL /dev/mmcblk0p2)" # ROOTFS
#P3_LABEL="$(lsblk -n --output=LABEL /dev/mmcblk0p3)" # SWAP
P4_LABEL="$(lsblk -n --output=LABEL /dev/mmcblk0p4)" # MAIN
P5_LABEL="$(lsblk -n --output=LABEL /dev/mmcblk0p5)" # ROMS
#grep all partitions current size
SD_SIZE=$(cat "/sys/block/mmcblk0/size")
P1_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p1/size")
P2_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p2/size")
P3_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p3/size")
P4_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p4/size")
P5_SIZE=$(cat "/sys/block/mmcblk0/mmcblk0p5/size")
SD_SIZE_IN_MiB=$((SD_SIZE * 512 / 1024 / 1024))
SD_SIZE_IN_GiB=$((SD_SIZE * 512 / 1024 / 1024 / 1024))
BOOT_SIZE=$(((1016+1 - 1000) * 1024 / 512)) #bootloader partition=1016K (see `genimage` script in buildroot)
## boot_size calculated to 512 byte sector size blocks, adding +1K as a safety measure for roundups (at fatresize we use KibiBits)
#Calculate unallocated left space to expand ROMS partition:
SD_MAX_UNALL_SIZE="$((${SD_SIZE} - (${P1_SIZE} + ${P2_SIZE} + ${P3_SIZE} + ${P4_SIZE} + ${P5_SIZE}) - $BOOT_SIZE))"
SD_MAX_UNALL_SIZE_IN_MiB=$((SD_MAX_UNALL_SIZE * 512 / 1024 / 1024))
SD_MAX_UNALL_SIZE_IN_GiB=$(echo "scale=1; ${SD_MAX_UNALL_SIZE} * 512 / 1024 / 1024 / 1024" | bc)
#Calculate available space for 5'th partition (ROMS):
SD_MAX_AVAIL_SIZE="$((${SD_SIZE} - (${P1_SIZE} + ${P2_SIZE} + ${P3_SIZE} + ${P4_SIZE}) - $BOOT_SIZE))"
SD_MAX_AVAIL_SIZE_IN_KiB=$((SD_MAX_AVAIL_SIZE * 512 / 1024))
# Change_MAIN_FileSystem-prompt for the p4 partition if requested
echo "Change ${P4_LABEL} FileSystem procedure" >> ${LOG}
CHANGE_FS_P4=false
test "${P4_FS_TYPE}" == "BTRFS"\
&& P4_FS_TYPE_EXTRA="EXT4"\
|| P4_FS_TYPE_EXTRA="BTRFS"
if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --stdout --ok-label "${P4_FS_TYPE}"\(default\) --cancel-label "${P4_FS_TYPE_EXTRA}" --title " Change FileSystem" \
--colors --pause "\n\n\Z5Change default FileSystem of ${P4_LABEL}?\Zn\n\n BTRFS - safe & reliable\Zn\n\n EXT4 - fast & optimal\Zn\n\n Select an option & press START
\n\n \ZbWARNING:\Zn\n After 30min changes\n to ${P4_LABEL} partition won't be possible." 15 60 1800); then
echo "Selected ${P4_FS_TYPE} for ${P4_LABEL} partition, continuing with default setup." | tee -a ${LOG}
sleep 2
else
P4_FS_TYPE="${P4_FS_TYPE_EXTRA}"
echo -en "\n\nConverting the ${P4_LABEL} partition filesystem to ${P4_FS_TYPE} type.\n\n" | tee -a ${LOG}
echo -en "\e[32mThis can take a few minutes, be patient!\e[0m\n"
sleep 3
mkdir "${ROMS}"/backup 2>&1 | tee -a ${LOG}
if test "${P5_FS_TYPE}" == "VFAT"; then
rsync -rvt --modify-window=1 --exclude "lost+found" --info=nonreg0 --info=progress2 "${HOME}" "${ROMS}"/backup
else
rsync -a --info=nonreg0 --info=progress2 "${HOME}" "${ROMS}"/backup
fi
echo $? > $TEMP && EXIT_CODE=$(cat $TEMP)
if test $EXIT_CODE -eq 0; then
echo "Archiving ${HOME} partition successful" | tee -a ${LOG_TEMP}
else
echo -en "\033[0;31mArchiving ${HOME} to ${ROMS}/backup failed with rsync exit code ${EXIT_CODE}\033[0m\n" | tee -a ${LOG_TEMP}
fi
sleep 2
umount /dev/mmcblk0p4 2>&1 | tee -a ${LOG_TEMP}
while (pgrep "umount"); do
sleep 1
done
clear
echo -en "\n\n"
if test "${P4_FS_TYPE}" == "EXT4"; then
mkfs.ext4 -d "${ROMS}"/backup/"${HOME}" -L "${P4_LABEL}" -v -F /dev/mmcblk0p4 2>&1 | tee -a ${LOG_TEMP}
sleep 2
e2fsck -y /dev/mmcblk0p4 2>&1 | tee -a ${LOG_TEMP}
mount /dev/mmcblk0p4 "${HOME}" -o rw,sync,exec 2>&1 | tee -a ${LOG_TEMP}
CHANGE_FS_P4=true
elif test "${P4_FS_TYPE}" == "BTRFS"; then
mkfs.btrfs -r "${ROMS}"/backup/"${HOME}" -L "${P4_LABEL}" -v -f /dev/mmcblk0p4 2>&1 | tee -a ${LOG_TEMP}
btrfsck /dev/mmcblk0p4 2>&1 | tee -a ${LOG_TEMP} # does not repair FS, just check integrity as it is dengarous to do so
mount /dev/mmcblk0p4 "${HOME}" -o commit=5,flushoncommit,noatime,nodiratime,exec 2>&1 | tee -a ${LOG_TEMP}
CHANGE_FS_P4=true
else
echo "ERROR: Unrecognized new extra FSTYPE for ${HOME} partition, no changes will be made just mounting back!" | tee -a ${LOG_TEMP}
mount /dev/mmcblk0p4 "${HOME}" 2>&1 | tee -a ${LOG_TEMP}
fi
restore_temp_log_func
rm -r "${ROMS}"/backup 2>&1 | tee -a ${LOG}
fi
## Correct inittab for new p4 filesystem type
if ${CHANGE_FS_P4}; then
echo "Correcting inittab of p4 at ${HOME} procedure" >> ${LOG}
sleep 1
mount -o remount,rw / /
while (pgrep "mount"); do
sleep 1
done
if test "${P4_FS_TYPE}" == "EXT4" ; then
sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p4\).*|\1 "${HOME}" -o rw,sync,exec|" /etc/inittab
elif test "${P4_FS_TYPE}" == "BTRFS" ; then
sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p4\).*|\1 "${HOME}" -o commit=5,flushoncommit,noatime,nodiratime,exec|" /etc/inittab
fi
mount -o remount,ro / /
cat /etc/inittab >> ${LOG}
fi
# Change_ROMS_FileSystem-prompt for the p5 partition if requested
echo "Change ${P5_LABEL} FileSystem procedure" >> ${LOG}
CHANGE_FS_P5=false
test "${P5_FS_TYPE}" == "EXT4"\
&& P5_FS_TYPE_EXTRA="BTRFS"\
&& P5_FS_TYPE_EXTRA2="VFAT"
test "${P5_FS_TYPE}" == "BTRFS"\
&& P5_FS_TYPE_EXTRA="EXT4"\
&& P5_FS_TYPE_EXTRA2="VFAT"
test "${P5_FS_TYPE}" == "VFAT"\
&& P5_FS_TYPE_EXTRA="BTRFS"\
&& P5_FS_TYPE_EXTRA2="EXT4"
dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --stdout --ok-label "${P5_FS_TYPE}(def.)" --cancel-label "${P5_FS_TYPE_EXTRA}" --extra-button --extra-label "${P5_FS_TYPE_EXTRA2}" --title " Change FileSystem" \
--colors --pause "\n\n\Z5Change default FileSystem for ${P5_LABEL}?\Zn\n\nEXT4 - fast write/read & UNIX compliant\Zn\n\nBTRFS - slow read but poweroff safe, UNIX compliant\Zn\n\nVFAT(32) - slow on-device write but Windows compatible\Zn\n\n Select an option & press START
\n\n \ZbWARNING:\Zn\n After 30min changes to ${P5_LABEL}\n partition won't be possible." 25 60 1800
echo $? > $TEMP
## Read the user's first choice from the tmp file
CHOICE=$(cat $TEMP)
if test $CHOICE -eq 0; then
echo "Selected ${P5_FS_TYPE} for ${P5_LABEL} partition, continuing with default setup." | tee -a ${LOG}
sleep 2
elif test $CHOICE -eq 1; then
P5_FS_TYPE="${P5_FS_TYPE_EXTRA}"
CHANGE_FS_P5=true
elif test $CHOICE -eq 3; then
P5_FS_TYPE="${P5_FS_TYPE_EXTRA2}"
CHANGE_FS_P5=true
else
dialog --backtitle "MiyooCFW 2.0" --no-shadow --timeout 2 --msgbox "Invalid choice, continuing with default setup!" 0 0
sleep 1.5
fi
if $CHANGE_FS_P5; then
echo -en "\n\nConverting the ${P5_LABEL} partition filesystem to ${P5_FS_TYPE} type.\n\n" | tee -a ${LOG}
echo -en "\e[32mThis can take a few minutes, be patient!\e[0m\n"
sleep 3
mkdir "${HOME}"/backup 2>&1 | tee -a ${LOG}
rsync -a --info=nonreg0 --info=progress2 "${ROMS}" "${HOME}"/backup
echo $? > $TEMP && EXIT_CODE=$(cat $TEMP)
if test $EXIT_CODE -eq 0; then
echo "Archiving ${ROMS} partition successful" | tee -a ${LOG}
else
echo "\033[0;31mArchiving ${ROMS} to ${HOME}/backup failed with rsync exit code ${EXIT_CODE}\033[0m" | tee -a ${LOG}
fi
sleep 2
umount /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
while (pgrep "umount"); do
sleep 1
done
clear
echo -en "\n\n"
if test "${P5_FS_TYPE}" == "VFAT"; then
mkfs.vfat -n ${P5_LABEL} -v -F32 /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
sleep 2
fsck.fat -y /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
mount /dev/mmcblk0p5 "${ROMS}" -t vfat -o rw,utf8 2>&1 | tee -a ${LOG}
while (pgrep "mount"); do
sleep 1
done
rsync -rvt --modify-window=1 --exclude "lost+found" --info=nonreg0 --info=progress2 "${HOME}"/backup"${ROMS}" /
echo $? > $TEMP && EXIT_CODE=$(cat $TEMP)
if test $EXIT_CODE -eq 0; then
echo "Extracting archive in ${ROMS} partition successful" | tee -a ${LOG}
else
echo "\033[0;31mExtracting archive ${ROMS} from ${HOME}/backup${ROMS} failed with rsync exit code ${EXIT_CODE}\033[0m" | tee -a ${LOG}
fi
elif test "${P5_FS_TYPE}" == "BTRFS"; then
mkfs.btrfs -r "${HOME}"/backup"${ROMS}" -v -f -L ${P5_LABEL} /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
sleep 2
btrfsck /dev/mmcblk0p5 2>&1 | tee -a ${LOG} # does not repair FS, just check integrity as it is dengarous to do so
mount /dev/mmcblk0p5 "${ROMS}" -o commit=5,flushoncommit,noatime,nodiratime 2>&1 | tee -a ${LOG}
elif test "${P5_FS_TYPE}" == "EXT4"; then
mkfs.ext4 -d "${HOME}"/backup"${ROMS}" -L "${P5_LABEL}" -v -F /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
sleep 2
e2fsck -y /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
mount /dev/mmcblk0p5 "${ROMS}" -o rw,noatime 2>&1 | tee -a ${LOG}
else
echo "ERROR: Unrecognized new extra FSTYPE for ${ROMS} partition, no changes will be made just mounting back!" | tee -a ${LOG}
mount /dev/mmcblk0p5 "${ROMS}" 2>&1 | tee -a ${LOG}
CHANGE_FS_P5=false
fi
rm -r "${HOME}"/backup
## Correct inittab for new p5 filesystem type
echo "Correcting inittab of p5 at ${ROMS} procedure" >> ${LOG}
sleep 1
mount -o remount,rw / /
while (pgrep "mount"); do
sleep 1
done
if test "${P5_FS_TYPE}" == "VFAT"; then
sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p5\).*|\1 "${ROMS}" -t vfat -o rw,utf8|" /etc/inittab
elif test "${P5_FS_TYPE}" == "BTRFS"; then
sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p5\).*|\1 "${ROMS}" -o commit=5,flushoncommit,noatime,nodiratime|" /etc/inittab
elif test "${P5_FS_TYPE}" == "EXT4"; then
sed -i "s|\(::sysinit:/bin/mount /dev/mmcblk0p5\).*|\1 "${ROMS}" -o rw,noatime|" /etc/inittab
fi
mount -o remount,ro / /
cat /etc/inittab >> ${LOG}
fi
# Expand_ROMS_Partition-prompt for the p5 (ROMS) partition if requested
echo "Expand ${P5_LABEL} FileSystem procedure" >> ${LOG}
RESIZE_COMMENCED=false
if (dialog --backtitle "MiyooCFW 2.0" --no-shadow --clear --stdout --ok-label YES --cancel-label NO --title " AUTO-RESIZE" \
--colors --pause "\n\n \Z5Expand ${P5_LABEL} partition?\Zn\n\n Select an option & press START
\n\n \ZbWARNING:\Zn\n After 30min auto-resize\n of ${P5_FS_TYPE} partition will begin." 15 60 1800); then
clear
SD_MAX_AVAIL_SIZE_IN_GiB=$(echo "scale=1; ${SD_MAX_AVAIL_SIZE_IN_KiB} / 1024 / 1024" | bc) #only to inform user about end point for resize
SD_MAX_AVAIL_SIZE_IN_GB=$(echo "scale=1; ${SD_MAX_AVAIL_SIZE_IN_KiB} * 1024 / 1000 / 1000 / 1000" | bc)
SD_MAX_AVAIL_SIZE_IN_MB=$((SD_MAX_AVAIL_SIZE_IN_KiB * 1024 / 1000 / 1000))
P5_SIZE_IN_GB=$(echo "scale=1; ${P5_SIZE} * 512 / 1000 / 1000 / 1000" | bc)
# roundup GB value to 0,1GB for integer calculations:
SD_MAX_AVAIL_SIZE_IN_GBx10=$(echo "$SD_MAX_AVAIL_SIZE_IN_GB" | tr -d ".")
P5_SIZE_IN_GBx10=$(echo "$P5_SIZE_IN_GB" | tr -d ".")
#Sanity checks if we don't down- or over-resize partition:
RESIZE_ABORT=false
if (test "$P5_SIZE_IN_GBx10" -ge "$SD_MAX_AVAIL_SIZE_IN_GBx10" || test "$SD_MAX_UNALL_SIZE_IN_MiB" -le 15); then
echo "Your ${P5_LABEL} partition is greater than available space for resizing or you lack unallocated sectors space" | tee -a ${LOG}
sleep 1.5
RESIZE_ABORT=true
fi
if test "${P5_FS_TYPE}" == "VFAT" ; then
if test "$SD_SIZE_IN_GiB" -gt 128; then
if (dialog --clear --stdout --ok-label NO --cancel-label YES --title " \Zb\Z1WARNING!\Zn" \
--colors --pause "\nYour SD card exceeds max. size for auto-resizing!
\n\nWe could however expand it to 118GB. \n\n \ZuDo you AGREE?\Zn
\n\n\ZbINFO: For microSD >128GB big we\n recommend to use your PC!\Zn" 0 0 30 || test $? -eq 255); then
dialog --clear --colors --timeout 2 --msgbox " FAT resizing \ZuABORTED!\Zn" 5 27
echo "Your SD card exceeds max. 128G size for auto-resizing!" >> ${LOG}
clear
RESIZE_ABORT=true
else
SD_MAX_AVAIL_SIZE_IN_KiB=123731968
echo "Your SD card exceeds max. 128G so picked that value instead!" >> ${LOG}
fi
fi
fi
if !(test "${P5_FS_TYPE}" == "VFAT" || test "${P5_FS_TYPE}" == "BTRFS" || test "${P5_FS_TYPE}" == "EXT4"); then
echo "ERROR: I couldn't recognize FSTYPE for ${ROMS} partition, resizing ABORTED!" | tee -a ${LOG}
RESIZE_ABORT=true
fi
if ! $RESIZE_ABORT; then
echo "Performing resize on ${ROMS}" >> ${LOG}
echo "The full size of your SD is ${SD_SIZE_IN_MiB}MB large" | tee -a ${LOG}
echo "Unallocated space available for resizing equals ${SD_MAX_UNALL_SIZE_IN_GiB}GB," | tee -a ${LOG}
echo "and more precisely it's ${SD_MAX_UNALL_SIZE_IN_MiB}MB big" | tee -a ${LOG}
echo "Resizing the ${P5_LABEL} (${P5_FS_TYPE}) partition to ${SD_MAX_AVAIL_SIZE_IN_GiB}GB." | tee -a ${LOG}
umount /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
if test "${P5_FS_TYPE}" == "VFAT"; then
echo -en "\e[32mThis can take a few minutes, be patient!\e[0m\n"
#TODO: fix outputting logs from fatresize stdout
fatresize --size="${SD_MAX_AVAIL_SIZE_IN_KiB}"ki -v -p /dev/mmcblk0p5 -n5 2>&1 | tee -a ${LOG}
fsck.fat -y /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
#echo -n -e \\xEB\\x58\\x90 > /dev/mmcblk0p5
sync
mount -t vfat -o rw,utf8 /dev/mmcblk0p5 "${ROMS}" 2>&1 | tee -a ${LOG}
else
echo -en "\e[32mThis can take a few seconds!\e[0m\n"
P5_START_POINT=$(parted --script /dev/mmcblk0 unit MB print 2>&1 | tee -a ${LOG} | grep '5' | tail -n1 | awk '{print $2}') \
&& echo -en "Expanding 5'th partition from START sector ${P5_START_POINT} to END \n in total size: ${SD_MAX_AVAIL_SIZE_IN_MB}MB\n" | tee -a ${LOG} \
|| echo -en "ERROR: Failed to determine P5_START_POINT for resizing" | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script rm '5' 2>&1 | tee -a ${LOG}
parted -a optimal /dev/mmcblk0 --script mkpart roms $P5_START_POINT 100% 2>&1 | tee -a ${LOG}
partx -u /dev/mmcblk0 2>&1 | tee -a ${LOG}
if test "${P5_FS_TYPE}" == "BTRFS"; then
mount /dev/mmcblk0p5 "${ROMS}" -o commit=5,flushoncommit,noatime,nodiratime 2>&1 | tee -a ${LOG}
btrfs filesystem resize max ${ROMS} 2>&1 | tee -a ${LOG}
elif test "${P5_FS_TYPE}" == "EXT4"; then
resize2fs /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
e2fsck -y /dev/mmcblk0p5 2>&1 | tee -a ${LOG}
mount /dev/mmcblk0p5 "${ROMS}" -o rw,noatime 2>&1 | tee -a ${LOG}
else
echo "ERROR: I still couldn't recognize FSTYPE for ${ROMS} partition, no resizing will be made just mounting back!" | tee -a ${LOG}
mount /dev/mmcblk0p5 "${ROMS}" 2>&1 | tee -a ${LOG}
#RESIZE_COMMENCED=false
fi
partprobe 2>&1 | tee -a ${LOG}
fi
RESIZE_COMMENCED=true
else
echo "${P5_LABEL} partition resizing was aborted!" | tee -a ${LOG}
sleep 2
fi
fi
if ! $RESIZE_COMMENCED && test "${P5_FS_TYPE}" == "VFAT" ; then
sgdisk --typecode=5:0700 /dev/mmcblk0 2>&1 | tee -a ${LOG} # Microsoft basic data - partition type
partprobe 2>&1 | tee -a ${LOG}
echo "Executed partprobe to correct partition table." >> ${LOG}
fi
# output FS table with type
df -Th >> ${LOG} 2>&1
# Cleanup - delete the temporary file storing variable value
rm $TEMP
# disable this script
mount -o remount,rw "${BOOTDIR}" 2>&1 | tee -a ${LOG}
echo "Disabling the firstboot script." | tee -a ${LOG}
if grep -sq FIRSTBOOT\=\1 "${HOME}/options.cfg"; then
sed -i '/^FIRSTBOOT=/d' ${HOME}/options.cfg 2>&1 | tee -a ${LOG}
echo "FIRSTBOOT=0" >> ${HOME}/options.cfg
else
mv "${BOOTDIR}/firstboot" "${BOOTDIR}/firstboot.done" 2>&1 | tee -a ${LOG}
fi
mount -o remount,ro "${BOOTDIR}" 2>&1 | tee -a ${LOG}
# copy over the config files
echo "Copying default configuration files into place..." | tee -a ${LOG}
if $BITTBOY_CONFIG; then
cp "${HOME}/gmenu2x/input_bittboy.conf" "${HOME}/gmenu2x/input.conf"
elif $MIYOO_CONFIG; then
cp "${HOME}/gmenu2x/input_miyoo.conf" "${HOME}/gmenu2x/input.conf"
fi
# create symlink to ROMS part. at /mnt/
ln -s "${ROMS}" "${HOME}" 2>&1 | tee -a ${LOG}
echo -en "\nUsing following GMenu2X input configuration:\n" >> ${GMENU2X_LOGS}
cat "${HOME}/gmenu2x/input.conf" >> ${GMENU2X_LOGS}
sync
echo "firstboot script finished." | tee -a ${LOG}
touch ${HOME}/firstboot.completed
echo
#install IPK packages
echo "starting ipk install manager..." | tee -a ${LOG}
${BOOTDIR}/ipk_install.sh 2>&1 | tee -a ${LOG}
# Reboot device if CONSOLE_VARIANT was overwritten from $CHOICE so that it could be applied in u-boot by readID
## or found firstboot custom script
if ($CONSOLE_OVERWRITE || test -r "${BOOTDIR}/firstboot.custom.sh"); then
safe_reboot_func
else
#just grep logs from temp directory before continuing just in case
restore_temp_log_func
fi