-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·363 lines (302 loc) · 8.29 KB
/
build.sh
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
echo "Should be root." >&2
exit 1
fi
[ -f config.sh ] && . config.sh
for X in $CLUSTER; do
case "$X" in
mpi)
MPI=y
;;
pvm)
PVM=y
;;
*)
echo "Unrecognised option: CLUSTER $X." >&2
;;
esac
done
for X in $MONITOR; do
case "$X" in
sinfo)
SINFO=y
;;
*)
echo "Unrecognised option: MONITOR $X." >&2
;;
esac
done
packages()
{
echo "Installing packages."
aptitude -q=3 update
CLUSTERING=
[ -n "$MPI" ] && CLUSTERING="$CLUSTERING libopenmpi-dev openmpi-bin openmpi-checkpoint"
[ -n "$PVM" ] && CLUSTERING="$CLUSTERING pvm pvm-dev"
MONITORING=
[ -n "$SINFO" ] && MONITORING="$MONITORING sinfo"
XORG="xorg feh"
case "$WM" in
wmii)
# We'll install wmii itself manually.
;;
"")
unset XORG
;;
*)
XORG="$XORG $WM"
esac
SSH="openssh-client openssh-server"
LIVE="rsync memtest86+ genisoimage grub-pc squashfs-tools live-initramfs live-boot live-config live-config-sysvinit live-boot-initramfs-tools syslinux hwdata"
PXE="dhcp3-server syslinux atftpd nfs-kernel-server"
MISC="build-essential gcc git make wget"
ALL="$CLUSTERING $MONITORING $XORG $SSH $LIVE $PXE $MISC $EXTRAPACKAGES"
aptitude -q=3 -y install $ALL || exit 2
# Only node1 needs this; our cluster script will start them manually.
update-rc.d isc-dhcp-server remove
update-rc.d nfs-kernel-server remove
if [ "$WM" == "wmii" ]; then
# The version of wmii in the Debian repositories is too old to be usable.
# So, let's build our own.
echo "Installing wmii."
if [ ! -f wmii_3.9.2_i386.deb ]; then
if [ ! -d "wmii+ixp-3.9.2" ]; then
wget -O - http://dl.suckless.org/wmii/wmii+ixp-3.9.2.tbz | tar xj
fi
cd wmii+ixp-3.9.2
make deb-dep
make deb
cd ..
fi
dpkg -i wmii_3.9.2_*.deb || exit 2
fi
}
config()
{
[ -z "$NETWORK" ] && NETWORK=192.168.1.0
NETBASE=$(awk -F '.' '{print $1"."$2"."$3}' <<< $NETWORK)
echo "Copying configuration files."
# DHCP
sed "s/DNS/${DNS// /, }/g
s/BROADCAST/$NETBASE.255/g
s/NETWORK/$NETBASE.0/g
s/RANGE/$NETBASE.2 $NETBASE.251/g" conf/dhcpd.conf >/etc/dhcp/dhcpd.conf
# Network interfaces for node1
sed "s/NODE1/$NETBASE.1/" conf/interfaces >/etc/network/interfaces
[ -n "$GATEWAY" ] && echo " gateway $GATEWAY" >>/etc/network/interfaces
# DNS
if [ -n "$DNS" ]; then
cp conf/resolv.conf /etc/resolv.conf
for DNSIP in $DNS; do
echo "nameserver $DNSIP" >>/etc/resolv.conf
done
else
rm /etc/resolv.conf
fi
# PXE
mkdir -p /srv/tftp/pxelinux.cfg
sed "s/NODE1/${NETBASE}.1/" conf/pxelinux.cfg >/srv/tftp/pxelinux.cfg/default
# SSH
cp conf/ssh{,d}_config /etc/ssh/
# NFS
cp conf/exports /etc/exports
# TFTP
cp conf/inetd.conf /etc/inetd.conf
# sinfo
[ -n "$SINFO" ] && sed "s/NETBASE/${NETBASE}/" conf/sinfo >/etc/default/sinfo
}
bling()
{
echo "Updating miscellaneous files."
# issue and motd
BASED_ON=$(printf "%63s" "Based on $(lsb_release -sd)")
sed "s#BASED_ON#$BASED_ON#" misc/issue >/etc/issue
# motd
rm -f /etc/motd
cp misc/motd /etc/motd
}
userdot()
{
PERSON=$(basename $1)
echo "Copying dotfiles for $PERSON."
cp dot/.{bash,vim}rc $1
chown $PERSON $1/.{bash,vim}rc
rm -f $1/.ssh/id_rsa*
su -c "ssh-keygen -q -f $1/.ssh/id_rsa -N ''" $PERSON
cat $1/.ssh/id_rsa.pub >>/etc/ssh/authorized_keys
if [ -n "$WM" ]; then
cp misc/wallpape.png $1/.wallpape.png
sed "s/WM/$WM/" dot/.xinitrc >$1/.xinitrc
cp dot/.Xresources $1
chown $PERSON $1/{.wallpape.png,.xinitrc,.Xresources}
case "$WM" in
wmii)
cp -r dot/.wmii $1
chown -R $PERSON $1/.wmii
;;
*)
;;
esac
fi
[ -n "$MPI" ] && ln -s /etc/cluster/mpi.hosts $1/mpi.hosts
[ -n "$PVM" ] && ln -s /etc/cluster/pvm.hosts $1/pvm.hosts
}
dot()
{
echo "Installing dotfiles."
for USER in $(ls /home); do
userdot /home/$USER
done
userdot /root
}
scripts()
{
echo "Installing cluster scripts and man pages."
cp scripts/cluster.shutdown /usr/bin
[ ! -d "/usr/local/man/man8" ] && mkdir -p /usr/local/man/man8
cp doc/cluster.shutdown.8 /usr/local/man/man8
cp scripts/cluster.update /usr/bin
cp doc/cluster.update.8 /usr/local/man/man8
cp scripts/cluster /etc/init.d/cluster
update-rc.d cluster defaults || exit 4
[ -z "$NETWORK" ] && NETWORK=192.168.1.0
NETBASE=$(awk -F '.' '{print $1"."$2"."$3}' <<< $NETWORK)
[ ! -d "/usr/local/man/man7" ] && mkdir -p /usr/local/man/man7
sed "s/NETBASE/${NETBASE}/g" doc/cluster.7 >/usr/local/man/man7/cluster.7
}
kernel()
{
[ -z "$KERNEL" ] && KERNEL=2.6.32
[ -z "$KERNEL_CONF" ] && KERNEL_CONF=/boot/config-$(uname -r)
[ -z "$AUFS_GIT" ] && AUFS_GIT="http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-2.6.git"
MINOR=${KERNEL/2.6./}
echo "Creating a usable kernel."
echo "First, cloning the aufs repository."
if [ ! -d "aufs2-2.6.git" ]; then
git clone --branch aufs2.1-$MINOR $AUFS_GIT aufs2-2.6.git || exit 3
cd aufs2-2.6.git
else
cd aufs2-2.6.git
echo "Checking out."
git checkout aufs2.1-$MINOR || exit 3
fi
echo "Configuring kernel."
sed '/CONFIG_NFS_FS/d
/CONFIG_NFS_V4/d
/CONFIG_NFSD/d
/CONFIG_NFSD_V4/d
/CONFIG_NFS_COMMON/d
/CONFIG_AUFS_EXPORT/d
/CONFIG_AUFS_FS/d
/CONFIG_EXPORTFS/d' "$KERNEL_CONF" >.config
echo "\
CONFIG_NFS_FS=y
CONFIG_NFS_V4=y
CONFIG_NFSD=y
CONFIG_NFSD_V4=y
CONFIG_NFS_COMMON=y
CONFIG_AUFS_FS=y
CONFIG_AUFS_EXPORT=y
CONFIG_EXPORTFS=y" >>.config
# We don't need specific values for the next two options, but a typical
# kernel conf won't include defaults for them, so to avoid prompting we
# supply them.
grep -q 'AUFS_HNOTIFY' .config || echo "CONFIG_AUFS_HNOTIFY=n" >>.config
grep -q 'AUFS_BR_HFSPLUS' .config || echo "CONFIG_AUFS_BR_HFSPLUS=y" >>.config
make silentoldconfig
echo "Building."
make
echo "Installing."
make modules_install
make headers_install
make install
echo "Thank you for your patience."
cd ..
}
pxe()
{
[ -z "$KERNEL" ] && KERNEL=2.6.31
echo "Setting up PXE."
if [ ! -f "/usr/lib/syslinux/pxelinux.0" ]; then
echo "Couldn't find pxelinux.0! Installing packages first."
packages
fi
cp /usr/lib/syslinux/pxelinux.0 /srv/tftp/pxelinux.0
if [ ! -f "/boot/vmlinuz-$KERNEL" ]; then
echo -n "Couldn't find kernel! Enter path (or blank to build one): "
read KERNELPATH
while [ ! -f "$KERNELPATH" ]; do
if [ -z "$KERNELPATH" ]; then
kernel
KERNELPATH="/boot/vmlinuz-$KERNEL"
else
echo -n "Invalid kernel path! Re-enter: "
read KERNELPATH
fi
done
fi
cp /boot/vmlinuz-$KERNEL /srv/tftp/vmlinuz.img.netboot
sed -i.old 's/BOOT=local/BOOT=nfs/' /etc/initramfs-tools/initramfs.conf
mkinitramfs -o /srv/tftp/initrd.img.netboot $KERNEL
mv /etc/initramfs-tools/initramfs.conf{.old,}
}
iso()
{
echo "Generating ISO."
scripts/remastersys
}
clean()
{
git reset --hard HEAD
}
--help()
{
echo "Usage: $0 [ ACTION... ]"
echo "Actions:"
echo " packages"
echo " config"
echo " bling"
echo " dot"
echo " scripts"
echo " kernel"
echo " pxe"
echo " iso"
echo "Specials:"
echo " localnode1"
echo " allbutkernel"
echo
echo "You almost certainly want to run this without arguments."
}
-h()
{
--help
}
localnode1()
{
packages
config
bling
dot
scripts
pxe
}
allbutkernel()
{
localnode1
iso
}
if [ $# -gt 0 ]; then
for f; do
$f
done
else
packages
config
bling
dot
scripts
kernel
pxe
iso
fi