+ added to branch.
[bootcd.git] / newbuild.sh
1 #!/bin/bash
2 #
3 # Builds custom BootCD ISO and USB images in the current
4 # directory.
5 #
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
8 #
9 # $Id: newbuild.sh,v 1.2 2006/12/04 20:07:18 mlhuang Exp $
10 #
11
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
13
14 BOOTCD_VERSION=4.0
15
16 if [ -f /etc/planetlab/plc_config ] ; then
17     # Source PLC configuration
18     . /etc/planetlab/plc_config
19 else
20     echo "Could not find /etc/planetlab/plc_config."
21     echo "This file defines the configuration of your PlanetLab installation."
22     exit 1
23 fi
24
25 # This support for backwards compatibility can be taken out in the
26 # future. RC1 based MyPLCs set $PLC_BOOT_SSL_CRT in the plc_config
27 # file, but >=RC2 based bootcd assumes that $PLC_BOOT_CA_SSL_CRT is
28 # set.
29 if [ -z "$PLC_BOOT_CA_SSL_CRT" -a ! -z "$PLC_BOOT_SSL_CRT" ] ; then
30     PLC_BOOT_CA_SSL_CRT=$PLC_BOOT_SSL_CRT
31     PLC_API_CA_SSL_CRT=$PLC_API_SSL_CRT
32 fi
33
34 output="$PLC_NAME-BootCD-$BOOTCD_VERSION.iso"
35
36 usage()
37 {
38     echo "Usage: build.sh [OPTION]..."
39     eceho "     -o file         Output file (default: $output)"
40     echo "      -h              This message"
41     exit 1
42 }
43
44 # Get options
45 while getopts "o:h" opt ; do
46     case $opt in
47         o)
48             output=$OPTARG
49             ;;
50         h|*)
51             usage
52             ;;
53     esac
54 done
55
56 FULL_VERSION_STRING="$PLC_NAME BootCD $BOOTCD_VERSION"
57 echo "* Building image for $FULL_VERSION_STRING"
58
59 # Do not tolerate errors
60 set -e
61
62 # Change to our source directory
63 srcdir=$(cd $(dirname $0) && pwd -P)
64 pushd $srcdir >/dev/null
65
66 # Root of the isofs
67 isofs=$PWD/isofs
68
69 # Miscellaneous files
70 misc=$(mktemp -d /tmp/misc.XXXXXX)
71 trap "rm -rf $misc" ERR INT
72
73 # initramfs requires that /init be present
74 ln -sf /sbin/init $misc/init
75
76 # Create version file
77 echo "$FULL_VERSION_STRING" >$misc/.bootcd
78
79 # Install GPG, boot, and API server public keys and certificates
80 install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $misc/$PLC_ROOT_GPG_KEY_PUB
81 install -D -m 644 $PLC_BOOT_CA_SSL_CRT $misc/$PLC_BOOT_CA_SSL_CRT
82 install -D -m 644 $PLC_API_CA_SSL_CRT $misc/$PLC_API_CA_SSL_CRT
83
84 cat > $misc/etc/planetlab/plc_config <<EOF
85 PLC_ROOT_GPG_KEY_PUB='$PLC_ROOT_GPG_KEY_PUB'
86
87 PLC_BOOT_HOST='$PLC_BOOT_HOST'
88 PLC_BOOT_IP='$PLC_BOOT_IP'
89 PLC_BOOT_PORT=$PLC_BOOT_PORT
90 PLC_BOOT_SSL_PORT=$PLC_BOOT_SSL_PORT
91 PLC_BOOT_CA_SSL_CRT='$PLC_BOOT_CA_SSL_CRT'
92
93 PLC_API_HOST='$PLC_API_HOST'
94 PLC_API_IP='$PLC_API_IP'
95 PLC_API_PORT=$PLC_API_PORT
96 PLC_API_PATH='$PLC_API_PATH'
97 PLC_API_CA_SSL_CRT='$PLC_API_CA_SSL_CRT'
98 EOF
99
100 # Generate /etc/issue
101 if [ "$PLC_WWW_PORT" = "443" ] ; then
102     PLC_WWW_URL="https://$PLC_WWW_HOST/"
103 elif [ "$PLC_WWW_PORT" != "80" ] ; then
104     PLC_WWW_URL="http://$PLC_WWW_HOST:$PLC_WWW_PORT/"
105 else
106     PLC_WWW_URL="http://$PLC_WWW_HOST/"
107 fi
108
109 mkdir -p $misc/etc
110 cat >$misc/etc/issue <<EOF
111 $FULL_VERSION_STRING
112 $PLC_NAME Node: \n
113 Kernel \r on an \m
114 $PLC_WWW_URL
115
116 This machine is a node in the $PLC_NAME distributed network.  It has
117 not fully booted yet. If you have cancelled the boot process at the
118 request of $PLC_NAME Support, please follow the instructions provided
119 to you. Otherwise, please contact $PLC_MAIL_SUPPORT_ADDRESS.
120
121 Console login at this point is restricted to root. Provide the root
122 password of the default $PLC_NAME Central administrator account at the
123 time that this CD was created.
124
125 EOF
126
127 # Pack miscellaneous files into a compressed archive
128 echo "* Compressing miscellaneous files image"
129 (cd $misc && find . | cpio --quiet -H newc -o) | \
130     python ../filesystem/cpiochown.py --owner root:root - | \
131     gzip -9 >$isofs/misc.img
132
133 rm -rf $misc
134 trap - ERR INT
135
136 # Calculate ramdisk size (total uncompressed size of all initrds)
137 ramdisk_size=$(gzip -l $isofs/*.img | tail -1 | awk '{ print $2; }') # bytes
138 ramdisk_size=$((($ramdisk_size + 1023) / 1024)) # kilobytes
139
140 # Write isolinux configuration
141 echo "$FULL_VERSION_STRING" >$isofs/version
142 cat >$isofs/isolinux.cfg <<EOF
143 DEFAULT kernel
144 APPEND ramdisk_size=$ramdisk_size initrd=base.img,bootcd.img,misc.img root=/dev/ram0 rw console=tty0
145 DISPLAY version
146 PROMPT 0
147 TIMEOUT 40
148 EOF
149
150 popd >/dev/null
151
152 # Create ISO image
153 echo "* Creating ISO image"
154 mkisofs -o "$output" \
155     -R -allow-leading-dots -J -r \
156     -b isolinux.bin -c boot.cat \
157     -no-emul-boot -boot-load-size 4 -boot-info-table \
158     $isofs
159
160 # XXX Create USB image
161
162 exit 0