@@ -229,21 +229,50 @@ if [[ "${romzip}" == *.@(img|bin) ]] && [ "$(head -c6 "${romzip}")" == "RKFWf" ]
229229 exit 0
230230fi
231231
232- if [[ $( 7z l -ba " ${romzip} " | grep -i aml) ]]; then
233- echo " aml detected"
234- cp " ${romzip} " " $tmpdir "
235- romzip=" $tmpdir /$( basename " ${romzip} " ) "
236- 7z e -y " ${romzip} " >> " $tmpdir " /zip.log
237- $aml_extract $( find . -type f -name " *aml*.img" )
232+ if 7z l -ba " ${romzip} " | grep -q aml; then
233+ echo " [INFO] Amlogic package detected"
234+ cp " ${romzip} " " ${tmpdir} "
235+
236+ # Extract image(s) from archive
237+ romzip=" ${tmpdir} /$( basename ${romzip} ) "
238+ echo " [INFO] Extracting archive..."
239+
240+ # '7z' might not be able to extract '.tar.bz2' directly
241+ if [[ " $( basename ${romzip} ) " == * " .tar.bz2" ]]; then
242+ tar -xvjf " ${romzip} " > /dev/null || {
243+ echo " [ERROR] Archive extraction ('.tar.bz2') failed!"
244+ exit 1
245+ }
246+ else
247+ 7z e -y " ${romzip} " >> " $tmpdir " /zip.log || {
248+ echo " [ERROR] Archive extraction failed!"
249+ exit 1
250+ }
251+ fi
252+
253+ # Extract through 'aml_extract'
254+ echo " [IFNO] Extracting through 'aml-upgrade-package-extract'..."
255+ $aml_extract $( find . -type f -name " *aml*.img" ) || {
256+ echo " [INFO] Extraction failed!"
257+ exit 1
258+ }
259+
260+ # Replace partitions' extension to '.img'
238261 rename ' s/.PARTITION$/.img/' * .PARTITION
239262 rename ' s/_aml_dtb.img$/dtb.img/' * .img
240263 rename ' s/_a.img/.img/' * .img
241- if [[ -f super.img ]]; then
264+
265+ # Generate a 'super.img'
266+ [[ -f super.img ]] && \
242267 superimage
243- fi
244- for partition in $PARTITIONS ; do
245- [[ -e " $tmpdir /$partition .img" ]] && mv " $tmpdir /$partition .img" " ${outdir} /$partition .img"
268+
269+ # Move to output directory
270+ for p in $PARTITIONS ; do
271+ [[ -e " $tmpdir /$p .img" ]] && \
272+ mv " $tmpdir /$p .img" " ${outdir} /$p .img"
246273 done
274+
275+ # Clean-up
247276 rm -rf " $tmpdir "
248277 exit 0
249278fi
0 commit comments