mirror of
https://github.com/foxlet/macOS-Simple-KVM.git
synced 2024-11-23 03:29:41 +01:00
[TOOLS] Revamp FetchMacOS.
This commit is contained in:
parent
528001280c
commit
dcee51047f
3 changed files with 100 additions and 27 deletions
32
jumpstart.sh
32
jumpstart.sh
|
@ -5,5 +5,35 @@
|
||||||
|
|
||||||
TOOLS=$PWD/tools
|
TOOLS=$PWD/tools
|
||||||
|
|
||||||
$TOOLS/FetchMacOS/fetch.sh
|
print_usage() {
|
||||||
|
echo
|
||||||
|
echo "Usage: $0"
|
||||||
|
echo
|
||||||
|
echo " -s, --high-sierra Fetch High Sierra media."
|
||||||
|
echo " -m, --mojave Fetch Mojave media."
|
||||||
|
echo " -c, --catalina Fetch Catalina media."
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local error_message="$@"
|
||||||
|
echo "${error_message}" 1>&2;
|
||||||
|
}
|
||||||
|
|
||||||
|
argument="$1"
|
||||||
|
case $argument in
|
||||||
|
-s|--high-sierra)
|
||||||
|
$TOOLS/FetchMacOS/fetch.sh -p 091-95155 -c PublicRelease13 || exit 1;
|
||||||
|
;;
|
||||||
|
-m|--mojave)
|
||||||
|
$TOOLS/FetchMacOS/fetch.sh -l -c PublicRelease14 || exit 1;
|
||||||
|
;;
|
||||||
|
-c|--catalina|*)
|
||||||
|
$TOOLS/FetchMacOS/fetch.sh -l -c DeveloperSeed || exit 1;
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
print_usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
$TOOLS/dmg2img $TOOLS/FetchMacOS/BaseSystem/BaseSystem.dmg $PWD/BaseSystem.img
|
$TOOLS/dmg2img $TOOLS/FetchMacOS/BaseSystem/BaseSystem.dmg $PWD/BaseSystem.img
|
||||||
|
|
|
@ -11,9 +11,9 @@ import requests
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
__author__ = "Foxlet"
|
__author__ = "Foxlet"
|
||||||
__copyright__ = "Copyright 2018, FurCode Project"
|
__copyright__ = "Copyright 2019, FurCode Project"
|
||||||
__license__ = "GPLv3"
|
__license__ = "GPLv3"
|
||||||
__version__ = "1.2"
|
__version__ = "1.3"
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)-15s %(message)s', level=logging.INFO)
|
logging.basicConfig(format='%(asctime)-15s %(message)s', level=logging.INFO)
|
||||||
logger = logging.getLogger('webactivity')
|
logger = logging.getLogger('webactivity')
|
||||||
|
@ -50,11 +50,13 @@ class Filesystem:
|
||||||
|
|
||||||
|
|
||||||
class SoftwareService:
|
class SoftwareService:
|
||||||
# macOS 10.14 ships in 4 different catalogs from SoftwareScan
|
# macOS 10.15 is available in 4 different catalogs from SoftwareScan
|
||||||
catalogs = {"CustomerSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15customerseed-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
catalogs = {"CustomerSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15customerseed-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
||||||
"DeveloperSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15seed-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
"DeveloperSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15seed-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
||||||
"PublicSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15beta-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
"PublicSeed":"https://swscan.apple.com/content/catalogs/others/index-10.15beta-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
||||||
"PublicRelease":"https://swscan.apple.com/content/catalogs/others/index-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"}
|
"PublicRelease":"https://swscan.apple.com/content/catalogs/others/index-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
||||||
|
"PublicRelease14":"https://swscan.apple.com/content/catalogs/others/index-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog",
|
||||||
|
"PublicRelease13":"https://swscan.apple.com/content/catalogs/others/index-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog"}
|
||||||
|
|
||||||
def __init__(self, catalog_id):
|
def __init__(self, catalog_id):
|
||||||
self.catalog_url = self.catalogs.get(catalog_id, self.catalogs["PublicRelease"])
|
self.catalog_url = self.catalogs.get(catalog_id, self.catalogs["PublicRelease"])
|
||||||
|
@ -67,38 +69,42 @@ class SoftwareService:
|
||||||
return catalog_raw.text.encode('UTF-8')
|
return catalog_raw.text.encode('UTF-8')
|
||||||
|
|
||||||
def getosinstall(self):
|
def getosinstall(self):
|
||||||
if (sys.version_info > (3, 0)):
|
# Load catalogs based on Py3/2 lib
|
||||||
root = plistlib.readPlistFromBytes(self.catalog_data)
|
if sys.version_info > (3, 0):
|
||||||
|
root = plistlib.loads(self.catalog_data)
|
||||||
else:
|
else:
|
||||||
root = plistlib.readPlistFromString(self.catalog_data)
|
root = plistlib.readPlistFromString(self.catalog_data)
|
||||||
|
|
||||||
|
# Iterate to find valid OSInstall packages
|
||||||
|
ospackages = []
|
||||||
products = root['Products']
|
products = root['Products']
|
||||||
for product in products:
|
for product in products:
|
||||||
if 'ExtendedMetaInfo' in products[product]:
|
if products.get(product, {}).get('ExtendedMetaInfo', {}).get('InstallAssistantPackageIdentifiers', {}).get('OSInstall', {}) == 'com.apple.mpkg.OSInstall':
|
||||||
IAMetaInfo = products[product]['ExtendedMetaInfo']
|
ospackages.append(product)
|
||||||
if 'InstallAssistantPackageIdentifiers' in IAMetaInfo:
|
return ospackages
|
||||||
IAPackageID = IAMetaInfo['InstallAssistantPackageIdentifiers']
|
|
||||||
if IAPackageID['OSInstall'] == 'com.apple.mpkg.OSInstall':
|
|
||||||
return product
|
|
||||||
|
|
||||||
|
|
||||||
class MacOSProduct:
|
class MacOSProduct:
|
||||||
def __init__(self, catalog, product_id):
|
def __init__(self, catalog, product_id):
|
||||||
if (sys.version_info > (3, 0)):
|
if sys.version_info > (3, 0):
|
||||||
root = plistlib.readPlistFromBytes(catalog)
|
root = plistlib.loads(catalog)
|
||||||
else:
|
else:
|
||||||
root = plistlib.readPlistFromString(catalog)
|
root = plistlib.readPlistFromString(catalog)
|
||||||
products = root['Products']
|
products = root['Products']
|
||||||
self.date = root['IndexDate']
|
self.date = root['IndexDate']
|
||||||
self.product = products[product_id]
|
self.product = products[product_id]
|
||||||
|
|
||||||
def fetchpackages(self, path):
|
def fetchpackages(self, path, keyword=None):
|
||||||
Filesystem.check_directory(path)
|
Filesystem.check_directory(path)
|
||||||
packages = self.product['Packages']
|
packages = self.product['Packages']
|
||||||
for item in packages:
|
if keyword:
|
||||||
if "BaseSystem" in item.get("URL"):
|
for item in packages:
|
||||||
|
if keyword in item.get("URL"):
|
||||||
|
Filesystem.download_file(item.get("URL"), item.get("Size"), path)
|
||||||
|
else:
|
||||||
|
for item in packages:
|
||||||
Filesystem.download_file(item.get("URL"), item.get("Size"), path)
|
Filesystem.download_file(item.get("URL"), item.get("Size"), path)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('-o', '--output-dir', default="BaseSystem/", help="Target directory for package output.")
|
@click.option('-o', '--output-dir', default="BaseSystem/", help="Target directory for package output.")
|
||||||
@click.option('-c', '--catalog-id', default="PublicRelease", help="Name of catalog.")
|
@click.option('-c', '--catalog-id', default="PublicRelease", help="Name of catalog.")
|
||||||
|
@ -109,23 +115,24 @@ def fetchmacos(output_dir="BaseSystem/", catalog_id="PublicRelease", product_id=
|
||||||
remote = SoftwareService(catalog_id)
|
remote = SoftwareService(catalog_id)
|
||||||
catalog = remote.getcatalog()
|
catalog = remote.getcatalog()
|
||||||
|
|
||||||
# Get the current macOS package
|
# If latest is used, find the latest OSInstall package
|
||||||
if latest:
|
if latest:
|
||||||
product_id = remote.getosinstall()
|
product_id = remote.getosinstall()[-1]
|
||||||
else:
|
else:
|
||||||
if product_id == "":
|
if product_id == "":
|
||||||
print("You must provide a Product ID (or pass the -l flag) to continue.")
|
print("You must provide a Product ID (or pass the -l flag) to continue.")
|
||||||
exit(1)
|
exit(1)
|
||||||
product_id = product_id
|
|
||||||
|
# Fetch the given Product ID
|
||||||
try:
|
try:
|
||||||
update = MacOSProduct(catalog, product_id)
|
product = MacOSProduct(catalog, product_id)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("Product ID {} could not be found.".format(product_id))
|
print("Product ID {} could not be found.".format(product_id))
|
||||||
exit(1)
|
exit(1)
|
||||||
logging.info("Selected macOS Product: {}".format(product_id))
|
logging.info("Selected macOS Product: {}".format(product_id))
|
||||||
|
|
||||||
# Download package to disk
|
# Download package to disk
|
||||||
update.fetchpackages(output_dir)
|
product.fetchpackages(output_dir, keyword="BaseSystem")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
fetchmacos()
|
fetchmacos()
|
||||||
|
|
|
@ -1,7 +1,43 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# fetch.sh: Run fetch-macos.py with safety checks
|
||||||
|
# by Foxlet <foxlet@furcode.co>
|
||||||
|
|
||||||
set +x;
|
set +x;
|
||||||
SCRIPTDIR="$(dirname "$0")";
|
SCRIPTDIR="$(dirname "$0")";
|
||||||
cd $SCRIPTDIR
|
cd $SCRIPTDIR
|
||||||
sudo easy_install pip
|
|
||||||
sudo -H pip install -r requirements.txt
|
initpip() {
|
||||||
python fetch-macos.py -p 041-71284 -c DeveloperSeed
|
sudo easy_install pip
|
||||||
|
pip install -r requirements.txt --user
|
||||||
|
}
|
||||||
|
|
||||||
|
getpip(){
|
||||||
|
if [ -x "$(command -v pip3)" ]; then
|
||||||
|
pip3 install -r requirements.txt --user
|
||||||
|
elif [ -x "$(command -v pip)" ]; then
|
||||||
|
pip install -r requirements.txt --user
|
||||||
|
else
|
||||||
|
echo "pip will be installed..." >&2
|
||||||
|
initpip
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
getpython(){
|
||||||
|
if [ -x "$(command -v python3)" ]; then
|
||||||
|
PYTHONBIN=python3
|
||||||
|
elif [ -x "$(command -v python)" ]; then
|
||||||
|
PYTHONBIN=python
|
||||||
|
elif [ -x "$(command -v python2)" ]; then
|
||||||
|
PYTHONBIN=python2
|
||||||
|
else
|
||||||
|
echo "Please install Python 3 before continuing." >&2
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
getpip
|
||||||
|
getpython
|
||||||
|
$PYTHONBIN fetch-macos.py $*
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in a new issue