11#! /data/data/com.tool.tree/files/home/bin/bash
22# kakathic
33
4+ source language
5+
46show_help () {
57 echo " Usage: repack_super -i <input> -m ''file1 file2'' -g <group> -s <size-gb> -f [raw, sparse] -t [A, AB, VAB]"
68 echo
@@ -18,7 +20,7 @@ show_help() {
1820}
1921
2022INPUT=" " ; MIMGPA=" " ; SUPGRUP=" " ; SAIZESUP=" " ;
21- DANGIMG=" " ; TYPEIMG=" " ;
23+ DANGIMG=" " ; TYPEIMG=" " ; ml1= " " ; ml2= " " ;
2224if [[ $# -eq 0 || " $1 " != -* ]]; then
2325show_help
2426fi
@@ -38,52 +40,61 @@ while getopts ":i:m:g:s:f:t:h" opt; do
3840done
3941
4042if [[ -z " $INPUT " || -z " $MIMGPA " ]]; then
41- echo " Lack of value" >&2
42- show_help
43+ echo " Lack of value:
44+ -i ${INPUT:- ???}
45+ -m ${MIMGPA:- ???} " >&2
4346fi
4447
4548[[ -z " $SUPGRUP " ]] && SUPGRUP=' qti_dynamic_partitions'
4649[[ -z " $SAIZESUP " ]] && SAIZESUP=' 8.5'
4750[[ -z " $DANGIMG " ]] && DANGIMG=' raw'
4851[[ -z " $TYPEIMG " ]] && TYPEIMG=' A'
4952
50- source language
53+ first_sector_size=" $( glog first_sector_size_super 2097152) "
54+ first_sector=" $( glog first_sector_super 1048576) "
55+
5156super_sizek=" $( echo " $SAIZESUP * 1024 * 1024 * 1024" | bc -l | cut -d. -f1) "
5257echo " ${sizes_text} : ${SAIZESUP} GB ➠ ${super_sizek} bytes"
5358echo
5459
5560argvs=" --super-name super --metadata-size 65536 "
5661cd " $INPUT "
5762
58- if [ $TYPEIMG = " A" ]; then
59- argvs+=" --metadata-slots 2 --block-size 4096 -- device super:${super_sizek} --group ${SUPGRUP} :${super_sizek} "
63+ if [ " $TYPEIMG " == " A" ]; then
64+ argvs+=" --metadata-slots 2 --device super:${super_sizek} : $first_sector --group ${SUPGRUP} :${super_sizek} "
6065fi
6166
6267for i in $MIMGPA ; do
63- ml1= ' ' ; ml2= ' ' ;
64- i1=$( echo " $i " | sed ' s/.img//g ' )
65- i2=$( echo " $i " | sed -e ' s/_a.img//g ' -e ' s/_b.img//g ' -e ' s/.img//g ' )
68+ echo " $i " | grep -q " -cow " && continue
69+ i1=$( echo " $i " | sed ' s/.img$// ' )
70+ i2=$( echo " $i " | sed -e ' s/_a.img$// ' -e ' s/_b.img$// ' -e ' s/.img$// ' )
6671info=$( checktype " $INPUT /$i1 .img" )
6772p_size=$( stat -c %s " $INPUT /$i1 .img" )
68- [ $info == " sparse" ] && simg2img " $INPUT /$i1 .img"
69- [ $TYPEIMG = " A" ] && argvs+=" --partition ${i2} :readonly:$p_size :${SUPGRUP} --image ${i2} =$i1 .img "
70- if [ $TYPEIMG == " AB" ] || [ $TYPEIMG == " VAB" ]; then
73+ # p_size=$(( ($(stat -c %s "$INPUT/$i1.img") + 4095) / 4096 * 4096 ))
74+ [ " $info " == " sparse" ] && simg2img " $INPUT /$i1 .img"
75+ [ " $TYPEIMG " == " A" ] && argvs+=" --partition ${i2} :readonly:$p_size :${SUPGRUP} --image ${i2} =$i1 .img "
76+ if [ " $TYPEIMG " == " AB" ] || [ " $TYPEIMG " == " VAB" ]; then
7177ml1+=" --partition ${i2} _a:none:$p_size :${SUPGRUP} _a --image ${i2} _a=$i1 .img "
7278ml2+=" --partition ${i2} _b:none:0:${SUPGRUP} _b "
7379fi
7480done
7581
76- if [ $TYPEIMG = " AB" ] || [ $TYPEIMG = " VAB" ]; then
77- argvs+=" --metadata-slots 3 --device super:${super_sizek} --group ${SUPGRUP} _a:${super_sizek} ${ml1} --group ${SUPGRUP} _b:${super_sizek} ${ml2} "
82+ if [ " $TYPEIMG " == " AB" ] || [ " $TYPEIMG " == " VAB" ]; then
83+ if [ " $TYPEIMG " == " AB" ] && [ " $( glog check_super_type_ab) " == 1 ]; then
84+ half_size=$(( super_sizek / 2 - first_sector_size * 2 ))
85+ else
86+ half_size=$(( super_sizek - first_sector_size))
87+ fi
88+ argvs+=" --metadata-slots 3 --device super:${super_sizek} :$first_sector --group ${SUPGRUP} _a:${half_size} ${ml1} --group ${SUPGRUP} _b:${half_size} ${ml2} "
7889fi
79- [ $TYPEIMG = " VAB" ] && argvs+=" --virtual-ab "
80- [ $DANGIMG = " sparse" ] && argvs+=" --sparse "
90+ [ " $TYPEIMG " = = " VAB" ] && argvs+=" --virtual-ab "
91+ [ " $DANGIMG " = = " sparse" ] && argvs+=" --sparse "
8192
8293mkdir -p out
8394echo " lpmake ${argvs} -F --output $INPUT /out/super.img" | sed -z ' s| --|\n--|g'
8495lpmake ${argvs} -F --output out/super.img 2> $TMP /super_log.log
8596
86- if [ $? == 1 ]; then
97+ if [ $? == 1 ]; then
8798killtree " \n$supers_text_1 " " $INPUT /out/super.img"
8899else
89100echo -e " \n$supers_text_2 "
0 commit comments