Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions raspiwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@
# Copyright Matthew Jump 2012
# The following code is licenced under the Gnu Public Licence, please see gpl.txt for reference
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# VERSION 1.15-martinseener1 -MACOSX- (January 2013) BETA
# * Fixed some typos
# * Fixed missing colon at an else-statement
# * Fixed whitespaces at SDsnip lines
# * Disabled CheckForUpdate() Check at startup since .xml file isn't present anymore

# VERSION 1.15 -MACOSX- (June 2012) BETA
# * Fix to unzipping system - credit to alecthegeek
Expand All @@ -46,7 +52,7 @@
from random import choice
from xml.dom.minidom import parseString

version = 1.15
version = '1.15-martinseener1'

#Display Augs
boldStart = "\033[1m"
Expand Down Expand Up @@ -186,7 +192,8 @@ def transfer(file,archiveType,obtain,SD,URL): #unzips the disk image
global path
if archiveType == 'zip':
#path = file.replace(".zip", "") + '/' + file.replace(".zip", ".img") <- my old code
path = file.replace(".zip", "") + '/' + os.path.basename(file).replace(".zip", ".img") #Thanks to Lewis Boon
#path = file.replace(".zip", "") + '/' + os.path.basename(file).replace(".zip", ".img") #Thanks to Lewis Boon
path = './' + os.path.basename(file).replace(".zip", ".img") #Thanks to Lewis Boon, modified by Martin Seener
extractCMD = 'unzip ' + file

if archiveType == 'img':
Expand Down Expand Up @@ -272,10 +279,10 @@ def transfer(file,archiveType,obtain,SD,URL): #unzips the disk image
SDsnip = "/dev/mmcblk" + SD[11]
else:
if OS[0] != 'Darwin':
SDsnip = SD.replace(' ', '')[:-1]
SDsnip = SD.replace(' ', '')[:-1]
else:
# remove weird partition notation in OS X partition names
SDsnip = SD.replace(' ', '')[:-2]
# remove weird partition notation in OS X partition names
SDsnip = SD.replace(' ', '')[:-2]

print path
print '\n\n###################################################################'
Expand Down Expand Up @@ -396,13 +403,13 @@ def getImage(SD): #gives the user a bunch of options to download an image, or se

def driveTest(SD):

sdID = raw_input("I believe this is your SD card: " + SD + " is that correct? (Y/n) ")
sdID = raw_input("I believe this is your SD card: " + SD + " is that correct?(Y/n) ")
if (sdID == 'Y') or (sdID == 'y'): #continue
unmount(SD) #<--works, so don't need to test
getImage(SD)

if (sdID == 'N') or (sdID == 'n'):
manualID = raw_input("Please enter the location you believe holds the SD Card: ")
manualID = raw_input("Please enter the location (Filesystem like /dev/disk5s1 (/dev/disk5 is not enough!)) you believe holds the SD Card: ")
driveTest(manualID)

#logic:
Expand All @@ -429,15 +436,21 @@ def driveTest(SD):
* Matt Jump
* exaviorn.com
////////////////////////
(Version 1.15 -MACOSX-)
(Version 1.15-martinseener1 -MACOSX-)
"""
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()
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()
checkforUpdate()
try:
checkforUpdate()
except:
answer = raw_input("There was an issue checking for updates, Continue anyway? Y/n: ")
if not ("Y" in answer or "y" in answer):
print "Terminating..."
exit()
print 'The following script is designed to copy a Raspberry Pi compatible disk image to an SD Card'
print boldStart + 'INCORRECTLY FOLLOWING THE WIZARD COULD RESULT IN THE CORRUPTION OF YOUR HARD DISK, PARTITIONS OR A BACKUP USB DRIVE (INCLUDING MOUNTED TIME MACHINE BACKUP DRIVES)' +end
print 'It is advisable to remove any other USB HDDs or memory sticks, the wizard might select that one, %s if you have multiple hard drives installed, please take a LOT of care selecting the right drive %s'% (boldStart, end)
Expand Down Expand Up @@ -465,3 +478,4 @@ def driveTest(SD):
else: #otherwise...
SD = matchSD(volumes).group(1) #selects the first SD/USB drive located
driveTest(SD) #action gets delegated to driveTest, which then leads on to the next step, I found this to be the easiest way