Revision 52ac594c

b/snf-image-host/defaults
26 26
# HELPER_KERNEL: Path to the helper VM kernel
27 27
# HELPER_KERNEL="$(HELPER_DIR)/kernel"
28 28

  
29
# HELPER_PKG: Path to the snf-image-helper package
30
# HELPER_PKG="$(HELPER_DIR)/snf-image-helper.deb"
31

  
32 29
# HELPER_INITRD: Path to the helper VM initial ramdisk
33 30
# HELPER_INITRD="$(HELPER_DIR)/initrd"
34 31

  
32
# HELPER_PKG: Path to the snf-image-helper package
33
# HELPER_PKG="$(HELPER_DIR)/snf-image-helper.deb"
34

  
35 35
# HELPER_TIMOUT: Soft and hard timeout limits for helper instance.
36 36
# Helper instance will be terminated after a given time if it hasn't exited by
37 37
# itself. The time to wait before killing the process is specified by those
b/snf-image-host/snf-image-update-helper.in
1 1
#!/bin/bash
2 2

  
3 3
set -e
4
set -x
5 4

  
6 5
. @osdir@/common.sh
7 6

  
8 7
CACHE_FILE="$HELPER_DIR/cache.tar"
9 8
ARCH=amd64
10
EXTRA_PKGS="linux-image-amd64,e2fsprogs,ntfs-3g,xmlstarlet"
9
EXTRA_PKGS="linux-image-amd64,e2fsprogs,ntfs-3g,ntfsprogs,xmlstarlet,python"
11 10

  
11
if [ ! -e "$HELPER_PKG" ]; then
12
    log_error "Helper package \`$HELPER_PKG' not found."
13
    log_error "You need to provide this for the script to work"
14
    exit 1
15
fi
16
cat >&1 <<EOF
17
This program will overwrite the following files:
18
  \`$HELPER_DIR/initrd'
19
  \`$HELPER_DIR/kernel'
20
  \`$HELPER_DIR/image'
21
EOF
22

  
23
while [[ 1 ]]; do
24
    echo -n "Do you want to continue [y/N]?"
25
    read answer
26
    [ "$(echo -n "$answer" | tr [A-Z] [a-z])" = "y" ] && break
27
    if [ -z "$answer" -o "$(echo -n "$answer" | tr [A-Z] [a-z])" = "n" ]; then
28
        log_error "Abord."
29
        exit 1
30
    fi
31
done
32

  
33
rm -f "$HELPER_DIR/initrd" "$HELPER_DIR/kernel" "$HELPER_DIR/image"
34

  
35
echo -n "Allocating space for helper disk image..."
12 36
helper_img=$(mktemp $HELPER_DIR/image.XXXXXXXX)
13 37

  
14
dd if=/dev/zero of=$helper_img bs=1k count=400000
38
dd if=/dev/zero of=$helper_img bs=1k count=400000 &> /dev/null
39
echo "done"
40

  
15 41
blockdev=$(losetup -sf $helper_img)
16 42
CLEANUP+=("losetup -d $blockdev")
17 43

  
44
sleep 1 # sometimes losetup returns and the device is still busy..
45

  
46
echo -n "Creating partitions..."
18 47
format_disk0 $blockdev "extdump"
48
echo "done"
19 49

  
20 50
root_dev=$(map_disk0 $blockdev)-1
21 51
CLEANUP+=("unmap_disk0 $blockdev")
......
28 58
mount $root_dev $TMPDIR
29 59
CLEANUP+=("umount $root_dev")
30 60

  
61
echo "Checking for cached root filesystem file \`$CACHE_FILE'..." 
31 62
if [  -f "$CACHE_FILE" ]; then
63
    echo "found"
32 64
    tar xf "$CACHE_FILE" -C $TMPDIR
33 65
else
66
    echo "not found"
67
    echo "Debootstraping to create a new root filesystem:"
34 68
    debootstrap --arch "$ARCH" --include $EXTRA_PKGS --variant=minbase \
35 69
	    squeeze $TMPDIR
36 70

  
......
43 77
    mv -f "$TMP_CACHE" "$CACHE_FILE"
44 78
fi
45 79

  
80
echo -n "Configureing filesystem..."
46 81
echo helper > $TMPDIR/etc/hostname
47 82

  
48 83
cat > $TMPDIR/etc/fstab <<EOF
......
52 87
/dev/sda1         /               ext3    defaults        0       1
53 88
proc              /proc           proc    defaults        0       0
54 89
EOF
90
echo "done"
55 91

  
92
echo -n "Extracting kernel..."
56 93
if [ ! -L "$TMPDIR/vmlinuz" -o ! -L "$TMPDIR/vmlinuz" ]; then
57 94

  
58 95
	log_error "vmlinuz or initrd.img link in root is missing."
59 96
	log_error "I don't know how to find a usable kernel/initrd pair."
60 97
	exit 1
61 98
fi
99
echo "done"
62 100

  
63 101
kernel=$(readlink -en $TMPDIR/vmlinuz)
64 102
initrd=$(readlink -en $TMPDIR/initrd.img)
......
73 111

  
74 112
rm $TMPDIR/vmlinuz $TMPDIR/initrd.img
75 113

  
114
echo "Installing snf-image-helper pkg in the new image..."
115
cp $HELPER_PKG $TMPDIR/tmp/
116
pkg_name=$(basename "$HELPER_PKG")  
117
CLEANUP+=("rm $TMPDIR/tmp/$pkg_name")
118
chroot ${TMPDIR} dpkg -i /tmp/$pkg_name
119
echo "done"
120

  
76 121
cleanup
77 122

  
78 123
mv $helper_img $HELPER_DIR/image

Also available in: Unified diff