tm_clone.sh

my fix - Gian Uberto Lauri, 02/14/2011 07:35 PM

Download (1.81 KB)

 
1
#!/bin/bash
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2010, 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
SRC=$1
20
DST=$2
21

    
22
if [ -z "${ONE_LOCATION}" ]; then
23
    TMCOMMON=/usr/lib/one/mads/tm_common.sh
24
else
25
    TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
26
fi
27

    
28
. $TMCOMMON
29

    
30
get_vmdir
31

    
32
SRC_PATH=`arg_path $SRC`
33
DST_PATH=`arg_path $DST`
34

    
35
#fix_paths
36

    
37
log "$1 $2 $DST"
38
log "SRC: $SRC_PATH"
39
log "DST: $DST_PATH"
40

    
41
DST_DIR=`dirname $DST_PATH`
42

    
43
log "Creating directory $DST_DIR"
44
exec_and_log "mkdir -p $DST_DIR"
45
exec_and_log "chmod a+w $DST_DIR"
46

    
47
case $SRC in
48
http://*)
49
    log "Downloading $SRC"
50
    exec_and_log "$WGET -O $DST_PATH $SRC"
51
    ;;
52

    
53
*)
54
    log "Cloning $SRC_PATH"
55
    exec_and_log "cp -r $SRC_PATH $DST_PATH"
56
    ;;
57
esac
58

    
59
exec_and_log "chmod a+rw $DST_PATH"
60