SF.net SVN: morphix: [2375] trunk/morphixinstaller2/lib_install.py
[email protected] Sat, 29 Jul 2006 19:13:54 -0700
| Newsgroups | gmane.linux.morphix.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 2375
Author: alextreme
Date: 2006-07-29 19:13:50 -0700 (Sat, 29 Jul 2006)
ViewCVS: http://svn.sourceforge.net/morphix/?rev=2375&view=rev
Log Message:
-----------
* real men do real commits
* basic install functionality should now be complete
Modified Paths:
--------------
trunk/morphixinstaller2/lib_install.py
Modified: trunk/morphixinstaller2/lib_install.py
===================================================================
--- trunk/morphixinstaller2/lib_install.py 2006-07-30 00:51:55 UTC (rev 2374)
+++ trunk/morphixinstaller2/lib_install.py 2006-07-30 02:13:50 UTC (rev 2375)
@@ -6,7 +6,7 @@
self.max_expert_mounts = 4
self.path_mnt_dir = '/mnt'
self.grub_menu_location = '/boot/grub/menu.lst'
- self.grub_dir = '/grub'
+ self.grub_dir = '/boot/grub'
self.proc_cmdline = '/proc/cmdline'
self.proc_partitions = '/proc/partitions'
self.proc_modules = '/proc/modules'
@@ -16,13 +16,20 @@
self.qtparted_path = '/usr/bin/qtparted'
self.gparted_path = '/usr/bin/gparted'
self.parted_path = '/sbin/parted'
+ self.mkinitrd_path = '/usr/sbin/mkinitrd.yaird'
- self.selected_harddisk = None
- self.selected_swap = None
- self.selected_root = None
+ # change usage to using this instead of function arguments
+ self.selected_harddisk = ""
+ self.selected_swap = ""
+ self.selected_root = ""
+ self.root_mountpoint = ""
self.do_debug = 0
+ if not os.access(self.mkinitrd_path, X_OK):
+ print("Error: Unable to find yaird, check your dependancies!")
+
+
def debug(self, string):
if self.do_debug == 1:
print(string)
@@ -137,9 +144,6 @@
self.executeCommand("umount /mnt/" + file)
return True
- def initInstallProcess(self):
- return True
-
def startPartitioner(self, harddisk, command):
self.executeCommand(command + harddisk)
return
@@ -179,10 +183,17 @@
return partitioners
def makeSwap(self, swap_partition):
+ if swap_partition == "" or swap_partition == "none":
+ return True
+
self.executeCommand("mkswap " + swap_partition)
return True
def makeFilesystem(self, partition, filesystem):
+
+ """ Call the appropriate mkfs command for the
+ selected partition and filesystem-type """
+
if filesystem == "ext2":
self.executeCommand("mkfs.ext2 " + partition)
return True
@@ -196,6 +207,9 @@
return False
def makeRoot(self, root_partition, root_mountpoint, filesystem_type = "ext3"):
+ """ Setup the root partition, initialize it using the
+ chosen filesystem type """
+
if root_partition == None:
return False
@@ -219,6 +233,10 @@
return
def executeMinimoduleInstallscripts(self, root_mountpoint):
+
+ """ Execute the /morphix/install.sh scripts in each
+ minimodule, if they exist """
+
minimods = os.listdir("/mnt/mini")
for minimod in minimods:
install_sh = "/mnt/mini/" + minimod + "/morphix/install.sh"
@@ -232,6 +250,9 @@
return True
def mountPartition(self, partition, destination):
+
+ """ Mount the partition, if the destination exists """
+
if not os.access(destination, os.F_OK):
if not os.mkdir(destination, 0755):
return False
@@ -244,6 +265,10 @@
return
def buildRoot(self, root_mountpoint, root_partition, filesystem_type, swap_partition):
+
+ """ The main copy-livecd function, call it to start the
+ installation """
+
self.executeCommand("mkdir -p " + root_mountpoint)
self.mountPartition(root_partition, root_mountpoint)
# TODO: mount extra partitions
@@ -306,32 +331,180 @@
return True
- def copyKernel():
- return
+ # Was copyKernel in MI1
- def setupEtcFiles(hostname):
+ def setupInitrd(self, root_mountpoint):
+
+ """ Create an initrd for booting the current kernel in
+ /boot/initrd.gz """
+
+ mkinitrd_destination = root_mountpoint + "/boot/initrd.gz"
+ kernel_version = self.getKernelVersion()
+
+ self.executeCommand("mkinitrd.yaird -o" + mkinitrd_destination + " " + kernel_version)
+ return True
+
+ def setupEtcFiles(self, root_mountpoint, hostname):
+
+ """ Setup various files in /etc using the given hostname """
+
+ hosts = open(root_mountpoint + "/etc/hosts", "w")
+ if not hosts:
+ return False
+
+ hosts.write("127.0.0.1\t" + hostname + " localhost\n\
+ \
+ # The following lines are desirable for IPv6 capable hosts\n\
+ # (added automatically by netbase upgrade)\n\
+ \
+ ::1 ip6-localhost ip6-loopback\n\
+ fe00::0 ip6-localnet\n\
+ ff00::0 ip6-mcastprefix\n\
+ ff02::1 ip6-allnodes\n\
+ ff02::2 ip6-allrouters\n\
+ ff02::3 ip6-allhosts\n")
+ hosts.close()
+
+ hn = open(root_mountpoint + "/etc/hostname", "w")
+ hn.write(hostname + "\n")
+ hn.close()
+
+ mailname = open(root_mountpoint + "/etc/mailname", "w")
+ mailname.write(hostname + "\n")
+ mailname.close()
+
return
- def setRootPassword(password):
+ def setRootPassword(self, root_mountpoint, password):
+
+ """ Set the root-user password """
+
+ self.executeCommand("chroot " + root_mountpoint + " sh -c \"echo \\\"root:" + password + "\\\" | chpasswd -m \"")
return
- def setupHomeDirectory(username, password):
+ def setupHomeDirectory(self, root_mountpoint, username, password):
+
+ """ Setup the user using the password supplied, add him
+ to a set of default groups """
+
+ user_groups = "dialout,dip,games,cdrom,video,audio,users"
+
+ # Remove morph user
+ self.executeCommand("chroot " + root_mountpoint + " sh -c 'deluser morph'")
+
+ # Add the new user-group
+ self.executeCommand("chroot " + root_mountpoint + " sh -c 'groupadd " + username + "'")
+
+ # Add the new user
+ self.executeCommand('chroot ' + root_mountpoint + ' sh -c \'useradd -m -k /etc/skel -c "Morphix User" -g ' + username + ' -s /bin/bash ' + username + '\'')
+
+ # Set the password
+ self.executeCommand("chroot " + root_mountpoint + " sh -c 'echo \"" + username + ":" + password + "\" | chpasswd -m '")
+
+ # Make really really really sure the users files have the
+ # right permissions
+ self.executeCommand("chroot " + root_mountpoint + " sh -c 'chown -R " + username + "." + username + " /home/" + username + "'")
+
+ # Add user to the various groups set
+ self.executeCommand("chroot " + root_mountpoint + " sh -c 'usernmod -G " + user_groups + " " + username + "'")
return
def getKernelArguments():
- return
- def setupGrub(grub_mode):
- return
+ """ Return a kernel arguments line using the ones entered
+ at livecd-boottime, minus various kernel arguments that
+ might cause problems """
- def setupDMA():\
- return
- def execPreinstallScript():
- return
+ filter = ["BOOT_IMAGE", "ro", "initrd=", "root=", "init=", "screen=", "depth=", "keyboard=", "xvrefresh", "ramdisk_size=", "lang=", "xmodule="]
- def execPostinstallScript():
- return
+ cmdline = self.getContents(self.proc_cmdline)
+ cmdline = cmdline.split()
+ k_args = ""
- def makeGrubBootfloppy():
+ for cmd in cmdline:
+ found = 0
+ for f in filter:
+ if cmd.find(f):
+ found = 1
+
+ if found == 0:
+ k_args += cmd + " "
+
+ return k_args
+
+ def setupGrub(self, root_mountpoint, grub_mode):
+
+ """ Setup grub using the mode chosen:
+ 1 - install into selected-harddisk MBR
+ 2 - install into selected root-partition
+ 3 - skip install of grub
+ 4 - install into selected boot-partition
+ """
+
+ if grub_mode < 1 or grub_mode > 4:
+ self.debug("Warning: Invalid grub mode chosen: " + grub_mode)
+ return False
+
+ if grub_mode == 3:
+ return True
+
+ self.executeCommand("mkdir -p " + root_mountpoint + self.grub_dir)
+ # initrd now used by default
+
+ initrd = "/boot/initrd.gz"
+
+ if grub_mode == 1: # install to MBR
+ self.executeCommand("grub-install --no-floppy --root-directory=" + root_mountpoint + "/ /dev/" + self.selected_harddisk)
+ self.executeCommand("gengrubmenu2 " + root_mountpoint + "/boot/grub /dev/" + self.selected_harddisk + " " + self.selected_root + " \"" + self.getKernelArguments() + "\" /boot/vmlinuz " + initrd)
+
+ if grub_mode == 2: # install to rootpartition
+ self.executeCommand("grub-install --no-floppy --root-directory=" + root_mountpoint + "/ " + self.selected_root)
+ self.executeCommand("gengrubmenu2 " + root_mountpoint + "/boot/grub /dev/" + self.selected_root + " " + self.selected_root + " \"" + self.getKernelArguments() + "\" /boot/vmlinuz " + initrd)
+
+ if grub_mode == 4: #
+ self.executeCommand("grub-install --no-floppy --root-directory=" + root_mountpoint + "/ " + self.selected_boot)
+ self.executeCommand("gengrubmenu2 " + root_mountpoint + "/boot/grub /dev/" + self.selected_boot + " " + self.selected_root + " \"" + self.getKernelArguments() + "\" /boot/vmlinuz " + initrd)
+
+ # grub should now be installed in /boot/grub
+
+ return True
+
+ def setupDMA():
+ # todo?
+ return True
+
+ def execPreinstallScript(self, root_mountpoint):
+
+ """
+ Two scripts are called before the actual install phase:
+ - /morphix/preinst_ext.sh (executed outside the chroot, with first argument being the install directory
+ - /morphix/preinst.sh (executed inside the install directory in a chroot)
+ """
+
+ if os.access("/morphix/preinst_ext.sh", F_OK):
+ self.executeCommand("sh /morphix/preinst_ext.sh " + root_mountpoint)
+ if os.access("/morphix/preinst.sh", F_OK):
+ self.executeCommand("chroot " + root_mountpoint + " sh /morphix/preinst_ext.sh")
+ return True
+
+ def execPostinstallScript(self, root_mountpoint, username):
+ """
+ Two scripts are called after the actual install phase:
+ - /morphix/postinst_ext.sh (executed outside the chroot, with first argument being the username of the created user, second argument being the install directory
+ - /morphix/postinst.sh (executed inside the install directory in a chroot, first argument being the username of the created user)
+ """
+
+ if os.access("/morphix/postinst_ext.sh", F_OK):
+ self.executeCommand("sh /morphix/preinst_ext.sh " + username + " " + root_mountpoint)
+ if os.access("/morphix/postinst.sh", F_OK):
+ self.executeCommand("chroot " + root_mountpoint + " sh /morphix/preinst_ext.sh " + username)
+ return True
+
+ def makeGrubBootfloppy(self):
+
+ """ Does a generic grub install on /dev/fd0 (untested) """
+
+ self.executeCommand("grub-floppy /dev/fd0")
+
return
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV