Skip to content

Commit dcee510

Browse files
committed
[TOOLS] Revamp FetchMacOS.
1 parent 5280012 commit dcee510

File tree

3 files changed

+100
-27
lines changed

3 files changed

+100
-27
lines changed

jumpstart.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,35 @@
55

66
TOOLS=$PWD/tools
77

8-
$TOOLS/FetchMacOS/fetch.sh
8+
print_usage() {
9+
echo
10+
echo "Usage: $0"
11+
echo
12+
echo " -s, --high-sierra Fetch High Sierra media."
13+
echo " -m, --mojave Fetch Mojave media."
14+
echo " -c, --catalina Fetch Catalina media."
15+
echo
16+
}
17+
18+
error() {
19+
local error_message="$@"
20+
echo "${error_message}" 1>&2;
21+
}
22+
23+
argument="$1"
24+
case $argument in
25+
-s|--high-sierra)
26+
$TOOLS/FetchMacOS/fetch.sh -p 091-95155 -c PublicRelease13 || exit 1;
27+
;;
28+
-m|--mojave)
29+
$TOOLS/FetchMacOS/fetch.sh -l -c PublicRelease14 || exit 1;
30+
;;
31+
-c|--catalina|*)
32+
$TOOLS/FetchMacOS/fetch.sh -l -c DeveloperSeed || exit 1;
33+
;;
34+
-h|--help)
35+
print_usage
36+
;;
37+
esac
38+
939
$TOOLS/dmg2img $TOOLS/FetchMacOS/BaseSystem/BaseSystem.dmg $PWD/BaseSystem.img

tools/FetchMacOS/fetch-macos.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import sys
1212

1313
__author__ = "Foxlet"
14-
__copyright__ = "Copyright 2018, FurCode Project"
14+
__copyright__ = "Copyright 2019, FurCode Project"
1515
__license__ = "GPLv3"
16-
__version__ = "1.2"
16+
__version__ = "1.3"
1717

1818
logging.basicConfig(format='%(asctime)-15s %(message)s', level=logging.INFO)
1919
logger = logging.getLogger('webactivity')
@@ -50,11 +50,13 @@ def check_directory(path):
5050

5151

5252
class SoftwareService:
53-
# macOS 10.14 ships in 4 different catalogs from SoftwareScan
53+
# macOS 10.15 is available in 4 different catalogs from SoftwareScan
5454
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",
5555
"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",
5656
"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",
57-
"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"}
57+
"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",
58+
"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",
59+
"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"}
5860

5961
def __init__(self, catalog_id):
6062
self.catalog_url = self.catalogs.get(catalog_id, self.catalogs["PublicRelease"])
@@ -67,38 +69,42 @@ def getcatalog(self):
6769
return catalog_raw.text.encode('UTF-8')
6870

6971
def getosinstall(self):
70-
if (sys.version_info > (3, 0)):
71-
root = plistlib.readPlistFromBytes(self.catalog_data)
72+
# Load catalogs based on Py3/2 lib
73+
if sys.version_info > (3, 0):
74+
root = plistlib.loads(self.catalog_data)
7275
else:
7376
root = plistlib.readPlistFromString(self.catalog_data)
77+
78+
# Iterate to find valid OSInstall packages
79+
ospackages = []
7480
products = root['Products']
7581
for product in products:
76-
if 'ExtendedMetaInfo' in products[product]:
77-
IAMetaInfo = products[product]['ExtendedMetaInfo']
78-
if 'InstallAssistantPackageIdentifiers' in IAMetaInfo:
79-
IAPackageID = IAMetaInfo['InstallAssistantPackageIdentifiers']
80-
if IAPackageID['OSInstall'] == 'com.apple.mpkg.OSInstall':
81-
return product
82+
if products.get(product, {}).get('ExtendedMetaInfo', {}).get('InstallAssistantPackageIdentifiers', {}).get('OSInstall', {}) == 'com.apple.mpkg.OSInstall':
83+
ospackages.append(product)
84+
return ospackages
8285

