Skip to content

Instantly share code, notes, and snippets.

@JayBrown
Last active October 24, 2022 18:02
Show Gist options
  • Select an option

  • Save JayBrown/cf2712c5d0ff1718af794fdedfdd5c0d to your computer and use it in GitHub Desktop.

Select an option

Save JayBrown/cf2712c5d0ff1718af794fdedfdd5c0d to your computer and use it in GitHub Desktop.

Revisions

  1. JayBrown revised this gist Jan 28, 2020. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions ckimg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # ckimg v0.4
    # ckimg v0.5

    for filepath in "$@"
    do
    @@ -12,16 +12,19 @@ do
    && { echo "Wrong file type: continuing..." >&2 ; continue ; }
    fsysr=$(hdiutil imageinfo "$filepath" 2>/dev/null)
    fsys=$(echo "$fsysr" \
    | sed -n '/partition-filesystems:/,/[0-9]:$/p' \
    | sed -e '1,1d' -e '$d' | xargs \
    | awk -F: '{print $1}')
    | sed -n '/partition-filesystems:/,/[A-Z]/p' \
    | grep -v -e "partition-")
    sysn=$(echo "$fsys" | wc -l | xargs)
    if [[ $sysn -eq 0 ]] ; then
    echo "Filesystem: n/a"
    elif [[ $sysn -eq 1 ]] ; then
    fsys=$(echo "$fsys" \
    | sed -e "s/://g" | xargs)
    echo "Filesystem: $fsys"
    else
    fsysx=$(echo "$fsys" | xargs)
    fsysx=$(echo "$fsys" | sort | sed -e "s/://g" \
    | awk 1 ORS=' & ' \
    | sed "s/ & $//" | xargs)
    echo "Filesystems: $fsysx"
    fi
    format=$(echo "$fsysr" | awk -F": " '/^Format: /{print $2}')
    @@ -41,7 +44,8 @@ do
    fi
    echo "Encryption: $crypt"
    if [[ $extension =~ ^(dmg|DMG)$ ]] ; then
    if [[ $fsys == "APFS" ]] ; then
    fsys=$(echo "$fsys" | grep -v "EFI")
    if [[ $(echo "$fsys" | grep "APFS") ]] ; then
    compat="macOS 10.14+"
    else
    if [[ $format == "ULFO" ]] ; then
  2. JayBrown revised this gist Jan 24, 2020. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions ckimg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # ckimg v0.3
    # ckimg v0.4

    for filepath in "$@"
    do
    @@ -9,7 +9,7 @@ do
    echo "Accessing: $shortpath"
    extension="${filename##*.}"
    ! [[ $extension =~ ^(dmg|DMG|sparsebundle|SPARSEBUNDLE|sparseimage|SPARSEIMAGE|cdr|CDR|iso|ISO|img|IMG)$ ]] \
    && { echo "Wrong file type: continuing..." ; continue ; }
    && { echo "Wrong file type: continuing..." >&2 ; continue ; }
    fsysr=$(hdiutil imageinfo "$filepath" 2>/dev/null)
    fsys=$(echo "$fsysr" \
    | sed -n '/partition-filesystems:/,/[0-9]:$/p' \
    @@ -76,17 +76,21 @@ do
    compat="OS 9"
    fi
    echo "Compatibility: $compat"
    hdiverify=$(hdiutil verify "$filepath" 2>&1)
    echo -n "Verifying " >&2 && while : ; do echo -n ▇ >&2 ; sleep 1 ; done &
    trap "kill $!" EXIT
    hdiverify=$(hdiutil verify "$filepath" 2>&1)
    kill $! && trap " " EXIT
    wait $! 2>/dev/null
    if [[ $(echo "$hdiverify" | grep "has no checksum\.$") ]] ; then
    echo "Verification: no checksum"
    echo -e "\nVerification: no checksum"
    else
    hdiresult=$(echo "$hdiverify" | grep "^hdiutil: verify: checksum" | rev | awk '{print $1}' | rev)
    if [[ $hdiresult == "INVALID" ]] ; then
    hdihash=$(echo "$hdiverify" | grep "^calculated" | xargs)
    else
    hdihash=$(echo "$hdiverify" | grep "^verified" | awk '{print substr($0, index($0,$2))}')
    fi
    echo "Verification: $hdiresult ($hdihash)"
    echo -e "\nVerification: $hdiresult ($hdihash)"
    fi
    echo "********"
    done
  3. JayBrown revised this gist Jan 24, 2020. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion ckimg
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # ckimg v0.2
    # ckimg v0.3

    for filepath in "$@"
    do
    @@ -76,6 +76,18 @@ do
    compat="OS 9"
    fi
    echo "Compatibility: $compat"
    hdiverify=$(hdiutil verify "$filepath" 2>&1)
    if [[ $(echo "$hdiverify" | grep "has no checksum\.$") ]] ; then
    echo "Verification: no checksum"
    else
    hdiresult=$(echo "$hdiverify" | grep "^hdiutil: verify: checksum" | rev | awk '{print $1}' | rev)
    if [[ $hdiresult == "INVALID" ]] ; then
    hdihash=$(echo "$hdiverify" | grep "^calculated" | xargs)
    else
    hdihash=$(echo "$hdiverify" | grep "^verified" | awk '{print substr($0, index($0,$2))}')
    fi
    echo "Verification: $hdiresult ($hdihash)"
    fi
    echo "********"
    done
    echo "Done."
  4. JayBrown revised this gist Jan 23, 2020. 2 changed files with 81 additions and 31 deletions.
    31 changes: 0 additions & 31 deletions ckapfs
    Original file line number Diff line number Diff line change
    @@ -1,31 +0,0 @@
    #!/bin/bash

    # ckapfs v0.1

    for filepath in "$@"
    do
    echo "$filepath"
    fsys=$(hdiutil imageinfo "$filepath" 2>/dev/null \
    | sed -n '/partition-filesystems:/,/[0-9]:$/p' \
    | sed -e '1,1d' -e '$d' | xargs \
    | awk -F: '{print $1}')
    sysn=$(echo "$fsys" | wc -l | xargs)
    if [[ $sysn -eq 0 ]] ; then
    echo "Error: no filesystems detected"
    elif [[ $sysn -eq 1 ]] ; then
    if [[ $fsys == "APFS" ]] ; then
    echo "Filesystem: $fsys (APFS detected!)"
    else
    echo "Filesystem: $fsys (not APFS)"
    fi
    else
    fsysx=$(echo "$fsys" | xargs)
    if [[ $(echo "$fsys" | grep "APFS") ]] ; then
    echo "Several filesystems detected: $fsysx (APFS detected!)"
    else
    echo "Several filesystems detected: $fsysx (not APFS)"
    fi
    fi
    echo "********"
    done
    echo "Done."
    81 changes: 81 additions & 0 deletions ckimg
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    #!/bin/bash

    # ckimg v0.2

    for filepath in "$@"
    do
    shortpath="${filepath/#$HOME/~}"
    filename=$(basename "$filepath")
    echo "Accessing: $shortpath"
    extension="${filename##*.}"
    ! [[ $extension =~ ^(dmg|DMG|sparsebundle|SPARSEBUNDLE|sparseimage|SPARSEIMAGE|cdr|CDR|iso|ISO|img|IMG)$ ]] \
    && { echo "Wrong file type: continuing..." ; continue ; }
    fsysr=$(hdiutil imageinfo "$filepath" 2>/dev/null)
    fsys=$(echo "$fsysr" \
    | sed -n '/partition-filesystems:/,/[0-9]:$/p' \
    | sed -e '1,1d' -e '$d' | xargs \
    | awk -F: '{print $1}')
    sysn=$(echo "$fsys" | wc -l | xargs)
    if [[ $sysn -eq 0 ]] ; then
    echo "Filesystem: n/a"
    elif [[ $sysn -eq 1 ]] ; then
    echo "Filesystem: $fsys"
    else
    fsysx=$(echo "$fsys" | xargs)
    echo "Filesystems: $fsysx"
    fi
    format=$(echo "$fsysr" | awk -F": " '/^Format: /{print $2}')
    if ! [[ $format ]] ; then
    format="n/a"
    compat="n/a"
    fi
    echo "Format: $format"
    descr=$(echo "$fsysr" | awk -F": " '/^Format Description: /{print $2}')
    echo "Description: $descr"
    cryptinfo=$(hdiutil isencrypted "$filepath" 2>/dev/null)
    if [[ $cryptinfo == "encrypted: NO" ]] ; then
    crypt="none"
    else
    crypt=$(echo "$fsysr" | awk -F": " '/Encryption: /{print $2}')
    ! [[ $crypt ]] && crypt="n/a"
    fi
    echo "Encryption: $crypt"
    if [[ $extension =~ ^(dmg|DMG)$ ]] ; then
    if [[ $fsys == "APFS" ]] ; then
    compat="macOS 10.14+"
    else
    if [[ $format == "ULFO" ]] ; then
    compat="OS X 10.11+"
    elif [[ $format == "UDBZ" ]] ; then
    if [[ $crypt == "AES-256" ]] ; then
    compat="Mac OS X 10.5+"
    else
    compat="Mac OS X 10.4+"
    fi
    else
    if [[ $crypt == "AES-256" ]] ; then
    compat="Mac OS X 10.5+"
    elif [[ $crypt == "AES-128" ]] ; then
    compat="Mac OS X 10.3+"
    else
    compat="Mac OS X 10.2+"
    fi
    fi
    fi
    elif [[ $extension =~ ^(sparsebundle|SPARSEBUNDLE)$ ]] ; then
    compat="Mac OS X 10.5+"
    elif [[ $extension =~ ^(sparseimage|SPARSEIMAGE)$ ]] ; then
    if [[ $crypt == "AES-256" ]] ; then
    compat="Mac OS X 10.5+"
    else
    compat="Mac OS X 10.3+"
    fi
    elif [[ $extension =~ ^(cdr|CDR|iso|ISO)$ ]] ; then
    compat="Mac OS X 10.0+"
    elif [[ $extension =~ ^(img|IMG)$ ]] ; then
    compat="OS 9"
    fi
    echo "Compatibility: $compat"
    echo "********"
    done
    echo "Done."
  5. JayBrown created this gist Jan 22, 2020.
    31 changes: 31 additions & 0 deletions ckapfs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash

    # ckapfs v0.1

    for filepath in "$@"
    do
    echo "$filepath"
    fsys=$(hdiutil imageinfo "$filepath" 2>/dev/null \
    | sed -n '/partition-filesystems:/,/[0-9]:$/p' \
    | sed -e '1,1d' -e '$d' | xargs \
    | awk -F: '{print $1}')
    sysn=$(echo "$fsys" | wc -l | xargs)
    if [[ $sysn -eq 0 ]] ; then
    echo "Error: no filesystems detected"
    elif [[ $sysn -eq 1 ]] ; then
    if [[ $fsys == "APFS" ]] ; then
    echo "Filesystem: $fsys (APFS detected!)"
    else
    echo "Filesystem: $fsys (not APFS)"
    fi
    else
    fsysx=$(echo "$fsys" | xargs)
    if [[ $(echo "$fsys" | grep "APFS") ]] ; then
    echo "Several filesystems detected: $fsysx (APFS detected!)"
    else
    echo "Several filesystems detected: $fsysx (not APFS)"
    fi
    fi
    echo "********"
    done
    echo "Done."