Skip to content

Commit

Permalink
Added support for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tech2077 committed Jun 25, 2012
1 parent f6c034d commit 8a1c920
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,7 +5,7 @@
## About
RasPiWrite is a simple and easily modifiable Python script that automates the process of mounting an SD card and downloading and installing a Linux image for a [Raspberry Pi](http://raspberrypi.org).

Currently the script is only compatible with Mac OS X systems, mostly because Macs have no easy way of installing Raspberry Pi distros. The goal is to try to make the script universal for all UNIX-like systems over time.
While this script has is fully functioning on Mac OS X, it now has at least working support for unix (Tested only on Ubuntu)

## Install

Expand Down
31 changes: 26 additions & 5 deletions raspiwrite.py
Expand Up @@ -53,6 +53,8 @@
end = "\033[0;0m"
WARNING = '\033[0;31m'

OS = os.uname() #gets OS vars

def checkforUpdate():
print 'Checking for updates...'
global version
Expand Down Expand Up @@ -154,8 +156,12 @@ def matchSD(input): #grabs just the drive's name from the df -h command (macOSX
return match

def unmount(location): #unmounts the drive so that it can be rewrittern
global OS
print 'Unmounting the drive in preparation for writing...'
output = getoutput('diskutil unmount ' + location)
if OS[0] != 'Darwin':
output = getoutput('umount ' + location)
else:
output = getoutput('diskutil unmount ' + location)
print output
if 'Unmount failed for' in output:
print WARNING + 'Error, the Following drive couldn\'t be unmounted, exiting...' + end
Expand All @@ -166,8 +172,9 @@ class transferInBackground (threading.Thread): #Runs the dd command in a thread
def run ( self ):
global SDsnip
global path
copyString = 'dd bs=1m if=%s of=%s' % (path,SDsnip)
copyString = 'dd bs=1M if=%s of=%s' % (path,SDsnip)
print 'Running ' + copyString + '...'

print getoutput(copyString)
print 'done!'

Expand Down Expand Up @@ -234,6 +241,12 @@ def transfer(file,archiveType,obtain,SD,URL): #unzips the disk image
else:
print 'Image has already been unzipped'
path = finalPath

if OS[0] != 'Darwin':
print getoutput('pwd')
path = getoutput("pwd")+ "/" + file.split("/")[-1].replace(".zip", "") + "/" + file.split("/")[-1].replace(".zip", ".img")
print path
print "Not Darwin\n"
else:
print 'Ok... Unzipping the disk , this may take a while...'
print getoutput(extractCMD) #extract here!
Expand All @@ -245,8 +258,17 @@ def transfer(file,archiveType,obtain,SD,URL): #unzips the disk image
else:
print 'Image has already been unzipped'
path = finalPath

if OS[0] != 'Darwin':
print getoutput('pwd')
path = getoutput("pwd")+ "/" + file.split("/")[-1].replace(".zip", "") + "/" + file.split("/")[-1].replace(".zip", ".img")
print path
print "Not Darwin\n"
global SDsnip
SDsnip = SD.replace(' ', '')[:-2]
if (SD.find("/dev/mmcblk") + 1):
SDsnip = "/dev/mmcblk" + SD[11]
else:
SDsnip = SD.replace(' ', '')[:-1]
print path
print '\n\n###################################################################'
print 'About to start the transfer procedure, here is your setup:'
Expand Down Expand Up @@ -401,10 +423,9 @@ def driveTest(SD):
////////////////////////
(Version 1.15 -MACOSX-)
"""
OS = os.uname() #gets OS vars
if OS[0] != 'Darwin': #if Mac OS, will change to posix once I have worked around some of the command differences
print WARNING + 'I\'m sorry, but your OS isn\'t supported at this time, Linux/Unix users - please tune in soon for a POSIX version' + end
exit()
# exit()
if not os.geteuid()==0:
print WARNING + 'Please run the script using sudo e.g. sudo python raspiwrite.py, or sudo ./raspiwrite.py (need to chmod +x first)' + end
exit()
Expand Down

0 comments on commit 8a1c920

Please sign in to comment.