aboutsummaryrefslogtreecommitdiff
blob: 5f6e86caa008199e089a3edb7b86abe8306464af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""
LiveCD stage2 target, builds upon previous LiveCD stage1 tarball
"""
# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.

import os


from catalyst.support import (normpath, file_locate, CatalystError, cmd,
	read_from_clst, touch)
from catalyst.fileops import ensure_dirs
from catalyst.base.stagebase import StageBase


class livecd_stage2(StageBase):
	"""
	Builder class for a LiveCD stage2 build.
	"""
	def __init__(self,spec,addlargs):
		self.required_values=["boot/kernel"]

		self.valid_values=[]

		self.valid_values.extend(self.required_values)
		self.valid_values.extend(["livecd/cdtar","livecd/empty","livecd/rm",\
			"livecd/unmerge","livecd/iso","livecd/gk_mainargs","livecd/type",\
			"livecd/readme","livecd/motd","livecd/overlay",\
			"livecd/modblacklist","livecd/splash_theme","livecd/rcadd",\
			"livecd/rcdel","livecd/fsscript","livecd/xinitrc",\
			"livecd/root_overlay","livecd/users","portage_overlay",\
			"livecd/fstype","livecd/fsops","livecd/linuxrc","livecd/bootargs",\
			"gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"])

		StageBase.__init__(self,spec,addlargs)
		if "livecd/type" not in self.settings:
			self.settings["livecd/type"] = "generic-livecd"

		file_locate(self.settings, ["cdtar","controller_file"])

	def set_source_path(self):
		self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"].rstrip('/')+".tar.bz2")
		if os.path.isfile(self.settings["source_path"]):
			self.settings["source_path_hash"] = \
				self.settings["hash_map"].generate_hash(
					self.settings["source_path"])
		else:
			self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+'/')
		if not os.path.exists(self.settings["source_path"]):
			raise CatalystError("Source Path: " +
				self.settings["source_path"] + " does not exist.",
					print_traceback=True)

	def set_spec_prefix(self):
		self.settings["spec_prefix"]="livecd"

	def set_target_path(self):
		self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/")
		if "autoresume" in self.settings["options"] \
			and self.resume.is_enabled("setup_target_path"):
				print "Resume point detected, skipping target path setup operation..."
		else:
			# first clean up any existing target stuff
			if os.path.isdir(self.settings["target_path"]):
				cmd("rm -rf "+self.settings["target_path"],
				"Could not remove existing directory: "+self.settings["target_path"],env=self.env)
				self.resume.enable("setup_target_path")
			ensure_dirs(self.settings["target_path"])

	def run_local(self):
		# what modules do we want to blacklist?
		if "livecd/modblacklist" in self.settings:
			try:
				myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a")
			except:
				self.unbind()
				raise CatalystError("Couldn't open " +
					self.settings["chroot_path"] +
					"/etc/modprobe.d/blacklist.conf.",
					print_traceback=True)

			myf.write("\n#Added by Catalyst:")
			# workaround until config.py is using configparser
			if isinstance(self.settings["livecd/modblacklist"], str):
				self.settings["livecd/modblacklist"] = self.settings["livecd/modblacklist"].split()
			for x in self.settings["livecd/modblacklist"]:
				myf.write("\nblacklist "+x)
			myf.close()

	def unpack(self):
		_unpack=True
		display_msg=None

		clst_unpack_hash = self.resume.get("unpack")

		if os.path.isdir(self.settings["source_path"]):
			unpack_cmd="rsync -a --delete "+self.settings["source_path"]+" "+self.settings["chroot_path"]
			display_msg="\nStarting rsync from "+self.settings["source_path"]+"\nto "+\
				self.settings["chroot_path"]+" (This may take some time) ...\n"
			error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed."
			invalid_snapshot=False

		if "autoresume" in self.settings["options"]:
			if os.path.isdir(self.settings["source_path"]) and \
				self.resume.is_enabled("unpack"):
				print "Resume point detected, skipping unpack operation..."
				_unpack=False
			elif "source_path_hash" in self.settings:
				if self.settings["source_path_hash"] != clst_unpack_hash:
					invalid_snapshot=True

		if _unpack:
			self.mount_safety_check()
			if invalid_snapshot:
				print "No Valid Resume point detected, cleaning up  ..."
				self.clear_autoresume()
				self.clear_chroot()

			ensure_dirs(self.settings["chroot_path"]+"/tmp", mode=1777)

			if "pkgcache" in self.settings["options"]:
				ensure_dirs(self.settings["pkgcache_path"], mode=0755)

			if not display_msg:
				raise CatalystError("Could not find appropriate source.\n"
					"Please check the 'source_subpath' "
					"setting in the spec file.",
					print_traceback=True)

			print display_msg
			cmd(unpack_cmd,error_msg,env=self.env)

			if "source_path_hash" in self.settings:
				self.resume.enable("unpack", data=self.settings["source_path_hash"])
			else:
				self.resume.enable("unpack")

	def set_action_sequence(self):
		self.settings["action_sequence"]=["unpack","unpack_snapshot",\
				"config_profile_link","setup_confdir","portage_overlay",\
				"bind","chroot_setup","setup_environment","run_local",\
				"build_kernel"]
		if "fetch" not in self.settings["options"]:
			self.settings["action_sequence"] += ["bootloader","preclean",\
				"livecd_update","root_overlay","fsscript","rcupdate","unmerge",\
				"unbind","remove","empty","target_setup",\
				"setup_overlay","create_iso"]
		self.settings["action_sequence"].append("clear_autoresume")