Last active
December 28, 2015 01:19
-
-
Save lashomb/7419958 to your computer and use it in GitHub Desktop.
First attempt at installing something with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/usr/bin/python | |
| import os, requests | |
| node_path = "/usr/local/bin/node" | |
| node_url = "http://nodejs.org/dist/v0.10.21/node-v0.10.21.pkg" | |
| os.chdir("/Users/Shared") | |
| def download_file(url): | |
| pkg_name = url.split('/')[-1] | |
| r = requests.get(url, stream=True) | |
| with open(pkg_name, 'wb') as f: | |
| for chunk in r.iter_content(chunk_size=1024): | |
| if chunk: # filter out keep-alive new chunks | |
| f.write(chunk) | |
| f.flush() | |
| return pkg_name | |
| package = os.path.realpath(download_file(node_url)) | |
| if not os.path.exists(node_path): | |
| from subprocess import call | |
| call(["/usr/sbin/installer", "-pkg", package, "-target", "/"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment