···11+#!/usr/bin/python2.7
22+# This file is part of Darling.
33+#
44+# Copyright (C) 2020 Lubos Dolezel
55+#
66+# Darling is free software: you can redistribute it and/or modify
77+# it under the terms of the GNU General Public License as published by
88+# the Free Software Foundation, either version 3 of the License, or
99+# (at your option) any later version.
1010+#
1111+# Darling is distributed in the hope that it will be useful,
1212+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+# GNU General Public License for more details.
1515+#
1616+# You should have received a copy of the GNU General Public License
1717+# along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+1919+import urllib2
2020+import json
2121+import tempfile
2222+import os
2323+import subprocess
2424+2525+print("You are about to download and install Apple Command Line Tools covered by the following license:")
2626+print("https://www.apple.com/legal/sla/docs/xcode.pdf\n")
2727+2828+while True:
2929+ resp = raw_input("Do you agree with the terms of the license? (y/n) ")
3030+3131+ if resp == "y":
3232+ break
3333+ elif resp == "n":
3434+ exit(1)
3535+3636+packagesResp = urllib2.urlopen("https://swdistcache.darlinghq.org/api/v1/products/by-tag?tag=DTCommandLineTools")
3737+packages = json.loads(packagesResp.read())
3838+3939+tempdir = tempfile.mkdtemp()
4040+4141+print("Downloading packages...")
4242+4343+for package in packages[0]['packages']:
4444+ fname = os.path.basename(package['url'])
4545+ print("Downloading " + fname + "...")
4646+4747+ f = urllib2.urlopen(package['url'])
4848+4949+ fullpath = tempdir + "/" + fname
5050+ with open(fullpath, "wb") as localfile:
5151+ for chunk in iter(lambda: f.read(16*1024), ''):
5252+ localfile.write(chunk)
5353+5454+ print("Installing...")
5555+ exitCode = subprocess.call(["sudo", "installer", "-pkg", fullpath, "-target", "/"])
5656+5757+ if exitCode != 0:
5858+ print("Installation failed with exit code " + str(exitCode))
5959+ exit(1)
6060+6161+ os.remove(fullpath)
6262+6363+os.rmdir(tempdir)
6464+6565+print("Installation complete!")