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