Change v3 to v4 yumgroups.xml
[myplc.git] / build_devel.sh
1 #!/bin/bash
2 #
3 # Build a complete MyPLC development environment. Requires PlanetLab
4 # source code to be exported into directories at the same level as we
5 # are (i.e., ..).
6 #
7 # devel/root.img (loopback image)
8 # devel/root/ (mount point)
9 # devel/data/ (various data files)
10 # devel/data/cvs/ (local CVS repository)
11 # devel/data/build/ (build area)
12 # devel/data/etc/planetlab/ (configuration)
13 # devel/data/root (root's home dir)
14 #
15 # Mark Huang <mlhuang@cs.princeton.edu>
16 # Copyright (C) 2006 The Trustees of Princeton University
17 #
18 # $Id: build_devel.sh,v 1.7 2007/01/12 14:48:02 mlhuang Exp $
19 #
20
21 . build.functions
22
23 # These directories are allowed to grow to unspecified size, so they
24 # are stored as symlinks to the /data partition. mkfedora and yum
25 # expect some of them to be real directories, however.
26 datadirs=(
27 /etc/planetlab
28 /root
29 /tmp
30 /usr/tmp
31 /var/tmp
32 /var/log
33 )
34 for datadir in "${datadirs[@]}" ; do
35     # If we are being re-run, it may be a symlink
36     if [ -h devel/root/$datadir ] ; then
37         rm -f devel/root/$datadir
38         mkdir -p devel/root/$datadir
39     fi
40 done
41
42 echo "* myplc-devel: Installing base filesystem"
43 mkdir -p devel/root
44 make_chroot devel/root plc_devel_config.xml
45
46 # Install configuration file
47 echo "* myplc-devel: Installing configuration file"
48 install -D -m 444 plc_devel_config.xml devel/data/etc/planetlab/default_config.xml
49 install -D -m 444 plc_config.dtd devel/data/etc/planetlab/plc_config.dtd
50
51 # Install configuration scripts
52 echo "* myplc-devel: Installing configuration scripts"
53 install -D -m 755 plc_config.py devel/root/tmp/plc_config.py
54 chroot devel/root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
55 install -D -m 755 plc-config devel/root/usr/bin/plc-config
56 install -D -m 755 plc-config-tty devel/root/usr/bin/plc-config-tty
57
58 # Install initscripts
59 echo "* myplc-devel: Installing initscripts"
60 find plc.d/functions | cpio -p -d -u devel/root/etc/
61 install -D -m 755 guest.init devel/root/etc/init.d/plc
62 chroot devel/root sh -c 'chkconfig --add plc; chkconfig plc on'
63
64 # Add a build user with the same ID as the current build user, who can
65 # then cross-mount their home directory into the image and build MyPLC
66 # in their home directory.
67 echo "* myplc-devel: Adding build user"
68 uid=${SUDO_UID:-2000}
69 gid=${SUDO_GID:-2000}
70 if ! grep -q "Automated Build" devel/root/etc/passwd ; then
71     chroot devel/root <<EOF
72 groupadd -g $gid build
73 useradd -c "Automated Build" -u $uid -g $gid -n -d /data/build -M -s /bin/bash build
74 EOF
75 fi
76
77 # Copy build scripts to build home directory
78 mkdir -p devel/data/build
79 rsync -a $srcdir/build/ devel/data/build/
80
81 # Allow build user to build certain RPMs as root
82 cat >devel/root/etc/sudoers <<EOF
83 root    ALL=(ALL) ALL
84 build   ALL=(root) NOPASSWD: /usr/bin/rpmbuild
85 EOF
86
87 # Move "data" directories out of the installation
88 echo "* myplc-devel: Moving data directories out of the installation"
89 move_datadirs devel/root devel/data "${datadirs[@]}"
90
91 # Fix permissions on tmp directories
92 chmod 1777 devel/data/tmp devel/data/usr/tmp devel/data/var/tmp
93
94 # Make image out of directory
95 echo "* myplc-devel: Building loopback image"
96 make_image devel/root devel/root.img
97
98 exit 0