28
|
1 |
#!/bin/bash |
|
2 |
# predeploy.sh - Made for Puppi |
|
3 |
|
|
4 |
# Sources common header for Puppi scripts |
|
5 |
. $(dirname $0)/header || exit 10 |
|
6 |
|
|
7 |
# Show help |
|
8 |
showhelp () { |
|
9 |
echo "This script prepares the contents of the predeploy directory" |
|
10 |
echo "It integrates and uses variables provided by other core Puppi scripts" |
|
11 |
echo "It has the following options:" |
|
12 |
echo "-v <variable_name> (optional) Name of the variable that identifies the file to untar/unzip" |
|
13 |
echo " By default is used $downloadedfile" |
|
14 |
echo "-t <file_type> (optional) The type of file that is retrieved: zip|tarball" |
|
15 |
echo " By default is used $source_type " |
|
16 |
echo "-m <magicfix> (optional) The prefix (directory) you may not want to put in the deploy" |
|
17 |
echo " Use this if the zip or tar contain a base dir (as often) and you want to copy" |
|
18 |
echo " to the deploy dir only its contents and not the whole directory" |
|
19 |
echo |
|
20 |
echo "Examples:" |
|
21 |
echo "predeploy.sh " |
|
22 |
echo "predeploy.sh -t zip" |
|
23 |
echo "predeploy.sh -t zip -v myz" |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
# Check Arguments |
|
28 |
while [ $# -gt 0 ]; do |
|
29 |
case "$1" in |
|
30 |
-v) |
|
31 |
downloadedfile="$(eval "echo \${$(echo ${2})}")" |
|
32 |
shift 2 ;; |
|
33 |
-t) |
|
34 |
source_type=$2 |
|
35 |
shift 2 ;; |
|
36 |
-m) |
|
37 |
predeploy_dirprefix=$2 |
|
38 |
shift 2 ;; |
|
39 |
esac |
|
40 |
done |
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
predeploy () { |
|
45 |
cd $predeploydir |
|
46 |
case "$source_type" in |
|
47 |
tarball) |
|
48 |
case "$debug" in |
|
49 |
yes|full) |
|
50 |
tar -zxvf $downloadedfile |
|
51 |
check_retcode |
|
52 |
;; |
|
53 |
*) |
|
54 |
tar -zxf $downloadedfile |
|
55 |
check_retcode |
|
56 |
;; |
|
57 |
esac |
|
58 |
;; |
|
59 |
zip) |
|
60 |
case "$debug" in |
|
61 |
yes|full) |
|
62 |
unzip $downloadedfile |
|
63 |
check_retcode |
|
64 |
;; |
|
65 |
*) |
|
66 |
unzip -qq $downloadedfile |
|
67 |
check_retcode |
|
68 |
;; |
|
69 |
esac |
|
70 |
;; |
|
71 |
gz) |
|
72 |
case "$debug" in |
|
73 |
yes|full) |
|
74 |
gzip -d $downloadedfile |
|
75 |
check_retcode |
|
76 |
;; |
|
77 |
*) |
|
78 |
gzip -d -q $downloadedfile |
|
79 |
check_retcode |
|
80 |
;; |
|
81 |
esac |
|
82 |
;; |
|
83 |
war) |
|
84 |
cp $downloadedfile . |
|
85 |
check_retcode |
|
86 |
;; |
|
87 |
esac |
|
88 |
} |
|
89 |
|
|
90 |
predeploy |
|
91 |
|
|
92 |
# Updates predeploydir if a directory prefix exists |
|
93 |
if [[ x$predeploy_dirprefix != "x" ]] ; then |
|
94 |
save_runtime_config "predeploydir=$predeploydir/$predeploy_dirprefix" |
|
95 |
fi |