Revision a1aef659

b/snf-image-host/snf-image-update-helper.in
5 5

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

  
8
if [ ! -e "$HELPER_PKG" ]; then
9
    log_error "Helper package \`$HELPER_PKG' not found."
10
    log_error "You need to provide this for the script to work."
8
list_defaults() {
9
    cat <<EOF
10

  
11
*** DEFAULT HELPER VALUES ***
12

  
13
Helper directory:               $HELPER_DIR
14
Helper cache file:              $HELPER_CACHE_FILE
15
Helper snf-image-helper pkg:    $HELPER_PKG
16

  
17
EOF
18
}
19

  
20
usage() {
21
    local rc="$1"
22

  
23
    cat <<EOF
24

  
25
Usage: $0 [options]
26

  
27
This script runs a debootstrap and creates a small Debian image populated with
28
the snf-image-helper package. This needs to be done before the first use of
29
ganeti's \`snf-image' guest OS type.
30

  
31
OPTIONS:
32
    -c  Overwrite the default cache file
33
    -d  Overwrite the default directory where the helper image will be hosted
34
    -h  Show this message
35
    -l  List default helper values
36
    -p  Overwrite the default snf-image-helper debian package
37
    -y  Automatic yes to prompts and run non-interactively.
38

  
39
EOF
40

  
41
    exit "$rc"
42
}
43

  
44
while getopts "c:d:hlp:y" opt; do
45
    case $opt in
46
        c) HELPER_CACHE_FILE="$OPTARG"
47
            ;;
48
        d) HELPER_DIR="$OPTARG"
49
            ;;
50
        h) usage 0
51
            ;;
52
        l) list_defaults; exit 0
53
            ;;
54
        p) HELPER_PKG="$OPTARG"
55
            ;;
56
        y) NO_PROMPT="yes"
57
            ;;
58
        ?) log_error "Use \`-h' for help"; exit 1
59
            ;;
60
    esac
61
done
62

  
63
echo
64
echo "This is the update helper image script for snf-image."
65
echo "If you don't know what to do, use \`-h'."
66
echo
67

  
68
if [ ! -d "$HELPER_DIR" -o ! -w "$HELPER_DIR" ]; then
69
    log_error "Helper directory \`$HELPER_DIR' does not exist or the script" \
70
    "has no write permission on it."
71
    exit 1
72
fi
73

  
74
if [ ! -r "$HELPER_PKG" ]; then
75
    log_error "Helper package \`$HELPER_PKG' does not exist or is not " \
76
    "readable by the script."
11 77
    exit 1
12 78
fi
13 79

  
14 80
cat >&1 <<EOF
15
This program will overwrite the following files:
81
This program will overwrite the following files if present:
16 82
  \`$HELPER_DIR/initrd'
17 83
  \`$HELPER_DIR/kernel'
18 84
  \`$HELPER_DIR/image'
......
20 86

  
21 87
while [[ 1 ]]; do
22 88
    echo -n "Do you want to continue [y/N]? "
89
    if [ "x$NO_PROMPT" = "xyes" ]; then
90
        echo "y";
91
        break;
92
    fi
93

  
23 94
    read answer
24 95
    [ "$(echo -n "$answer" | tr [A-Z] [a-z])" = "y" ] && break
25 96
    if [ -z "$answer" -o "$(echo -n "$answer" | tr [A-Z] [a-z])" = "n" ]; then
......
75 146
    chmod +x "$target/usr/sbin/policy-rc.d"
76 147

  
77 148
    debootstrap --arch amd64 --include "$HELPER_EXTRA_PKGS" \
78
        --variant=minbase stable "$target" "$HELPER_MIRROR" 2>&1 | sed -e 's/^/DEBOOTSTRAP: /g'
149
        --variant=minbase stable "$target" "$HELPER_MIRROR" 2>&1 | \
150
        sed -e 's/^/DEBOOTSTRAP: /g'
79 151

  
80 152
    rm "$target/usr/sbin/policy-rc.d"
81 153
    
......
84 156
        xargs -r0 rm -f
85 157

  
86 158
    tmp_cache=$(mktemp "$HELPER_CACHE_FILE.XXXXXX")
87
    tar cf "$tmp_cache" --one-file-system -C "$target" . || { rm "$tmp_cache"; false; }
159
    tar cf "$tmp_cache" --one-file-system -C "$target" . || \
160
        { rm "$tmp_cache"; false; }
88 161
    mv -f "$tmp_cache" "$HELPER_CACHE_FILE"
89 162
fi
90 163

  

Also available in: Unified diff