Setting tag MyPLC-4.3-31
[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         # create /etc/planetlab/nodefamily if missing
32         [ -f /etc/planetlab/nodefamily ] || { mkdir -p /etc/planetlab ; echo "planetlab-i386" > /etc/planetlab/nodefamily ; }
33         # move if plain directories
34         for legacydir in /usr/share/bootcd /var/www/html/download ; do
35             if [ -d "${legacydir}" ] && [ ! -h ${legacydir} ] ; then
36                 rm -rf ${legacydir}-legacy
37                 mv -f ${legacydir} ${legacydir}-legacy
38             fi
39         done
40         ########## end
41
42         # get the default nodefamily
43         def_nodefamily=$(cat /etc/planetlab/nodefamily)
44         
45         # Customize the Boot CD : run build.sh on all available bootcd's
46         shopt -s nullglob
47         for bootcd in /usr/share/bootcd-* ; do
48             name=$(basename $bootcd)
49             nodefamily=$(echo $name | sed -e s,bootcd-,,)
50             download=/var/www/html/download-${nodefamily}
51             [ -d ${download} ] || mkdir -p ${download}
52
53             pushd ${download}
54             ${bootcd}/build.sh ${PLC_BUILD_ALL_BOOTCDS:+-a}
55             check
56             popd
57         
58             # the default: create symlinks to the actual locations
59             if [ "${nodefamily}" == "${def_nodefamily}" ] ; then
60                 rm -rf /usr/share/bootcd
61                 ln -s /usr/share/bootcd-${nodefamily} /usr/share/bootcd
62                 rm -rf /var/www/html/download
63                 ln -s /var/www/html/download-${nodefamily} /var/www/html/download
64             fi
65         done
66
67         result "$MESSAGE"
68         ;;
69 esac
70
71 exit $ERRORS