Fixed spacing/tabs. Updated catalyst.conf comments. Added autoresume, md5, and...
[catalyst.git] / modules / livecd_stage2_target.py
1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo/src/catalyst/modules/livecd_stage2_target.py,v 1.52 2005/12/02 17:05:56 wolf31o2 Exp $
4
5 """
6 Builder class for a LiveCD stage2 build.
7 """
8
9 import os,string,types,stat,shutil
10 from catalyst_support import *
11 from generic_stage_target import *
12
13 class livecd_stage2_target(generic_stage_target):
14         def __init__(self,spec,addlargs):
15                 self.required_values=["boot/kernel"]
16                 
17                 self.valid_values=[]
18                 
19                 self.valid_values.extend(self.required_values)
20                 self.valid_values.extend(["livecd/cdtar","livecd/empty","livecd/rm",\
21                         "livecd/unmerge","livecd/iso","livecd/gk_mainargs","livecd/type",\
22                         "livecd/readme","livecd/motd","livecd/overlay",\
23                         "livecd/modblacklist","livecd/splash_theme","livecd/splash_type",\
24                         "livecd/rcadd","livecd/rcdel","livecd/fsscript","livecd/xinitrc",\
25                         "livecd/root_overlay","livecd/devmanager","livecd/users",\
26                         "gamecd/conf","livecd/users","portage_overlay","livecd/cdfstype",\
27                         "livecd/linuxrc","livecd/bootargs","gamecd/conf","livecd/xdm",\
28                         "livecd/xsession"])
29                 
30                 generic_stage_target.__init__(self,spec,addlargs)
31                 if not self.settings.has_key("livecd/type"):
32                         self.settings["livecd/type"] = "generic-livecd"
33
34                 file_locate(self.settings, ["cdtar","controller_file"])
35         
36         def set_source_path(self):
37                 self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
38                 if os.path.isfile(self.settings["source_path"]):
39                 self.settings["source_path_md5sum"]=calc_md5(self.settings["source_path"])
40                 else:
41                 self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/")
42                 if not os.path.exists(self.settings["source_path"]):
43                         raise CatalystError,"Source Path: "+self.settings["source_path"]+" does not exist."
44         
45         def set_spec_prefix(self):
46                 self.settings["spec_prefix"]="livecd"
47
48         def set_target_path(self):
49                 self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
50                 if self.settings.has_key("AUTORESUME") \
51                         and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"):
52                                 print "Resume point detected, skipping target path setup operation..."
53                 else:
54                         # first clean up any existing target stuff
55                         if os.path.isdir(self.settings["target_path"]):
56                                 cmd("rm -rf "+self.settings["target_path"],
57                                 "Could not remove existing directory: "+self.settings["target_path"])
58                                 touch(self.settings["autoresume_path"]+"setup_target_path")
59                         if not os.path.exists(self.settings["target_path"]):
60                                 os.makedirs(self.settings["target_path"])
61
62         def run_local(self):
63                 # what modules do we want to blacklist?
64                 if self.settings.has_key("livecd/modblacklist"):
65                         try:
66                                 myf=open(self.settings["chroot_path"]+"/etc/hotplug/blacklist","a")
67                         except:
68                                 self.unbind()
69                                 raise CatalystError,"Couldn't open "+self.settings["chroot_path"]+"/etc/hotplug/blacklist."
70                         myf.write("\n#Added by Catalyst:")
71                         for x in self.settings["livecd/modblacklist"]:
72                                 myf.write("\n"+x)
73                         myf.close()
74                 def unpack(self):
75                                 unpack=True
76
77                                 clst_unpack_md5sum=read_from_clst(self.settings["autoresume_path"]+"unpack")
78
79                                 if os.path.isdir(self.settings["source_path"]):
80                                                 unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"]
81                                                 display_msg="\nStarting rsync from "+self.settings["source_path"]+"\nto "+\
82                                                                 self.settings["chroot_path"]+" (This may take some time) ...\n"
83                                                 error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed."
84                                                 invalid_snapshot=False
85
86                                 if self.settings.has_key("AUTORESUME"):
87                                         if os.path.isdir(self.settings["source_path"]) and \
88                                                         os.path.exists(self.settings["autoresume_path"]+"unpack"):
89                                                                 print "Resume point detected, skipping unpack operation..."
90                                                                 unpack=False
91                                         elif self.settings.has_key("source_path_md5sum"):
92                                                 if self.settings["source_path_md5sum"] != clst_unpack_md5sum:
93                                                                 invalid_snapshot=True
94
95                                 if unpack:
96                                                 self.mount_safety_check()
97
98                                                 if invalid_snapshot:
99                                                                 print "No Valid Resume point detected, cleaning up  ..."
100                                                                 #os.remove(self.settings["autoresume_path"]+"dir_setup")
101                                                                 self.clear_autoresume()
102                                                                 self.clear_chroot()
103                                                                 #self.dir_setup()
104
105                                                 if not os.path.exists(self.settings["chroot_path"]):
106                                                                 os.makedirs(self.settings["chroot_path"])
107
108                                                 if not os.path.exists(self.settings["chroot_path"]+"/tmp"):
109                                                                 os.makedirs(self.settings["chroot_path"]+"/tmp",1777)
110
111                                                 if self.settings.has_key("PKGCACHE"):
112                                                                 if not os.path.exists(self.settings["pkgcache_path"]):
113                                                                                 os.makedirs(self.settings["pkgcache_path"],0755)
114
115                                                 print display_msg
116                                                 cmd(unpack_cmd,error_msg)
117
118                                                 if self.settings.has_key("source_path_md5sum"):
119                                                                 myf=open(self.settings["autoresume_path"]+"unpack","w")
120                                                                 myf.write(self.settings["source_path_md5sum"])
121                                                                 myf.close()
122                                                 else:
123                                                                 touch(self.settings["autoresume_path"]+"unpack")
124
125
126         def set_action_sequence(self):
127                 self.settings["action_sequence"]=["unpack","unpack_snapshot",\
128                                 "config_profile_link","setup_confdir","portage_overlay",\
129                                 "bind","chroot_setup","setup_environment","run_local",\
130                                 "build_kernel","bootloader","preclean","livecd_update",
131                                 "root_overlay","fsscript","rcupdate","unmerge",\
132                                 "unbind","remove","empty","target_setup",\
133                                 "setup_overlay","create_iso","clear_autoresume"]
134
135 def register(foo):
136         foo.update({"livecd-stage2":livecd_stage2_target})
137         return foo