tm_context.sh

Marco Gomes, 21 Mar 2012 12:36

Download (2.23 KB)

 
1
#!/bin/bash
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
17
#--------------------------------------------------------------------------- #
18

    
19
CONTEXT_FILE=$1
20

    
21
while (( "$#" )); do
22
    if [ "$#" == "1" ]; then
23
        DST=$1
24
    else
25
        SRC="$SRC $1"
26
    fi
27
    shift
28
done
29

    
30

    
31
if [ -z "${ONE_LOCATION}" ]; then
32
    TMCOMMON=/usr/lib/one/mads/tm_common.sh
33
else
34
    TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
35
fi
36

    
37
. $TMCOMMON
38

    
39

    
40
DST_PATH=`arg_path $DST`
41
DST_DIR=`dirname $DST_PATH`
42
DST_FILE=`basename $DST_PATH`
43
DST_HASH=`echo -n $DST | $MD5SUM | $AWK '{print $1}'`
44
if [ -z "$ONE_LOCATION" ]; then
45
       TMP_DIR="/var/lib/one/$DST_HASH"
46
else
47
       TMP_DIR="$ONE_LOCATION/var/$DST_HASH"
48
fi
49
ISO_DIR="$TMP_DIR/isofiles"
50

    
51

    
52
exec_and_log "mkdir -p $ISO_DIR"
53

    
54
for f in $SRC; do
55
    case $f in
56
    http://*)
57
        exec_and_log "$WGET -O $ISO_DIR $f"
58
        ;;
59

    
60
    *)
61
        if [ $SECURE_CONTEXT -eq 0 -o "$f" == "$CONTEXT_FILE" ]; then
62
            exec_and_log "cp -R $f $ISO_DIR"
63
        else
64
            log "not copying potentialy dangerous file $f"
65
        fi
66
        ;;
67
    esac
68
done
69

    
70
exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
71
exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST"
72
exec_and_log "rm -rf $TMP_DIR"
73