2aa522cc4a9e93c5e4d7c16808ae492226f9f977
[vserver-reference.git] / initscripts / lxc-sliceimage
1 #!/bin/bash
2 # chkconfig: 345 20 80
3 # description: Create BTRFS subvolumes for LXC reference images.
4 #
5
6 # not needed -- Source function library
7 #. /etc/init.d/functions
8
9 # This is where sliceimage(s) store their reference images
10 sliceimage_dir=/vservers/.vref
11 lxc_dir=/vservers/.lvref
12
13 # Check if we are in the build environment
14 function check_node () {
15     mount | grep -q 'planetlab-vservers' || exit 0
16     [ -d $sliceimage_dir ] || { echo "No sliceimage installed" ; exit 1; }
17 }
18
19 function start () {
20
21     check_node
22     
23     mkdir -p $lxc_dir
24
25     slicefamilies=$(cd $sliceimage_dir ; ls )
26
27     for slicefamily in $slicefamilies; do
28         # initialize if needed
29         [ -d $lxc_dir/$slicefamily ] || btrfs subvolume create $lxc_dir/$slicefamily
30         # xxx what is that ?
31         #btrfs subvolume create $lxc_dir/lxc-squeeze-x86_64
32         # copy the slice image into the btrfs ?
33         rsync -av --delete $sliceimage_dir/$slicefamily/ $lxc_dir/$slicefamily/
34     done
35 }
36
37 function status () {
38     echo -n "Checking node .. "
39     check_node
40     echo OK
41     echo "From installed sliceimage variants"
42     ls $sliceimage_dir
43     echo "Exported to lxc"
44     ls $lxc_dir
45 }
46
47 case "$1" in
48     start|restart|reload)       start ; exit 0 ;;
49     status)                     status ; exit 0 ;;
50     stop)                       exit 0 ;;
51     *)  echo $"Usage: $0 {start|stop|status}"
52         exit 1
53         ;;
54 esac
55