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