Statistics
| Branch: | Tag: | Revision:

root / snf-image-helper / tasks / 50EnforcePersonality.in @ 6d789991

History | View | Annotate | Download (1.4 kB)

1
#! /bin/bash
2

    
3
### BEGIN TASK INFO
4
# Provides:		EnforcePersonality
5
# RunBefore:		UmountImage
6
# RunAfter:		DeleteSSHKeys
7
# Short-Description:	Inject files to the instance
8
### END TASK INFO
9

    
10
set -e
11
set -o pipefail
12

    
13
. "@commondir@/common.sh"
14

    
15
if [ ! -d "$SNF_IMAGE_TARGET" ]; then
16
    log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
17
fi
18

    
19
if [ -z "$SNF_IMAGE_PERSONALITY" ]; then
20
    warn "This image has no personality (0 files to inject)"
21
fi
22

    
23
if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
24
    echo "$SNF_IMAGE_PERSONALITY" |
25
        @scriptsdir@/inject-files.py "$SNF_IMAGE_TARGET"
26
    exit 0
27
elif [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "linux" ]; then
28
    tmpdir=$(chroot "$SNF_IMAGE_TARGET" mktemp -d)
29
    add_cleanup rm -rf "$SNF_IMAGE_TARGET/$tmpdir"
30
    echo "$SNF_IMAGE_PERSONALITY" |
31
        @scriptsdir@/inject-files.py -d "$SNF_IMAGE_TARGET/$tmpdir"
32
    chroot "$SNF_IMAGE_TARGET" chmod 777 "$tmpdir"
33
    {
34
        while read -d $'\0' src; do
35
            read -d $'\0' owner;
36
            read -d $'\0' group;
37
            read -d $'\0' mode;
38
            read -d $'\0' dest;
39
            chroot "$SNF_IMAGE_TARGET" chown "$owner:$group" "$tmpdir/$src"
40
            chroot "$SNF_IMAGE_TARGET" su -l "$owner" -c \
41
                "install -D -m $mode $(printf "%q" "$tmpdir")/$src \
42
                $(printf "%q" "$dest")"
43
        done
44
    } < "$SNF_IMAGE_TARGET/$tmpdir/manifest"
45
fi
46

    
47
exit 0
48

    
49
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
50