-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_package.sh
296 lines (278 loc) · 10.2 KB
/
install_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
######### Global variables######
create_only_tar="yes"
oslevel=0
packagaNames=("")
i=0
arr=("temp1","temp2")
val=7.2
###########################
ver() {
printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' ');
}
usage() {
echo "install_package.sh options are -o -t -c -p -h"
echo ""
echo "-p: Mandatory"
echo " For giving packages name to install/tar."
echo " After -p option add packages names. Ex: -p package1 package2"
echo ""
echo "-o: Mandatory"
echo " For providing oslevel, supported levels are above version 7.1"
echo ""
echo "-t: Optional"
echo " For creating just tar, for installation do not use this option"
echo " also please run the script as a root priviledge for installation"
echo ""
echo "-c: Optional"
echo " For clearing cache directory /var/AutoInstaller-tmp/"
echo ""
echo "-h: Optional"
echo " For getting help"
exit
}
#Too few Arguments
len=$#
if [ $len -lt 4 ]; then
echo "Cannot process, please enter commnad correctly"
usage
fi
#Clear cache and set if only tar file needed
create_only_tar="no"
args=$*
for var in $@;do
arr[$i]="$var"
i=`expr $i + 1`
done
i=0
# Compares the two packages version number
function cmp_version {
large=$(echo $1 $2 |
awk '{ split($1, a, ".");
split($2, b, ".");
x = 0;
for (i = 1; i <= 4; i++)
if (a[i] < b[i]) {
x = 3;
break;
} else if (a[i] > b[i]) {
x = 2;
break;
}
print x;
}')
return $large
}
# Compares the two packages release number
function cmp_release {
arg1=`expr $1`
arg2=`expr $2`
echo $1 | grep "_" > /dev/null 2>&1
ret1=$?
echo $2 | grep "_" > /dev/null 2>&1
ret2=$?
if [[ $ret1 -eq 0 ]] && [[ $ret2 -eq 0 ]]
then
if [[ $arg1 < $arg2 ]]
then
return 3
elif [[ $arg1 > $arg2 ]]
then
return 2
fi
else
echo $2 | grep "_" > /dev/null 2>&1
if [[ $? -eq 0 ]]
then
arg2=`echo $2 | grep "_" | sed 's/_.*//' | bc`
fi
if [[ $arg1 -lt $arg2 ]]
then
return 3
elif [[ $arg1 -gt $arg2 ]]
then
return 2
fi
fi
}
checkPackages()
{
rpms_list=("")
pkg_list=("")
pkgname_list=("")
pkg_name_ver_list=("")
install_list=("")
idx=0
ls /var/AutoInstaller-tmp/$1/*.rpm | while read rpm_file
do
echo "##$rpm_file##"
pkg_list[$idx]=`rpm -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}" $rpm_file`
pkgname_list[$idx]=`rpm -qp --qf "%{NAME}" $rpm_file`
rpms_list[$idx]=`echo $rpm_file`
pkg_name_ver_list[$idx]=`rpm -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}" $rpm_file`
$idx=`expr $idx + 1`
done
#let "pkg_count=0"
pkg_count=${#pkg_list[*]}
p=0
echo $pkg_count
while (( $p < $pkg_count ))
do
rpm -q --qf %{NAME} ${pkgname_list[$p]} > /dev/null 2>&1
n_inst=$?
if [[ $n_inst -eq 0 ]] # package with the same name is installed
then
inst_pkgname=`rpm -q --qf %{NAME} ${pkgname_list[$p]}`
rpm -q --qf %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH} ${pkg_list[$p]} > /dev/null 2>&1
i_inst=$?
if [[ $i_inst -ne 0 ]] # package with exact version isn't installed
then
# check if rpm from dnf_bundle is higher version than the one installed.
inst_pkgname_ver=`rpm -q --qf %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH} ${pkgname_list[$p]}`
if [[ "${pkgname_list[$p]}" = "$inst_pkgname" ]]
then
inst_ver=`rpm -q --qf %{VERSION} ${pkgname_list[$p]}`
rpm_ver=`rpm -qp --qf %{VERSION} ${rpms_list[$p]}`
cmp_version $inst_ver $rpm_ver
rc1=$?
if [[ $rc1 -eq 0 ]] # Same version matches. Check for the release.
then
inst_rel=`rpm -q --qf %{RELEASE} ${pkgname_list[$p]}`
rpm_rel=`rpm -qp --qf %{RELEASE} ${rpms_list[$p]}`
cmp_release $inst_rel $rpm_rel
rc2=$?
if [[ $rc2 -eq 3 ]] # Installed release is less than the bundle
then
echo "$inst_pkgname_ver will be updated to ${pkg_name_ver_list[$p]}"
install_list[${#install_list[*]}+1]=${rpms_list[$p]}
elif [[ $rc2 -eq 2 ]] # Higher version is already installed
then
echo "Skipping ${pkg_name_ver_list[$p]} as higher version $inst_pkgname_ver is installed."
fi
elif [[ $rc1 -eq 3 ]] # Installed rpm lower than the bundle
then
echo "$inst_pkgname_ver will be updated to ${pkg_name_ver_list[$p]}"
install_list[${#install_list[*]}+1]=${rpms_list[$p]}
elif [[ $rc1 -eq 2 ]]
then
echo "Skipping ${pkg_name_ver_list[$p]} as higher version $inst_pkgname_ver is installed."
fi
fi
elif [[ $i_inst -eq 0 ]] # exact version of the package is installed. Do nothing.
then
echo "${pkg_name_ver_list[$p]} is already installed"
fi
elif [[ $n_inst -ne 0 ]] # package with the name isn't installed
then
echo "${pkg_name_ver_list[$p]} will be installed"
install_list[${#install_list[*]}+1]=${rpms_list[$p]}
fi
(( p+=1 ))
done
if [[ ${#install_list[@]} -eq 0 ]]
then
#echo "\n"
#echo "\nperl and all it's dependencies are already installed."
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 0
fi
echo "Installing the packages..."
rpm -Uvh ${install_list[@]}
rc=$?
if [[ $rc -eq 0 ]]
then
#echo "\n"
#echo "perl and dependencies installed successfully."
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 0
elif [[ $rc -ne 0 ]]
then
#echo "\n"
echo "perl and dependencies installation failed."
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi
}
for ((index=0; index < ${#arr[@]}; index++));do
if [[ ${arr[$index]} =~ "-c" ]];
then
echo "Clearing your cache directory"
if [[ -e /var/AutoInstaller-tmp/ ]];
then
rm -rf /var/AutoInstaller-tmp/
fi
fi
if [[ ${arr[$index]} =~ "-t" ]];
then
create_only_tar="yes"
fi
if [[ ${arr[$index]} =~ "-o" ]];
then
index=`expr $index + 1`
oslevel=${arr[$index]}
if [[ $(ver $oslevel) -lt $(ver $val) ]];
then
echo "Versions above 7.1 are supported"
exit
fi
fi
if [[ ${arr[$index]} =~ "-h" ]];
then
usage
fi
if [[ ${arr[$index]} =~ "-p" ]];
then
index=`expr $index + 1`
while [[ $index < ${#arr[@]} ]];do
if [ '${arr[$index]}' = '-' ];then
break
else
packageName[$i]=${arr[$index]}
fi
i=`expr $i + 1`
index=`expr $index + 1`
done
fi
done
# Checking if the user has enetered package names or not
if [[ ${#packageName[@]} -eq 0 ]];then
echo "Package list cannot be empty"
usage
fi
# Checking if the oslevel has been provided or not
if [[ $oslevel =~ "0" ]];then
echo "Please provide oslevel using -o option"
usage
fi
if [[ ! -e /var/AutoInstaller-tmp/ ]];then
mkdir /var/AutoInstaller-tmp/
fi
cd /var/AutoInstaller-tmp/
for ((index=0; index < ${#packageName[@]}; index++));do
links=`/usr/bin/awk "/^${packageName[$index]}/{ f = 1;next } /^[a-z]/{ f = 0 } f;" /master_file`
mkdir ${packageName[$index]} 2>&1 | tee /dev/null
for l in $links;do
if [[ $l =~ "$oslevel" && ( $l =~ "ppc/" || $l =~ "noarch" || $l =~ "ppc-") ]];then
rpmname=`echo "$l"|/usr/bin/awk -F/ '{print $NF}'`
if ! ls -l $rpmname >/dev/null 2>&1 ;then
cd ${packageName[$index]}
LDR_CNTRL=MAXDATA=0x80000000@DSA /usr/opt/perl5/bin/lwp-download $l
cp $rpmname ../
cd ../
else
cp $rpmname ${packageName[$index]}
fi
fi
done
if [[ $create_only_tar == "yes" ]];
then
tar -cf ${packageName[$index]}.tar ${packageName[$index]}/*
else
rpm -ivh ${packageName[$index]}/*
#checkPackages "${packageName[$index]}"
fi
rm -rf ${packageName[$index]}/
done