svn:keywords
[bootmanager.git] / source / steps / InstallInit.py
1 #!/usr/bin/python
2 #
3 # $Id$
4 # $URL$
5 #
6 # Copyright (c) 2003 Intel Corporation
7 # All rights reserved.
8 #
9 # Copyright (c) 2004-2006 The Trustees of Princeton University
10 # All rights reserved.
11 # expected /proc/partitions format
12
13 import os, sys, string
14
15 import utils
16 from Exceptions import *
17
18 def Run( vars, log ):
19     """
20     Setup the install environment:
21     - unmount anything in the temp/sysimg path (possible from previous
22       aborted installs
23     - create temp directories
24     
25     Expect the following variables from the store:
26     TEMP_PATH         the path to download and store temp files to
27     SYSIMG_DIR        the directory name of the system image
28                       contained in TEMP_PATH
29     PLCONF_DIR        The directory to store the configuration file in
30     
31     Sets the following variables:
32     SYSIMG_PATH       the directory where the system image will be mounted,
33                       (= TEMP_PATH/SYSIMG_DIR)
34     """
35
36     log.write( "\n\nStep: Install: Initializing.\n" )
37     
38     # make sure we have the variables we need
39     try:
40         TEMP_PATH= vars["TEMP_PATH"]
41         if TEMP_PATH == "":
42             raise ValueError("TEMP_PATH")
43
44         SYSIMG_PATH= vars["SYSIMG_PATH"]
45         if SYSIMG_PATH == "":
46             raise ValueError("SYSIMG_PATH")
47
48         PLCONF_DIR= vars["PLCONF_DIR"]
49         if PLCONF_DIR == "":
50             raise ValueError, "PLCONF_DIR"
51
52     except KeyError, var:
53         raise BootManagerException, "Missing variable in vars: %s\n" % var
54     except ValueError, var:
55         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
56
57     # if this is a fresh install, then nothing should be
58     # here, but we support restarted installs without rebooting
59     # so who knows what the current state is
60
61     log.write( "Unmounting any previous mounts\n" )
62
63     try:
64         # backwards compat, though, we should never hit this case post PL 3.2
65         os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
66         utils.sysexec_chroot_noerr( SYSIMG_PATH, "umount /rcfs", log )
67     except OSError, e:
68         pass
69
70     utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH )
71     utils.sysexec_noerr( "umount %s/mnt/cdrom" % SYSIMG_PATH )
72     utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH )
73     utils.sysexec_noerr( "umount %s" % SYSIMG_PATH )
74     vars['ROOT_MOUNTED']= 0
75
76 #    log.write( "Removing any old files, directories\n" )
77 #    utils.removedir( TEMP_PATH )
78     
79     log.write( "Cleaning up any existing PlanetLab config files\n" )
80     try:
81         flist = os.listdir( PLCONF_DIR)
82         for file in flist:
83             utils.removedir( file )
84     except OSError:
85         pass
86     
87     # create the temp path and sysimg path. since sysimg
88     # path is in temp path, both are created here
89     log.write( "Creating system image path\n" )
90     utils.makedirs( SYSIMG_PATH )
91
92     return 1