Facebook
From Baby Crow, 2 Years ago, written in Bash.
Embed
Download Paste or View Raw
Hits: 353
  1. #!/bin/bash
  2.  
  3. # This program is free software. It comes without any warranty, to
  4. # the extent permitted by applicable law. You can redistribute it
  5. # and/or modify it under the terms of the Do What The {censored} You Want
  6. # To Public License, Version 2, as published by Sam Hocevar. See
  7. # http://www.wtfpl.net/ for more details. */
  8.  
  9. # One more contribution to open source world.
  10.  
  11. # Note: try to reduce lines and add more features
  12. #       you will be add in contribute area.
  13.  
  14.  
  15. # Global functions
  16. print() { printf -- "$1\n"; }
  17. log() { printf -- "\033[37m LOG: $1 \033[0m\n"; }
  18. success() { printf -- "\033[32m SUCCESS: $1 \033[0m\n"; }
  19. warning() { printf -- "\033[33m WARNING: $1 \033[0m\n"; }
  20. error() { printf -- "\033[31m ERROR: $1 \033[0m\n"; }
  21. heading() { printf -- "   \033[1;30;42m $1 \033[0m\n\n"; }
  22. newUiPage() {
  23.   clear
  24.   echo "---------------------------------------------------"
  25.   echo "-       macOS Legit Copy Downloader v1.0.1        -"
  26.   echo "-                By Hanger1 (H1)                  -"
  27.   echo "---------------------------------------------------"
  28.   echo " Contributor: ricoc90"
  29.   echo " "
  30.   echo " "
  31. }
  32.  
  33.  
  34. # Global Variables
  35. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  36. tmpDir="$DIR"
  37. srcDir="$DIR/macOSsrc"
  38.  
  39. # Prgram functions
  40. downloadAndParseCatalog(){
  41.  
  42.    # Download catalog file from apple server
  43.    #-------------------------------
  44.    print "\nLoading macOS catalog from swscan.apple.com..."
  45.    if ! curl --fail -s -f -o "$tmpDir/catalog.gz" "$1"; then error "Failed to download catalog" && exit; fi
  46.    gunzip -k "$tmpDir/catalog.gz"
  47.    rm "$tmpDir/catalog.gz"
  48.  
  49.  
  50.    # Parse catalog file into arrays
  51.    #-------------------------------
  52.    versionsArray=($(getListOfVersions))
  53.  
  54.    appleDiagnosticsArray=($(findLinkInCatalog AppleDiagnostics.dmg "$tmpDir/catalog"))
  55.    appleDiagnosticsChunklistArray=($(findLinkInCatalog AppleDiagnostics.chunklist "$tmpDir/catalog"))
  56.    baseSystemArray=($(findLinkInCatalog BaseSystem.dmg "$tmpDir/catalog"))
  57.    baseSystemChunklistArray=($(findLinkInCatalog BaseSystem.chunklist "$tmpDir/catalog"))
  58.    installInfoArray=($(findLinkInCatalog InstallInfo.plist "$tmpDir/catalog"))
  59.    installESDArray=($(findLinkInCatalog InstallESDDmg.pkg "$tmpDir/catalog"))
  60.  
  61.    rm "$tmpDir/catalog"
  62.  
  63. }
  64.  
  65. findLinkInCatalog(){
  66.    array=($(awk '/'$1'</{print $1}' "$2"))
  67.    let index=0
  68.    for element in "${array[@]}"; do
  69.        array[$index]="${element:8:${#element}-17}"
  70.        let index=index+1
  71.    done
  72.    echo ${array[@]}
  73. }
  74.  
  75. getListOfVersions(){
  76.    versionInfoArray=($(findLinkInCatalog InstallInfo.plist "$tmpDir/catalog"))
  77.    let index=0
  78.    for element in "${versionInfoArray[@]}"; do
  79.        infoline=$(curl -s -f $element | tail -5)
  80.        versionInfo[$index]="$(echo $infoline | awk -v FS="(string>|</string)" '{print $2}')"
  81.        let index++
  82.    done
  83.    echo ${versionInfo[@]}
  84. }
  85.  
  86.  
  87.  
  88.  
  89. checkOSAvaibility() {
  90.    if curl --output /dev/null --silent --head --fail "https://swscan.apple.com/content/catalogs/others/index-$1seed-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog.gz"; then echo "$1"; else echo "10.14"; fi
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. downloadOS(){
  98.    # Print User Interface
  99.    newUiPage
  100.    LATEST_VERSION=$(checkOSAvaibility "10.15")
  101.  
  102.    # User input for selecting release type
  103.    PS3=""$'\n(You can also able to download macOS 10.15 when it will available)\n\n'"Which release you want? "
  104.    select RELEASETYPE in "Developer Release" "Beta Release" "Public Release"; do
  105.        case $RELEASETYPE in
  106.            Developer* ) CATALOGTYPE="-${LATEST_VERSION}seed"; break;;
  107.            Beta* ) CATALOGTYPE="-${LATEST_VERSION}beta"; break;;
  108.            Public* ) break;;
  109.        esac
  110.    done
  111.  
  112.  
  113.    downloadAndParseCatalog "https://swscan.apple.com/content/catalogs/others/index${CATALOGTYPE}-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog.gz"
  114.  
  115.  
  116.    newUiPage
  117.    # User input for selecting macOS versions
  118.    PS3=""$'\n'"Select macOS version : "
  119.    select MACVERSION in "${versionsArray[@]}"; do
  120.        if [[ $REPLY -le ${#versionsArray[@]} && $REPLY -gt 0 ]]
  121.            then
  122.  
  123.                # Dont break sequence (It's sequenced with $fileNames[@])
  124.                links=(${appleDiagnosticsArray[$[$REPLY - 1]]} ${appleDiagnosticsChunklistArray[$[$REPLY - 1]]} ${baseSystemArray[$[$REPLY - 1]]} ${baseSystemChunklistArray[$[$REPLY - 1]]} ${installInfoArray[$[$REPLY - 1]]} ${installESDArray[$[$REPLY - 1]]})
  125.                fileNames=("AppleDiagnostics.dmg" "AppleDiagnostics.chunklist" "BaseSystem.dmg" "BaseSystem.chunklist" "InstallInfo.plist" "InstallESDDmg.pkg")
  126.                
  127.                # Ask user to download macOS or only print links
  128.                while true; do read -p ""$'\n'"You wanna download macOS ? [y/n] " yn
  129.                    print ""
  130.                    if [[ $yn == y ]]; then
  131.  
  132.                            # make source directory
  133.                            if [ ! -d "$srcDir" ]; then mkdir "$srcDir"; fi
  134.  
  135.                            # Download files into $srcDir from $links[@]
  136.                            for i in {0..5}; do
  137.                                curl -f -o "$srcDir/${fileNames[$i]}" "${links[$i]}"
  138.                            done && break;
  139.  
  140.                        elif [[ $yn == n ]]; then
  141.                            for link in "${links[@]}"; do print $link; done && break; #&& exit;
  142.                    fi
  143.                done
  144.  
  145.                break
  146.            else error "Invalid choice."
  147.        fi
  148.    done
  149. }
  150.  
  151.  
  152.  
  153. createinstallmedia(){
  154.    #---------------------------------------------------------------------------
  155.    #  Create Install Media
  156.    #---------------------------------------------------------------------------
  157.  
  158.    # Taking ownership of downloaded files
  159.    #-------------------------------------------------
  160.    chmod a+x "$srcDir/BaseSystem.dmg"
  161.    chmod a+x "$srcDir/BaseSystem.chunklist"
  162.    chmod a+x "$srcDir/InstallInfo.plist"
  163.    chmod a+x "$srcDir/InstallESDDmg.pkg"
  164.    chmod a+x "$srcDir/AppleDiagnostics.dmg"
  165.    chmod a+x "$srcDir/AppleDiagnostics.chunklist"
  166.  
  167.  
  168.    # Mount 'BaseSystem.dmg'
  169.    #-------------------------
  170.    $(hdiutil attach "$srcDir/BaseSystem.dmg" 2>&1 >/dev/null)
  171.  
  172.    print "\n\nMake sure \"macOS Base System\" volume is mounted\n"
  173.    read -p "Press enter to continue..."
  174.  
  175.  
  176.    # Pull 'Install macOS XXXX.app' from 'BaseSystem.dmg'
  177.    #-----------------------------------------------------
  178.    FOLDERS=(/Volumes/*)
  179.    for folder in "${FOLDERS[@]}"; do
  180.        [[ -d "$folder" && "$folder" =~ "macOS Base System" ]] && basePath="$folder"
  181.    done
  182.    
  183.  
  184.  
  185.    for file in "$basePath/"*; do # Find XXXX.app in mounted volume
  186.        if [[ $file == *.app ]]; then
  187.            let index=${#name_array[@]}
  188.            name_array[$index]="${file##*/}"
  189.        fi
  190.    done
  191.    installAppName=${name_array[0]}
  192.  
  193.  
  194.  
  195.    newUiPage
  196.    print "Copying $installAppName to out folder..."
  197.    cp -R "/Volumes/macOS Base System/$installAppName" "$DIR/"
  198.  
  199.  
  200.    # UnMount 'BaseSystem.dmg'
  201.    #-------------------------
  202.    $(hdiutil detach /Volumes/macOS\ Base\ System 2>&1 >/dev/null)
  203.  
  204.    print "Copying Files to SharedSupport folder...\n"
  205.  
  206.    # Create SharedSupport folder inside 'Install macOS XXXX.app/Contents'
  207.    #----------------------------------------------------------------------
  208.    SharedSupportDir="$DIR/${installAppName}/Contents/SharedSupport"
  209.    if [ ! -d "$SharedSupportDir" ]; then mkdir "$SharedSupportDir"; fi
  210.  
  211.  
  212.    # Copy All contents of src folder to 'Install macOS XXXX.app/Contents/SharedSupport'
  213.    #----------------------------------------------------------------------
  214.    # cp -R $srcDir/* $DIR/Install\ macOS\ Mojave\ Beta.app/Contents/SharedSupport
  215.  
  216.    cp -R "$srcDir/BaseSystem.dmg" "$SharedSupportDir"
  217.    cp -R "$srcDir/BaseSystem.chunklist" "$SharedSupportDir"
  218.    cp -R "$srcDir/InstallInfo.plist" "$SharedSupportDir"
  219.    cp -R "$srcDir/AppleDiagnostics.dmg" "$SharedSupportDir"
  220.    cp -R "$srcDir/AppleDiagnostics.chunklist" "$SharedSupportDir"
  221.  
  222.    # This file will be copied with InstallESD.dmg name
  223.    cp -R "$srcDir/InstallESDDmg.pkg" "$SharedSupportDir/InstallESD.dmg"
  224.  
  225.  
  226.    # Replace <string>InstallESDDmg.pkg</string> to <string>InstallESD.dmg</string> in 'src/InstallInfo.plist'
  227.    #----------------------------------------------------------------------------------------------------------
  228.    sed -i "" 's/<string>InstallESDDmg.pkg<\/string>/<string>InstallESD.dmg<\/string>/g' "$SharedSupportDir/InstallInfo.plist"
  229.  
  230.  
  231.  
  232.    # Remove these lines from 'src/InstallInfo.plist'
  233.    #------------------------------------------------
  234.     #           <key>chunklistURL</key>
  235.     #           <string>InstallESDDmg.chunklist</string>
  236.     #           <key>chunklistid</key>
  237.     #           <string>com.apple.chunklist.InstallESDDmg</string>
  238.    sed -i "" '30,33d' "$SharedSupportDir/InstallInfo.plist"
  239.  
  240.  
  241.    # Replace <string>com.apple.pkg.InstallESDDmg</string> to <string>com.apple.dmg.InstallESD</string> in 'src/InstallInfo.plist'
  242.    #----------------------------------------------------------------------------------------------------------
  243.    sed -i "" 's/<string>com.apple.pkg.InstallESDDmg<\/string>/<string>com.apple.dmg.InstallESD<\/string>/g' "$SharedSupportDir/InstallInfo.plist"
  244.  
  245.  
  246.    # Replace InstallESDDmg.pkg to InstallESD.dmg in 'src/InstallInfo.plist'
  247.    #----------------------------------------------------------------------------------------------------------
  248.    sed -i "" 's/InstallESDDmg.pkg/InstallESD.dmg/g' "$SharedSupportDir/InstallInfo.plist"
  249.  
  250.  
  251.    # newUiPage
  252.  
  253.    DEVICES=($(ls /Volumes))
  254.  
  255.    read -p 'Enter name of USB media : ' INSTALLER_DEVICE
  256.  
  257.  
  258.  
  259.    # Creates a bootable installer for macOS on selected media
  260.    # As discribed in https://support.apple.com/en-us/HT201372
  261.    print ""
  262.    sudo "$DIR/$installAppName/Contents/Resources/createinstallmedia" --volume /Volumes/$INSTALLER_DEVICE
  263.  
  264.  
  265.    read -p 'You wanna delete downloaded files ? (y/n) : ' ANSWER
  266.    if [ $ANSWER == y ]; then rm -R "$srcDir"; fi
  267. }
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275. newUiPage
  276. # User input for selecting release type
  277. PS3=""$'\n'"What you want to do? "
  278. select RELEASETYPE in "Download macOS" "Make bootable Media"; do
  279.    case $RELEASETYPE in
  280.        Download* ) downloadOS; break;;
  281.        Make* ) createinstallmedia; break;;
  282.    esac
  283. done
  284.  
  285.  
  286. exit

Replies to Untitled rss

Title Name Language When
Re: Untitled Paltry Pig bash 1 Year ago.