merge from HEAD
[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 # Marc E. Fiuczynski <mef@cs.princeton.edu>
17 # Copyright (C) 2006-2007 The Trustees of Princeton University
18 #
19 # $Id:$
20 #
21
22 . build.functions
23
24 # These directories are allowed to grow to unspecified size, so they
25 # are stored as symlinks to the /data partition. mkfedora and yum
26 # expect some of them to be real directories, however.
27 datadirs=(
28 /etc/planetlab
29 /root
30 /tmp
31 /usr/tmp
32 /var/tmp
33 /var/log
34 )
35
36 pl_fixdirs devel/root "${datadirs[@]}"
37
38
39 echo "* myplc-devel: Installing base filesystem"
40 mkdir -p devel/root
41 make_chroot devel/root plc_devel_config.xml
42
43 # Install configuration file
44 echo "* myplc-devel: Installing configuration file"
45 install -D -m 444 plc_devel_config.xml devel/data/etc/planetlab/default_config.xml
46 install -D -m 444 plc_config.dtd devel/data/etc/planetlab/plc_config.dtd
47
48 # Install configuration scripts
49 echo "* myplc-devel: Installing configuration scripts"
50 install -D -m 755 plc_config.py devel/root/tmp/plc_config.py
51 chroot devel/root sh -c 'cd /tmp; python plc_config.py build; python plc_config.py install'
52 install -D -m 755 plc-config devel/root/usr/bin/plc-config
53 install -D -m 755 plc-config-tty devel/root/usr/bin/plc-config-tty
54
55 # Install initscripts
56 echo "* myplc-devel: Installing initscripts"
57 find plc.d/functions | cpio -p -d -u devel/root/etc/
58 install -D -m 755 guest.init devel/root/etc/init.d/plc
59 chroot devel/root sh -c 'chkconfig --add plc; chkconfig plc on'
60
61 # Add a build user with the same ID as the current build user, who can
62 # then cross-mount their home directory into the image and build MyPLC
63 # in their home directory.
64 echo "* myplc-devel: Adding build user"
65 uid=${SUDO_UID:-2000}
66 gid=${SUDO_GID:-2000}
67 if ! grep -q "Automated Build" devel/root/etc/passwd ; then
68     chroot devel/root sh -c "groupadd -o -g $gid build; \
69 useradd -o -c 'Automated Build' -u $uid -g $gid -n -d /data/build -M -s /bin/bash build; \
70 exit 0"
71 fi
72
73 # Copy build scripts to build home directory
74 mkdir -p devel/data/build
75 rsync -a $srcdir/build/ devel/data/build/
76
77 # Allow build user to build certain RPMs as root
78 cat >devel/root/etc/sudoers <<EOF
79 root    ALL=(ALL) ALL
80 build   ALL=(root) NOPASSWD: /usr/bin/rpmbuild
81 EOF
82
83 # Move "data" directories out of the installation
84 echo "* myplc-devel: Moving data directories out of the installation"
85 pl_move_dirs devel/root devel/data /data "${datadirs[@]}"
86
87 # Fix permissions on tmp directories
88 pl_fixtmp_permissions devel/data
89
90 # Make image out of directory
91 echo "* myplc-devel: Building loopback image"
92 pl_make_image devel/root devel/root.img 100000000
93
94 exit 0