eb2c18f046d7315e2a6c73ef4d6e25bef27763a7
[bootmanager.git] / source / steps / InstallInit.py
1 # Copyright (c) 2003 Intel Corporation
2 # All rights reserved.
3
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7
8 #     * Redistributions of source code must retain the above copyright
9 #       notice, this list of conditions and the following disclaimer.
10
11 #     * Redistributions in binary form must reproduce the above
12 #       copyright notice, this list of conditions and the following
13 #       disclaimer in the documentation and/or other materials provided
14 #       with the distribution.
15
16 #     * Neither the name of the Intel Corporation nor the names of its
17 #       contributors may be used to endorse or promote products derived
18 #       from this software without specific prior written permission.
19
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 # EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
33 # YOUR JURISDICTION. It is licensee's responsibility to comply with any
34 # export regulations applicable in licensee's jurisdiction. Under
35 # CURRENT (May 2000) U.S. export regulations this software is eligible
36 # for export from the U.S. and can be downloaded by or otherwise
37 # exported or reexported worldwide EXCEPT to U.S. embargoed destinations
38 # which include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
39 # Afghanistan and any other country to which the U.S. has embargoed
40 # goods and services.
41
42
43
44 import os, sys, shutil
45 import string
46
47 import utils
48
49
50 def Run( vars, log ):
51     """
52     Setup the install environment:
53     - unmount anything in the temp/sysimg path (possible from previous
54       aborted installs
55     - create temp directories
56     
57     Expect the following variables from the store:
58     TEMP_PATH         the path to download and store temp files to
59     SYSIMG_DIR        the directory name of the system image
60                       contained in TEMP_PATH
61     PLCONF_DIR        The directory to store the configuration file in
62     
63     Sets the following variables:
64     SYSIMG_PATH    the directory where the system image will be mounted,
65                    (= TEMP_PATH/SYSIMG_DIR)
66     """
67
68     log.write( "\n\nStep: Install: Initializing.\n" )
69     
70     # make sure we have the variables we need
71     try:
72         TEMP_PATH= vars["TEMP_PATH"]
73         if TEMP_PATH == "":
74             raise ValueError("TEMP_PATH")
75
76         SYSIMG_PATH= vars["SYSIMG_PATH"]
77         if SYSIMG_PATH == "":
78             raise ValueError("SYSIMG_PATH")
79
80         PLCONF_DIR= vars["PLCONF_DIR"]
81         if PLCONF_DIR == "":
82             raise ValueError, "PLCONF_DIR"
83
84     except KeyError, var:
85         raise BootManagerException, "Missing variable in vars: %s\n" % var
86     except ValueError, var:
87         raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
88
89     # if this is a fresh install, then nothing should be
90     # here, but we support restarted installs without rebooting
91     # so who knows what the current state is
92
93     log.write( "Unmounting any previous mounts\n" )
94
95     try:
96         # backwards compat, though, we should never hit this case post PL 3.2
97         os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
98         utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
99     except OSError, e:
100         pass
101
102     utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH, log )
103     utils.sysexec_noerr( "umount %s/mnt/cdrom" % SYSIMG_PATH, log )
104     utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
105     utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
106     
107     log.write( "Removing any old files, directories\n" )
108     utils.removedir( TEMP_PATH )
109     
110     log.write( "Cleaning up any existing PlanetLab config files\n" )
111     utils.removedir( PLCONF_DIR )
112     
113     # create the temp path and sysimg path. since sysimg
114     # path is in temp path, both are created here
115     log.write( "Creating system image path\n" )
116     utils.makedirs( SYSIMG_PATH )
117
118     return 1