8386

8487
class MacOSProduct:
8588
def __init__(self, catalog, product_id):
86-
if (sys.version_info > (3, 0)):
87-
root = plistlib.readPlistFromBytes(catalog)
89+
if sys.version_info > (3, 0):
90+
root = plistlib.loads(catalog)
8891
else:
8992
root = plistlib.readPlistFromString(catalog)
9093
products = root['Products']
9194
self.date = root['IndexDate']
9295
self.product = products[product_id]
9396

94-
def fetchpackages(self, path):
97+
def fetchpackages(self, path, keyword=None):
9598
Filesystem.check_directory(path)
9699
packages = self.product['Packages']
97-
for item in packages:
98-
if "BaseSystem" in item.get("URL"):
100+
if keyword:
101+
for item in packages:
102+
if keyword in item.get("URL"):
103+
Filesystem.download_file(item.get("URL"), item.get("Size"), path)
104+
else:
105+
for item in packages:
99106
Filesystem.download_file(item.get("URL"), item.get("Size"), path)
100107

101-
102108
@click.command()
103109
@click.option('-o', '--output-dir', default="BaseSystem/", help="Target directory for package output.")
104110
@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=
109115
remote = SoftwareService(catalog_id)
110116
catalog = remote.getcatalog()
111117

112-
# Get the current macOS package
118+
# If latest is used, find the latest OSInstall package
113119
if latest:
114-
product_id = remote.getosinstall()
120+
product_id = remote.getosinstall()[-1]
115121
else:
116122
if product_id == "":
117123
print("You must provide a Product ID (or pass the -l flag) to continue.")
118124
exit(1)
119-
product_id = product_id
125+
126+
# Fetch the given Product ID
120127
try:
121-
update = MacOSProduct(catalog, product_id)
128+
product = MacOSProduct(catalog, product_id)
122129
except KeyError:
123130
print("Product ID {} could not be found.".format(product_id))
124131
exit(1)
125132
logging.info("Selected macOS Product: {}".format(product_id))
126133

127134
# Download package to disk
128-
update.fetchpackages(output_dir)
135+
product.fetchpackages(output_dir, keyword="BaseSystem")
129136

130137
if __name__ == "__main__":
131138
fetchmacos()

tools/FetchMacOS/fetch.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1+
#!/bin/bash
2+
3+
# fetch.sh: Run fetch-macos.py with safety checks
4+
# by Foxlet <foxlet@furcode.co>
5+
16
set +x;
27
SCRIPTDIR="$(dirname "$0")";
38
cd $SCRIPTDIR
4-
sudo easy_install pip
5-
sudo -H pip install -r requirements.txt
6-
python fetch-macos.py -p 041-71284 -c DeveloperSeed
9+
10+
initpip() {
11+
sudo easy_install pip
12+
pip install -r requirements.txt --user
13+
}
14+
15+
getpip(){
16+
if [ -x "$(command -v pip3)" ]; then
17+
pip3 install -r requirements.txt --user
18+
elif [ -x "$(command -v pip)" ]; then
19+
pip install -r requirements.txt --user
20+
else
21+
echo "pip will be installed..." >&2
22+
initpip
23+
fi
24+
}
25+
26+
getpython(){
27+
if [ -x "$(command -v python3)" ]; then
28+
PYTHONBIN=python3
29+
elif [ -x "$(command -v python)" ]; then
30+
PYTHONBIN=python
31+
elif [ -x "$(command -v python2)" ]; then
32+
PYTHONBIN=python2
33+
else
34+
echo "Please install Python 3 before continuing." >&2
35+
exit 1;
36+
fi
37+
}
38+
39+
getpip
40+
getpython
41+
$PYTHONBIN fetch-macos.py $*
42+
743
exit;

0 commit comments

Comments
 (0)