3 # Copyright (C) 2011 GRNET S.A.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # Provides: EnforcePersonality
22 # RunBefore: UmountImage
23 # RunAfter: MountImage
24 # Short-Description: Inject files to the instance
29 . "@commondir@/common.sh"
31 trap task_cleanup EXIT
34 # Check if the task should be prevented from running.
37 # Default mode for directories
40 if [ ! -d "$SNF_IMAGE_TARGET" ]; then
41 log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing"
44 if [ -z "$SNF_IMAGE_PERSONALITY" ]; then
45 warn "This image has no personality (0 files to inject)"
49 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
50 echo "$SNF_IMAGE_PERSONALITY" |
51 @scriptsdir@/inject-files.py "$SNF_IMAGE_TARGET"
55 tmpdir="$(env TMPDIR="$SNF_IMAGE_TARGET/tmp" mktemp -d)"
56 add_cleanup rm -rf "$tmpdir"
57 echo "$SNF_IMAGE_PERSONALITY" |
58 @scriptsdir@/inject-files.py -d "$tmpdir"
60 { while read -d $'\0' src; do
66 err_msg="Unable to inject file: \`$dest' to the VM. "
68 # Default owner (Probably root)
69 if [ -z "$owner" ]; then
72 uid="$({ grep "^$owner:" "$SNF_IMAGE_TARGET/etc/passwd" || true; } | cut -d: -f3)"
73 if [ -z "$uid" ]; then
74 log_error "$err_msg" "File owner: \`$owner' does not exist!"
78 # Default group (Probably root in Linux and wheel in *BSD)
79 if [ -z "$group" ]; then
82 gid="$({ grep "^$group:" "$SNF_IMAGE_TARGET/etc/group" || true; } | cut -d: -f3)"
83 if [ -z "$gid" ]; then
84 log_error "$err_msg" "Group: \`$group' does not exist!"
88 path=( "$(dirname "$dest")" )
90 parent="$(dirname "${path[0]}")"
91 if [ "$parent" = "${path[0]}" ]; then
94 path=( "$parent" "${path[@]}" )
97 for dir in "${path[@]}"; do
98 if [ -d "$SNF_IMAGE_TARGET/$dir" ]; then
100 elif [ -e "$SNF_IMAGE_TARGET/$dir" ]; then
101 log_error "$err_msg" "File: \`$dir' exists and is not a directory."
104 mkdir -m "$DIRMODE" "$SNF_IMAGE_TARGET/$dir"
105 chown "$uid:$gid" "$SNF_IMAGE_TARGET/$dir"
108 install -o "$uid" -g "$gid" -m "$mode" "$tmpdir/$src" "$SNF_IMAGE_TARGET/$dest"
109 done } < "$tmpdir/manifest"
114 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :