88# to you under the Apache License, Version 2.0 (the
99# "License"); you may not use this file except in compliance
1010# with the License. You may obtain a copy of the License at
11- #
11+ #
1212# http://www.apache.org/licenses/LICENSE-2.0
13- #
13+ #
1414# Unless required by applicable law or agreed to in writing,
1515# software distributed under the License is distributed on an
1616# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -37,48 +37,49 @@ templateId=
3737hyper=
3838msKey=password
3939DISKSPACE=2120000 # free disk space required in kilobytes
40- dbHost=
41- dbUser=
40+ dbHost=" localhost "
41+ dbUser=" root "
4242dbPassword=
43- dbPort=
43+ dbPort=3306
4444jasypt=' /usr/share/cloudstack-common/lib/jasypt-1.9.2.jar'
4545while getopts ' m:h:f:u:Ft:e:s:o:r:d:p:' # OPTION
4646do
4747 case $OPTION in
48- m) mflag=1
49- mntpoint=" $OPTARG "
50- ;;
51- f) fflag=1
52- tmpltimg=" $OPTARG "
53- ;;
54- u) uflag=1
55- url=" $OPTARG "
56- ;;
57- F) Fflag=1 ;;
48+ m) mflag=1
49+ mntpoint=" $OPTARG "
50+ ;;
51+ f) fflag=1
52+ tmpltimg=" $OPTARG "
53+ ;;
54+ u) uflag=1
55+ url=" $OPTARG "
56+ ;;
57+ F) Fflag=1
58+ ;;
5859 t) templateId=" $OPTARG "
59- ;;
60+ ;;
6061 e) ext=" $OPTARG "
61- ;;
62+ ;;
6263 h) hyper=" $OPTARG "
63- ;;
64+ ;;
6465 s) sflag=1
65- msKey=" $OPTARG "
66- ;;
66+ msKey=" $OPTARG "
67+ ;;
6768 o) oflag=1
6869 dbHost=" $OPTARG "
69- ;;
70+ ;;
7071 r) rflag=1
7172 dbUser=" $OPTARG "
72- ;;
73+ ;;
7374 d) dflag=1
7475 dbPassword=" $OPTARG "
75- ;;
76+ ;;
7677 p) pflag=1
7778 dbPort=" $OPTARG "
78- ;;
79- ? ) usage
80- failed 2
81- ;;
79+ ;;
80+ ? ) usage
81+ failed 2
82+ ;;
8283 esac
8384done
8485
9495 failed 2
9596fi
9697
97- if [ ! -d $mntpoint ]
98+ if [ ! -d $mntpoint ]
9899then
99100 echo " mount point $mntpoint doesn't exist\n"
100101 failed 4
101102fi
102103
103- if [[ " $fflag " == " 1" && ! -f $tmpltimg ]]
104+ if [[ " $fflag " == " 1" && ! -f $tmpltimg ]]
104105then
105106 echo " template image file $tmpltimg doesn't exist"
106107 failed 3
107108fi
108109
109- if [ " $pflag " != 1 ]; then
110- dbPort=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.port' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
111- fi
110+ if [ -f /etc/cloudstack/management/db.properties ]
111+ then
112+ if [ " $pflag " != 1 ]
113+ then
114+ dbPort=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.port' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
115+ fi
112116
113- if [ " $oflag " != 1 ]; then
114- dbHost=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.host' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
115- fi
116- if [ " $rflag " != 1 ]; then
117- dbUser=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.username' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
118- fi
117+ if [ " $oflag " != 1 ]
118+ then
119+ dbHost=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.host' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
120+ fi
121+
122+ if [ " $rflag " != 1 ]
123+ then
124+ dbUser=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.username' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
125+ fi
119126
120- if [ -f /etc/cloudstack/management/db.properties ]; then
121127 encType=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.encryption.type' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
122128 if [ " $encType " == " file" ]
123129 then
@@ -130,23 +136,24 @@ if [ -f /etc/cloudstack/management/db.properties ]; then
130136 failed 9
131137 fi
132138 fi
133- fi
134139
135- if [[ " $encType " == " file" || " $encType " == " web" ]]
136- then
137- encPassword=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.password' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' i | sed ' s/^ENC(\(.*\))/\1/' )
138- if [ ! $encPassword == " " ]
139- then
140- dbPassword=(` java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false` )
141- if [ ! $dbPassword ]
142- then
143- echo " Failed to decrypt DB password from db.properties"
144- failed 9
145- fi
146- fi
147- else
148- if [ " $dflag " != 1 ]; then
149- dbPassword=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.password' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' i )
140+ if [[ " $encType " == " file" || " $encType " == " web" ]]
141+ then
142+ encPassword=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.password' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' i | sed ' s/^ENC(\(.*\))/\1/' )
143+ if [ ! $encPassword == " " ]
144+ then
145+ dbPassword=(` java -classpath $jasypt org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI decrypt.sh input=$encPassword password=$msKey verbose=false` )
146+ if [ ! $dbPassword ]
147+ then
148+ echo " Failed to decrypt DB password from db.properties"
149+ failed 9
150+ fi
151+ fi
152+ else
153+ if [ " $dflag " != 1 ]
154+ then
155+ dbPassword=$( sed ' /^\#/d' /etc/cloudstack/management/db.properties | grep ' db.cloud.password' | tail -n 1 | cut -d " =" -f2- | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' i )
156+ fi
150157 fi
151158fi
152159
184191
185192if [ ! $templateId ]
186193then
187- echo " Unable to get template Id from database"
188- failed 8
194+ echo " Unable to get template Id from database"
195+ failed 8
189196fi
190197
191198_uuid=$( uuidgen)
192199localfile=$_uuid .$ext
193200
194- _res=(` mysql -h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e " update cloud.vm_template set uuid=\" $_uuid \" , url=\" $url \" where id=\" $templateId \" " ` )
201+ _res=(` mysql -P $dbPort - h $dbHost --user=$dbUser --password=$dbPassword --skip-column-names -U cloud -e " update cloud.vm_template set uuid=\" $_uuid \" , url=\" $url \" where id=\" $templateId \" " ` )
195202
196203mntpoint=` echo " $mntpoint " | sed ' s|/*$||' `
197204
0 commit comments