multi-module change - first step towards multi-bootcd's myplc
[myplc.git] / plc.d / bootcd
1 #!/bin/bash
2 #
3 # priority: 1000
4 #
5 # Rebuild the Boot CD
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10 # $Id$
11 #
12
13 # Source function library and configuration
14 . /etc/plc.d/functions
15 . /etc/planetlab/plc_config
16
17 # Be verbose
18 set -x
19
20 case "$1" in
21     start)
22         if [ "$PLC_BOOT_ENABLED" != "1" -a \
23              "$PLC_WWW_ENABLED" != "1" ] ; then
24             exit 0
25         fi
26
27         MESSAGE=$"Rebuilding Boot CD"
28         dialog "$MESSAGE"
29
30         ########## legacy myplcs - temporary code
31         [ -f /etc/planetlab/nodefamily ] || { mkdir -p /etc/planetlab ; echo "planetlab-i386" > /etc/planetlab/nodefamily ; }
32         ########## end
33
34         # get the default nodefamily
35         def_nodefamily=$(cat /etc/planetlab/nodefamily)
36
37         ########## legacy myplcs - temporary code
38         [ -d /usr/share/bootcd ] && mv /usr/share/bootcd /usr/share/bootcd-${def_nodefamily}
39         [ -d /var/www/html/download ] && mv /var/www/html/download /var/www/html/download-${def_nodefamily}
40         ########## end
41
42         
43         # Customize the Boot CD : run build.sh on all available bootcd's
44         shopt -s nullglob
45         for bootcd in /usr/share/bootcd-* ; do
46             name=$(basename $bootcd)
47             nodefamily=$(echo $name | sed -e s,bootcd-,,)
48             download=/var/www/html/download-${nodefamily}
49             [ -d ${download} ] || mkdir -p ${download}
50
51             pushd ${download}
52             ${bootcd}/build.sh ${PLC_BUILD_ALL_BOOTCDS:+-a}
53             check
54             popd
55         
56             # the default: create symlinks to the actual locations
57             if [ "${nodefamily}" == "${def_nodefamily}" ] ; then
58                 rm -rf /var/www/html/download
59                 ln -s /var/www/html/download-${nodefamily} /var/www/html/download
60                 rm -rf /usr/share/bootcd
61                 ln -s /usr/share/bootcd-${nodefamily} /usr/share/bootcd
62             fi
63         done
64
65         result "$MESSAGE"
66         ;;
67 esac
68
69 exit $ERRORS