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
|
#!/usr/bin/python
#
# mk-rescueimage.ppc - builds a rescue image from an existing tree
# which can be converted into a yaboot bootable
# iso and used as a sysadmin rescue image.
#
#
# Usage: mk-rescueimage.ppc <src-tree> <dest-dir> <productname>
#
# the rescue image will be created as <dest-dir>/ppc-rescueimage
#
import os
import sys
import string
def usage():
print "usage: mk-rescueimage.ppc <toplevel> <dest-dir> <productname> [<productpath>]"
sys.exit(0)
if len(sys.argv) < 5:
usage()
sys.exit(1)
if not os.access("%s/ppc" % (sys.argv[2],), os.F_OK):
print "ERROR - Destination directory %s does not contain a ppc directory!" % (sys.argv[2],)
sys.exit(1)
srcdir = sys.argv[1]
destdir = sys.argv[2]+"/ppc-rescueimage"
productname = sys.argv[3]
if len(sys.argv) > 4:
productpath = sys.argv[4]
# clean and create destination directory
os.system("rm -rf %s" % (destdir,))
os.system("mkdir %s" % (destdir,))
# copy documentation
for pat in ["*eula*", "*EULA*", "README*", "RELEASE*", "GPL", "RPM-*"]:
os.system("cp -p %s/%s %s/ 2>/dev/null" % (srcdir, pat, destdir))
# cp yaboot files
os.system("cp -a %s/ppc %s/" % (srcdir, destdir))
os.system("cp -a %s/etc %s/" % (srcdir, destdir))
# cp stage image
os.system("mkdir -p %s/%s/base" % (destdir, productpath))
os.system("cp -a %s/%s/base/stage2.img %s/%s/base" % (srcdir, productpath, destdir, productpath))
for arch in ("ppc32", "ppc64"):
# munge various yaboot configs to have a default of rescue mode
cfgfile = open("%s/ppc/%s/yaboot.conf" % (destdir, arch), "r")
cfglines = cfgfile.readlines()
cfgfile.close()
# backup old one
os.system("cp %s/ppc/%s/yaboot.conf %s/ppc/%s/yaboot.conf.backup" % (destdir, arch, destdir, arch))
cfgfile = open("%s/ppc/%s/yaboot.conf" % (destdir, arch), "w+")
fndit = 0
for l in cfglines:
if string.find(l, "Welcome") != -1:
cfgfile.write(l.replace("installer", "rescue"))
continue
if string.find(l, "default=") != -1:
cfgfile.write("default=rescue\n")
continue
# see if we're into the stanza now
elif string.find(l, "image=") != -1:
fndit = 1
# build up the rescue stanza based on whats in the
# default stanza as we echo it out
rescuestanza = l + " label=rescue\n"
# if we fall through then write it out
cfgfile.write(l)
else:
# we're writing out the matching stanza - if we hit the append
# line put rescue on the end of it, otherwise just echo line
if fndit:
if string.find(l, "read-only") != -1:
rescuestanza = rescuestanza + l + " append=rescue\n"
else:
if not string.find(l, "label=") != -1:
rescuestanza = rescuestanza + l
cfgfile.write(l)
if fndit:
cfgfile.write('\n' + rescuestanza)
cfgfile.close()
if not fndit:
print "Could not find default stanza, did not modify yaboot.conf"
os.system("mv -f %s/ppc/%s/yaboot.conf.backup %s/ppc/%s/yaboot.conf" % (destdir, arch, destdir, arch))
else:
os.system("rm -f %s/ppc/%s/yaboot.conf.backup" % (destdir, arch))
# Modify top level yaboot to indicate rescue CD instead of install CD
#
cfgfile = open("%s/etc/yaboot.conf" % (destdir,), "r")
cfglines = cfgfile.readlines()
cfgfile.close()
cfgfile = open("%s/etc/yaboot.conf" % (destdir,), "w")
origlines = ''
rescuelines = ''
# do some inline replacements of text
for l in cfglines:
if l.find("init-message") != -1:
entry = cfglines.index(l)
cfglines[entry] = cfglines[entry].replace("installer", "rescue")
cfglines[entry] = cfglines[entry].replace("linux32", "rescue32")
continue
if l.find("default=") != -1:
cfglines[cfglines.index(l)] = l.replace("linux", "rescue")
continue
if l.find("image=/ppc/ppc64") != -1:
origlines = cfglines[cfglines.index(l):]
break
# create a big string that is easier to do replacements on
for l in origlines:
rescuelines += l
# Do replacements on the big string
rescuelines = rescuelines.replace("label=linux64", "label=rescue64")
rescuelines = rescuelines.replace("alias=linux", "alias=rescue")
rescuelines = rescuelines.replace("label=linux32", "label=rescue32")
rescuelines = rescuelines.replace("read-only", "read-only\n append=rescue")
for l in cfglines:
cfgfile.write(l)
cfgfile.write('\n' + rescuelines)
|