Skip to content

Commit 9da5dca

Browse files
committed
refactor: Write from zero other partition extraction logic
1 parent 54ea22a commit 9da5dca

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

extractor.sh

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,22 @@ fi
175175

176176
echo "Extracting firmware on: $outdir"
177177

178-
for otherpartition in $OTHERPARTITIONS; do
179-
filename=$(echo $otherpartition | cut -f 1 -d ":")
180-
outname=$(echo $otherpartition | cut -f 2 -d ":")
181-
if [[ $(7z l -ba "$romzip" | grep $filename) ]]; then
182-
echo "$filename detected for $outname"
183-
foundfiles=$(7z l -ba "$romzip" | gawk '{ print $NF }' | grep $filename)
184-
7z e -y "$romzip" $foundfiles 2>/dev/null >> $tmpdir/zip.log
185-
outputs=$(ls *"$filename"*)
186-
for output in $outputs; do
187-
[[ ! -e "$outname".img ]] && mv $output "$outname".img
188-
$simg2img "$outname".img "$outdir/$outname".img 2>/dev/null
189-
if [[ ! -s "$outdir/$outname".img ]] && [ -f "$outname".img ]; then
190-
mv "$outname".img "$outdir/$outname".img
191-
fi
192-
done
178+
# Extract firmware partitions
179+
for partition in ${OTHERPARTITIONS}; do
180+
# Set the names for the partition(s)
181+
IN=$(echo $partition | cut -f 1 -d ":")
182+
OUT=$(echo $partition | cut -f 2 -d ":")
183+
184+
# Check if partition is present on archive
185+
if $(7z l -ba "$romzip" | grep -q $IN); then
186+
echo "[INFO] Extracting ${IN}..."
187+
188+
# Extract to '${outdir}'
189+
7zz x "${romzip}" "${IN}" -so > ${outdir}/${IN}.sparse
190+
191+
# Convert from sparse to RAW image
192+
$simg2img "${outdir}/${IN}".sparse "${outdir}/${OUT}".img
193+
rm -rf "${outdir}/${IN}".sparse
193194
fi
194195
done
195196

0 commit comments

Comments
 (0)