-
-
Save extratone/909dddb48582004e18e3a9f71668871a to your computer and use it in GitHub Desktop.
A zsh script to extract the largest DMG from an IPSW to the same folder with the label as name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# ipsw2dmg.sh by github.com/atnbueno - v2.0.0 (2022-07-31) - License: MIT | |
# Check if input file exists (with or without an .ipsw extension) | |
if [ -f "$1" ]; then | |
INPUT=$(realpath "$1") | |
else | |
if [ -f "$1.ipsw" ]; then | |
INPUT=$(realpath "$1.ipsw") | |
else | |
ERR="Input file ($1) not found" | |
fi | |
fi | |
# Check that the script is called with two parameters | |
if [ $# -lt 2 ]; then | |
ERR="The script requires two parameters" | |
fi | |
if [ -n "${ERR}" ]; then | |
autoload -U colors && colors # necessary to colorize the feedback to the user | |
echo $fg[green]ipsw2dmg extracts the largest DMG from an IPSW to the same folder with the label as name | |
echo $fg[red]ERROR: $ERR | |
echo $fg[yellow]Usage: ipsw2dmg.sh input.ipsw label.dmg$reset_color | |
else | |
IPSW=$(basename "$INPUT" .ipsw) | |
LABEL=$(basename "$2" .dmg) | |
DMG=$(unzip -l "$1"|sort|grep dmg|tail -1|cut -c32-) | |
CD=$PWD # remember the current directory | |
cd ${INPUT%/*} # work where the input file is | |
unzip -o "$IPSW.ipsw" "$DMG" | |
mv -f "$DMG" "$LABEL.dmg" | |
read -q "ANSWER?Delete input file (y/N)? " # interactive question | |
echo # finish the line to avoid a highlighted "%" | |
if [[ "$ANSWER" == "y" ]]; then # -q returns "y" if input is "y" or "Y", "n" otherwise | |
rm "$1" | |
fi | |
echo "$LABEL.dmg" can be found at $PWD: | |
ls -la *.dmg # show the new file along any other DMG in the same folder | |
cd $CD # go back to the original directory | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment