summaryrefslogtreecommitdiff
path: root/protostar
blob: 8d2a4b0d1341434cb91b7f08f19bb05acb6703bb (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash

set -e
set -u

TMP="${TMP:-/var/tmp}"

DATE=$(date '+%Y-%m-%d-%H%M')
DIST="${DIST:-bok}"
REPO="${REPO:-http://apt.osdyson.org}"

# We will search for usr archive on CD:
USR_IMG=usr.img.$(echo $DATE | md5sum | cut -f1 -d ' ')

ISONAME="${ISONAME:-dyson-${DIST}-${DATE}}.iso"

ROOT="${TMP}/ROOT"
BOOTSTRAPFS="${BOOTSTRAPFS:-dyson/deb}"
ROOT="/$BOOTSTRAPFS"
BOOTARCH="${ROOT}/boot_archive"

# Move files from usr to usr1,
# Create links from usr to usr1.
# E. g.:
# usr_symlink_move usr/bin/bash
#   /usr/bin/bash -> /usr1/bin/bash
# usr_symlink_move usr/lib/devfsadm
#   /usr/lib/devfsadm -> /usr1/lib/devfsadm
usr_symlink_move() {
    f=${1#*/} # NO LEADING SLASH!
    d=$(dirname "$f")
    if [ ! -d "usr1/$d" ]; then
        mkdir -p "usr1/$d"
    fi
    mv -v "usr/$f" "usr1/$f"
    ln -sf "/usr1/$f" "usr/$f"
}

if [ -z "${ROOT}" ] || [ "${ROOT}" = / ]; then
    echo "WTF? Bad root: \`${ROOT}'" >&2
    exit 1
fi

rm -rf "${ROOT}"/*
if zfs list "${BOOTSTRAPFS}@init"; then
    zfs rollback "${BOOTSTRAPFS}@init"
else

echo "Preparing base system (debootstrap)..."
debootstrap \
    --no-check-gpg \
    --exclude=locales,syslogd,gawk,aptitude,aptitude-common,libboost-iostreams1.48.0,libboost-iostreams1.49.0,libcwidget3 \
    --include=python-newt,illumos-grub-eltorito,illumos-kernel,mc,vim-tiny,screen,openssh-client,wget,bzip2,xz-utils,debootstrap,less,file,lynx,bash-completion \
    "${DIST}" \
    "${ROOT}" \
    "${REPO}"
zfs snapshot dyson/deb@init
fi

mkdir "$ROOT/usr/install"
cp -a install DysonInstaller $ROOT/usr/install/

mv $ROOT/var/lib/dpkg $ROOT/usr/dpkg
ln -sf /usr/dpkg $ROOT/var/lib/dpkg

rm -rf "${ROOT}"/var/cache/*
rm -rf "${ROOT}"/etc/cron.*
rm -rf "${ROOT}"/var/log/*
rm -rf "${ROOT}"/usr/share/doc/*

# Remove messages and localized mans:
rm -rf "${ROOT}"/usr/share/locale/*/LC_MESSAGES
rm -rf "${ROOT}"/usr/share/man/*/man[0-9]*


#sed -i '/^PermitRootLogin/ s,no,yes,' /etc/ssh/sshd_config

cat <<VFSTAB > $ROOT/etc/vfstab
#device         device          mount           FS      fsck    mount   mount
#to mount       to fsck         point           type    pass    at boot options
#
/devices/ramdisk:a -            /               ufs     1       no     rw,nologging
fd              -               /dev/fd         fd      -       no      -

VFSTAB

echo "dyson-${DIST}-live" > "${ROOT}/etc/nodename"

# Set root password (just "root"):
echo 'root:root' | chpasswd -R "$ROOT"
echo 'User: root, password: root' >> "${ROOT}/etc/issue"

# Script to find and mount usr.lzma:
sed "s/##USR_IMG##/$USR_IMG/g" "fs-root" > "${ROOT}/lib/svc/method/fs-root"
chmod +x "${ROOT}/lib/svc/method/fs-root"

cat net-physical > "${ROOT}/lib/svc/method/net-physical"
chmod +x "${ROOT}/lib/svc/method/net-physical"

dummy_prog='#!/sbin/sh
exit 0
'
echo "$dummy_prog" > "${ROOT}/lib/svc/method/fs-usr"
echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive"
echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive-update"


echo "Importing manifests..."
rm -f "${ROOT}/etc/svc/repository.db"
# bash or ksh, please:
bash "${ROOT}/lib/svc/method/manifest-import" \
    -f "${ROOT}/etc/svc/repository.db" \
    -d "${ROOT}/lib/svc/manifest"
# Thank you! Bye-bye!
echo "$dummy_prog" > "${ROOT}/lib/svc/method/manifest-import"


mkdir -p "${BOOTARCH}"
mkdir -p "${BOOTARCH}/usr"
mkdir -p "${BOOTARCH}/cdrom"

pushd "${ROOT}"

# Move some critical libs:
march=`dpkg-architecture -qDEB_HOST_MULTIARCH`
mkdir -p lib/$march
for lib in \
    libdiskmgt \
    libexacct \
    libfmevent \
    libidmap \
    libipmi \
    liblzma \
    libpool \
    libproject \
    libsmbios \
    libsunavl \
    libtecla \
    libtopo \
    libxml2 \
    libz \
    libzonecfg \
    ; do
    mv -v -f usr/lib/$march/$lib.so.* lib/$march/ || \
        mv -v -f usr/lib/$lib.so.* lib/$march/
done

# Move usr/sbin to sbin:
find usr/sbin -type l -delete
mv usr/sbin/* sbin/
rm -rf  usr/sbin
ln -sf ../../sbin usr/sbin

# Moving some files from usr to usr1
# and creating symlinks from usr to usr1
usr_symlink_move usr/bin/cat
usr_symlink_move usr/bin/dash
usr_symlink_move usr/bin/grep
usr_symlink_move usr/bin/ln
usr_symlink_move usr/bin/ls
usr_symlink_move usr/bin/rm
usr_symlink_move usr/bin/sh
usr_symlink_move usr/lib/devfsadm
usr_symlink_move usr/lib/fs/hsfs/mount
usr_symlink_move usr/lib/fs/ufs/mount

# usr2 will be packed and stored on CD:
mv usr usr2

# This is usr before usr2 is mounted,
# fs-root will mount usr2 and replace usr -> usr2
ln -sf usr1 usr
ln -sf ../../sbin usr1/sbin

# List here files or directories which
# should be *moved* to boot archive.
# Caution: files from /usr require
# special treating: see above
tar --remove-files -c -f - \
    bin \
    boot/solaris \
    dev \
    devices \
    etc \
    home \
    kernel \
    lib \
    media \
    mnt \
    opt \
    platform \
    proc \
    root \
    run \
    sbin \
    srv \
    system \
    tmp \
    usr \
    usr1 \
    var \
| tar xf - -C "${BOOTARCH}"

# Restore the kernel:
mkdir -p platform/i86pc/kernel/amd64
cp -p "${BOOTARCH}/platform/i86pc/kernel/amd64/unix" \
    platform/i86pc/kernel/amd64/

# Mount point for compressed /usr:
mkdir "${BOOTARCH}/usr2"

popd # Exit from $ROOT


find "${BOOTARCH}" -ls > bootarch.list

echo "Making boot archive..."
sync; sync

size=$(du -s -m "${BOOTARCH}" | cut -f1)
((size+=20)) # +20 MB of free space
dd if=/dev/zero of="${ROOT}/boot/boot_archive" bs=1M count="$size"
lofidev=$(lofiadm -a "${ROOT}/boot/boot_archive")
rlofidev="${lofidev/lofi/rlofi}"
yes | newfs -m 0 "${rlofidev}"
mkdir -p "${ROOT}/boot/boot_archive.mount"
mount "${lofidev}" "${ROOT}/boot/boot_archive.mount"
mv "${BOOTARCH}"/* "${ROOT}/boot/boot_archive.mount"/
umount "${ROOT}/boot/boot_archive.mount"
lofiadm -d "${lofidev}"
rmdir "${BOOTARCH}"
rmdir "${ROOT}/boot/boot_archive.mount"
gzip -9 -f "${ROOT}/boot/boot_archive"

echo "Making usr archive..."
# usr will be mounted from usr.lzma:
genisoimage \
   -o "${ROOT}/${USR_IMG}" \
   -N -l -R -U \
   -allow-multidot \
   -quiet -no-iso-translate -cache-inodes -d -D \
   -V "usr" \
   "${ROOT}/usr2"

rm -rf "${ROOT}/usr2"
lofiadm -C lzma "${ROOT}/${USR_IMG}"


echo "Configuring GRUB..."
cat <<GRUB > "${ROOT}/boot/grub/menu.lst"
default=0
timeout=3
foreground=ffffff
background=215ECA
title Dyson ($DIST) LiveCD, $DATE
    kernel /platform/i86pc/kernel/amd64/unix
    module /boot/boot_archive.gz
title Dyson ($DIST) LiveCD, $DATE - verbose boot
    kernel /platform/i86pc/kernel/amd64/unix -k -m verbose
    module /boot/boot_archive.gz
GRUB

echo "Making final ${ISONAME}..."
genisoimage \
    -o "${ISONAME}" \
    -b boot/grub/stage2_eltorito \
    -c .catalog \
    -no-emul-boot \
    -boot-load-size 4 \
    -boot-info-table \
    -N -l -R -U \
    -allow-multidot \
    -no-iso-translate \
    -cache-inodes \
    -d -D \
    -V "${ISONAME}" \
    "${ROOT}"

ls -lh "${ISONAME}"

exit 0