-
Notifications
You must be signed in to change notification settings - Fork 13
/
create-seed
executable file
·161 lines (149 loc) · 3.76 KB
/
create-seed
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# This is a script to create an initial 'seed' image based on pristine
# sources. User images will be built on top of this one.
#
# Two arguments are required:
#
# * a path to a built smartos-live repository
# * the name of the seed image to create
#
if [ $# -ne 2 ]; then
echo "usage: $0 <smartos-live> <seedname>" >&2
exit 2
else
smartoslive=$1; shift
protoname=$1; shift
fi
imagetoolsdir="$(dirname $0)"
set -ex
zfs destroy zones/${protoname} || true
zfs create zones/${protoname}
#
# Requisite directories and symlinks
#
for dir in /home /root /var/ssh
do
mkdir -p /zones/${protoname}/root${dir}
done
mkdir -p -m 1777 /zones/${protoname}/root/tmp
ln -s ./usr/bin /zones/${protoname}/root/bin
#
# Copy in proto directories
#
for dir in etc var
do
rsync -av ${smartoslive}/proto/${dir} /zones/${protoname}/root/
done
#
# Apply overlays
#
rsync -av ${smartoslive}/overlay/generic/etc/ /zones/${protoname}/root/etc/
#
# Apply manual changes.
#
# - remove legacy rc2.d scripts
# - remove /etc/issue
# - remove SDC-specific root cron
# - remove legacy /bin/i386 usage from /etc/profile
# - remove users which may clash with pkgsrc, and sort.
#
rm -f /zones/${protoname}/root/etc/rc2.d/S*
rm -f /zones/${protoname}/root/etc/issue
rm -f /zones/${protoname}/root/etc/cron.d/crontabs/root
ed /zones/${protoname}/root/etc/profile <<EOF
/bin.i386/
s,/bin/i386,[ \`uname -p\` = \"i386\" ],
w
q
EOF
ed /zones/${protoname}/root/etc/passwd <<EOF
/^lp/d
/^gdm/d
/^mysql/d
/^openldap/d
/^webservd/d
/^postgres/d
w
q
EOF
ed /zones/${protoname}/root/etc/shadow <<EOF
/^lp/d
/^gdm/d
/^mysql/d
/^openldap/d
/^webservd/d
/^postgres/d
w
q
EOF
ed /zones/${protoname}/root/etc/group <<EOF
/^lp/d
/^gdm/d
/^mysql/d
/^openldap/d
/^webservd/d
/^postgres/d
w
q
EOF
for file in group passwd
do
sort -t: -k3,3n /zones/${protoname}/root/etc/${file} >/tmp/${file} \
&& mv /tmp/${file} /zones/${protoname}/root/etc/${file}
done
ed /zones/${protoname}/root/etc/user_attr >/dev/null <<EOF
/^lp/d
/^admin/d
w
q
EOF
#
# Generate SVC repository. Some manifests are missing, apply them manually.
#
${imagetoolsdir}/create-smf-repo ${smartoslive} ${imagetoolsdir}/include/manifests /tmp/repository.db
#svcdir="${smartoslive}/projects/illumos/usr/src/cmd/svc"
#for mf in ${smartoslive}/proto/lib/svc/manifest/system/boot-archive.xml \
# ${smartoslive}/overlay/generic/lib/svc/manifest/system/sysidtool.xml \
#for mf in ${imagetoolsdir}/include/mdata.xml
#do
# env SVCCFG_REPOSITORY=/tmp/repository.db \
# SVCCFG_CONFIGD_PATH=${svcdir}/configd/svc.configd-native \
# ${svcdir}/svccfg/svccfg-native import ${mf}
#done
#
# Import our fake mdata.xml to satisfy SDC 6.5 and 7.0
#
#env SVCCFG_REPOSITORY=/tmp/repository.db \
# SVCCFG_CONFIGD_PATH=${smartoslive}/projects/illumos/usr/src/cmd/svc/configd/svc.configd-native \
# ${smartoslive}/projects/illumos/usr/src/cmd/svc/svccfg/svccfg-native import ${imagetoolsdir}/include/mdata.xml
cp /tmp/repository.db /zones/${protoname}/root/etc/svc/repository.db
#
# Apply mode/permission changes based on the published manifest.
#
while read ftype file mode owner group
do
target="/zones/${protoname}/root/${file}"
case "${ftype}" in
d)
if [ -d ${target} ]; then
chmod ${mode} ${target}
chown ${owner}:${group} ${target}
fi
;;
f)
if [ -f ${target} ]; then
chmod ${mode} ${target}
chown ${owner}:${group} ${target}
fi
;;
esac
done < ${smartoslive}/manifest.gen
#
# Do just enough zoneinit stuff to get a zone to boot, this will be overwritten
# later when we do a proper smtools install.
#
mkdir -p /zones/${protoname}/root/var/zoneinit
cp ${imagetoolsdir}/include/zoneinit.json /zones/${protoname}/root/var/zoneinit
cp ${imagetoolsdir}/include/S99final /zones/${protoname}/root/etc/rc2.d/S99final
chmod 0755 /zones/${protoname}/root/etc/rc2.d/S99final