Downloads and extracts disk 7 now

I'm not real happy with how I'm doing this.  It's obviously not as clean
or as simple as a shell script would be, but that's to be expected since
we have to emulate with those shell commands--whole programs in their
own right--do.  But right now, the logic doesn't flow right either for a
structured program or an unstructured shell script.  Probably trying to
do too much in one go there.
This commit is contained in:
T. Joseph Carter 2015-11-06 23:55:36 -08:00
parent d52b6ef9f1
commit c3b4829e26

View File

@ -1,26 +1,35 @@
#! /usr/bin/env python
import os, sys, subprocess
import tempfile
gsosDir = "/media/A2SHARED/FILES"
imagesDir = gsosDir + "/GSOS.INSTALLER/IMAGES"
imageToolsDir = gsosDir + "/GSOS.INSTALLER/IMAGE.TOOLS"
netInstallDir = gsosDir + "/GSOS.INSTALLER/NET.INSTALL"
gsosDir = '/media/A2SHARED/FILES'
imagesDir = gsosDir + '/GSOS.INSTALLER/IMAGES'
imageToolsDir = gsosDir + '/GSOS.INSTALLER/IMAGE.TOOLS'
netInstallDir = gsosDir + '/GSOS.INSTALLER/NET.INSTALL'
p8Dir = "/media/A2SHARED/A2FILES"
diskToolsP8Dir = p8Dir + "/DISK.TOOLS.P8"
p8Dir = '/media/A2SHARED/A2FILES'
diskToolsP8Dir = p8Dir + '/DISK.TOOLS.P8'
commDir = "/media/A2SHARED/A2FILES/COMM"
spectrumDir = commDir + "/SPECTRUM"
protermDir = commDir + "/PROTERM"
zlinkDir = commDir + "/Z.LINK"
adtproDir = commDir + "/ADTPRO"
commDir = '/media/A2SHARED/A2FILES/COMM'
spectrumDir = commDir + '/SPECTRUM'
protermDir = commDir + '/PROTERM'
zlinkDir = commDir + '/Z.LINK'
adtproDir = commDir + '/ADTPRO'
disk7_filename = 'Disk_7_of_7-Apple_II_Setup.sea.bin'
disk7_url = 'http://archive.org/download/download.info.apple.com.2012.11/download.info.apple.com.2012.11.zip/download.info.apple.com%2FApple_Support_Area%2FApple_Software_Updates%2FEnglish-North_American%2FApple_II%2FApple_IIGS_System_6.0.1%2F' + disk7_filename
# Python 3.x replaced (useless) input() with raw_input()
try:
stdin_input = raw_input
stdin_input = raw_input # Python 2
except NameError:
stdin_input = input
stdin_input = input # Python 3
try:
import urllib.request as urlrequest # Python 3
except ImportError:
import urllib2 as urlrequest # Python 2
# Differing from the shell script in that we explicitly strip the / here
if os.environ.has_key('A2SERVER_SCRIPT_URL'):
@ -29,16 +38,55 @@ if os.environ.has_key('A2SERVER_SCRIPT_URL'):
if scriptURL.endsWith('/'):
scriptURL = scriptURL[:-1]
else:
scriptURL = "http://appleii.ivanx.com/a2server"
scriptURL = 'http://appleii.ivanx.com/a2server'
def download_url(url, filename):
html = urlrequest.urlopen(url)
data = html.read()
f = open(filename, 'wb')
f.write(data)
f.close
def do_install():
pass
netboot_tmp = tempfile.mkdtemp(suffix = '.a2server-netboot')
print('You\'ll want to go and delete this directory:')
print(netboot_tmp)
os.chdir(netboot_tmp)
if __name__ == "__main__":
# You commonly see GS/OS 6.0.1 as six floppies for the Apple IIgs, but
# there's actually a seventh HFS-formatted floppy containing AFP network
# boot files the Apple //e and IIgs. We need those.
disk7_file = os.path.join(netboot_tmp, disk7_filename)
download_url(disk7_url, disk7_file)
# The file's wrapped in MacBinary, unar can unwrap it for us
unar = ['unar', '-q', '-k', 'skip', disk7_filename]
ret = subprocess.call(unar)
if ret == 0:
# The actual HFS image is exactly 819200 bytes long and appears after
# the first 84 bytes of the file. Admittedly we're dealing with a lot
# of magic numbers here.
source = 'Disk 7 of 7-Apple II Setup.sea'
a2setup_hdv_name = 'A2SETUP.HDV'
with open(source, 'rb') as src, open(a2setup_hdv_name, 'wb') as dst:
src.seek(84)
dst.write(src.read(819200))
if dst.tell() != 819200:
print('Disk 7 was somehow corrupted')
return False
else:
print('Failed to extract %s: unar returned with error %i' % (disk7_name, ret))
return False
# XXX Re-enable this
#os.rmdir(netboot_tmp)
if __name__ == '__main__':
# bail out on automated netboot setup unless -b is also specified
# FIXME: This logic belongs in a2server-setup, not here
autoAnswerYes = os.path.isfile("/tmp/a2server-autoAnswerYes")
if autoAnswerYes and not os.path.isfile("/tmp/a2server-setupNetBoot"):
autoAnswerYes = os.path.isfile('/tmp/a2server-autoAnswerYes')
if autoAnswerYes and not os.path.isfile('/tmp/a2server-setupNetBoot'):
sys.exit(0)
# We need root to do this. If we don't have it, just rerun the command with
@ -49,16 +97,20 @@ if __name__ == "__main__":
# is as a proof of concept that it can be done this way in the main
# a2server-setup script, which of course means we don't actually need to change
# the password for the user.
#
# XXX Disabling this for development
"""
if os.geteuid() != 0:
args = sys.argv
args.insert(0, 'sudo')
# At the very least, we should print the command line we're running here
print ("Rerunning with sudo...")
print ('Rerunning with sudo...')
ret = subprocess.call(args)
sys.exit(ret)
"""
reply = stdin_input("""
Do you want to set up A2SERVER to be able to boot Apple II
computers over the network? [y] """)
if reply.startswith("y") or reply.startswith("Y") or reply == "":
do_install
if reply.startswith('y') or reply.startswith('Y') or reply == '':
do_install()