Skip to content
This repository
Browse code

Merge pull request #8 from tech2077/master

Added functional Linux Support (tech2077)
  • Loading branch information...
commit d3f95d11ead02443d8f0074cd98625002580da08 2 parents 2939210 + 8a1c920
Matt Jump authored June 25, 2012

Showing 2 changed files with 26 additions and 5 deletions. Show diff stats Hide diff stats

  1. 2  README.md
  2. 29  raspiwrite.py
2  README.md
Source Rendered
@@ -5,7 +5,7 @@
5 5
 ## About
6 6
 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). 
7 7
 
8  
-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.
  8
+While this script has is fully functioning on Mac OS X, it now has at least working support for unix (Tested only on Ubuntu)
9 9
 
10 10
 ## Install
11 11
 
29  raspiwrite.py
@@ -53,6 +53,8 @@
53 53
 end = "\033[0;0m"
54 54
 WARNING = '\033[0;31m'
55 55
 
  56
+OS = os.uname() #gets OS vars
  57
+
56 58
 def checkforUpdate():
57 59
 	print 'Checking for updates...'
58 60
 	global version
@@ -154,8 +156,12 @@ def matchSD(input):	#grabs just the drive's name from the df -h command (macOSX
154 156
 	return match
155 157
 
156 158
 def unmount(location):	#unmounts the drive so that it can be rewrittern
  159
+	global OS
157 160
 	print 'Unmounting the drive in preparation for writing...'
158  
-	output = getoutput('diskutil unmount ' + location)
  161
+	if OS[0] != 'Darwin':
  162
+		output = getoutput('umount ' + location)
  163
+	else:
  164
+		output = getoutput('diskutil unmount ' + location)
159 165
 	print output
160 166
 	if 'Unmount failed for' in output:
161 167
 		print WARNING + 'Error, the Following drive couldn\'t be unmounted, exiting...' + end
@@ -168,6 +174,7 @@ def run ( self ):
168 174
 	global path
169 175
 	copyString = 'dd bs=1M if=%s of=%s' % (path,SDsnip)
170 176
 	print 'Running ' + copyString + '...'
  177
+
171 178
 	print getoutput(copyString)
172 179
 	print 'done!'
173 180
      
@@ -234,6 +241,12 @@ def transfer(file,archiveType,obtain,SD,URL):	#unzips the disk image
234 241
 				else:
235 242
 					print 'Image has already been unzipped'
236 243
 				path = finalPath
  244
+
  245
+			if OS[0] != 'Darwin':
  246
+				print getoutput('pwd')
  247
+				path = getoutput("pwd")+ "/" + file.split("/")[-1].replace(".zip", "") + "/" + file.split("/")[-1].replace(".zip", ".img")
  248
+				print path
  249
+				print "Not Darwin\n"
237 250
 		else:
238 251
 			print 'Ok... Unzipping the disk , this may take a while...'
239 252
 			print getoutput(extractCMD) #extract here!
@@ -245,8 +258,17 @@ def transfer(file,archiveType,obtain,SD,URL):	#unzips the disk image
245 258
 				else:
246 259
 					print 'Image has already been unzipped'
247 260
 				path = finalPath
  261
+
  262
+			if OS[0] != 'Darwin':
  263
+				print getoutput('pwd')
  264
+				path = getoutput("pwd")+ "/" + file.split("/")[-1].replace(".zip", "") + "/" + file.split("/")[-1].replace(".zip", ".img")
  265
+				print path
  266
+				print "Not Darwin\n"
248 267
 	global SDsnip
249  
-	SDsnip =  SD.replace(' ', '')[:-2]
  268
+	if (SD.find("/dev/mmcblk") + 1):
  269
+		SDsnip = "/dev/mmcblk" + SD[11]
  270
+	else:
  271
+		SDsnip =  SD.replace(' ', '')[:-1]
250 272
 	print path
251 273
 	print '\n\n###################################################################'
252 274
 	print 'About to start the transfer procedure, here is your setup:'
@@ -401,10 +423,9 @@ def driveTest(SD):
401 423
 ////////////////////////
402 424
 (Version 1.15 -MACOSX-)
403 425
 """
404  
-OS = os.uname() #gets OS vars
405 426
 if OS[0] != 'Darwin': #if Mac OS, will change to posix once I have worked around some of the command differences
406 427
 	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
407  
-	exit()
  428
+#	exit()
408 429
 if not os.geteuid()==0:
409 430
 	print WARNING + 'Please run the script using sudo e.g. sudo python raspiwrite.py, or sudo ./raspiwrite.py (need to chmod +x first)' + end
410 431
 	exit()

0 notes on commit d3f95d1

Please sign in to comment.
Something went wrong with that request. Please try again.