-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnf_aixtoolbox.sh
244 lines (220 loc) · 7.04 KB
/
dnf_aixtoolbox.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
#!/bin/ksh
# This scripts downloads the rpm.rte & dnf_bundle.tar
# rpm.rte-4.13.0.x which is a prequisite for dnf.
# dnf_bundle.tar contains dnf and its dependent packages.
# This script checks if any of the package from dnf_bundle is
# already installed and then installs the packages accordingly.
export LANG=C
if [[ -e /usr/opt/rpm/bin/rpm ]]
then
RPM_CMD="/usr/opt/rpm/bin/rpm"
else
RPM_CMD="/usr/bin/rpm"
fi
# Check if we are running this as the root user.
if [[ "$(id -u)" != "0" ]]
then
echo "This script must be run as root."
exit 1
fi
# First check the AIX version.
oslvl=`/usr/bin/oslevel`
aix_ver=$(/usr/bin/lslpp -qLc bos.rte | /usr/bin/awk -F':' '{print $3}')
af1=$(echo $aix_ver | /usr/bin/cut -d"." -f1)
af2=$(echo $aix_ver | /usr/bin/cut -d"." -f2)
af3=$(echo $aix_ver | /usr/bin/cut -d"." -f3)
if [[ "$oslvl" = "7.1.0.0" ]]
then
if [[ ( ! $af1 -ge 7 ) || ( ! $af2 -ge 1 ) || ( ! $af3 -ge 3 ) ]]
then
echo "dnf and dependencies can be installed on AIX 7.1.3 and higher versions."
exit 1
fi
else
if [[ ( ! $af1 -ge 7 ) || ( ! $af2 -ge 1 ) ]]
then
echo "dnf and dependencies can be installed on AIX 7.1.3 and higher versions."
exit 1
fi
fi
# Check if yum3 is installed.
yum3_instd=0
$RPM_CMD -qa | grep yum-3.4.3 > /dev/null 2>&1
if [[ $? -eq 0 ]]
then
yum3_instd=1
fi
prog=${0##*/}
yum4=0
usage() {
print >&2 "Usage: $prog <-d> <-y> <-n> -?
-d Install and setup dnf if yum is not installed.
yum command will not be available only dnf command can be used.
-y Installs dnf, and updates yum3 to dnf yum4 if yum3 is installed.
If no yum3 is installed then dnf and yum4 will be installed.
yum command will also be available along with dnf.
-n Install dnf where both yum and dnf can coexist if yum is installed already.
This is not a recommended option."
exit 1
}
if [[ $# -ne 1 ]]
then
usage
exit 1
fi
arg=`echo $1 | /usr/bin/cut -c1-3`
if [[ "$arg" = "-d" ]]
then
yum4=1 # Install only dnf if no YUM is installed.
if [[ $yum3_instd -eq 1 ]]
then
echo "YUM is already installed in the machine."
echo "Please use the option -y to update to YUM4(dnf)."
exit 1
fi
elif [[ "$arg" = "-y" ]]
then
yum4=2 # Update existing YUM3 to YUM4.
elif [[ "$arg" = "-n" ]]
then
yum4=3 # Have both YUM and dnf at the same time.
else
usage
fi
# Check openssl version.
function print_openssl_err {
echo "Please install openssl 1.0.2.2001 and higher version."
echo "You can download and install latest openssl from AIX web download site"
echo "https://www-01.ibm.com/marketing/iwm/platform/mrs/assets?source=aixbp"
exit 1
}
ssl_ver=$(lslpp -Lc openssl.base | /usr/bin/awk 'FNR==2' | /usr/bin/awk -F':' '{print $3}')
f1=$(echo $ssl_ver | /usr/bin/cut -d"." -f1)
f2=$(echo $ssl_ver | /usr/bin/cut -d"." -f2)
f3=$(echo $ssl_ver | /usr/bin/cut -d"." -f3)
f4=$(echo $ssl_ver | /usr/bin/cut -d"." -f4)
if [[ ( ! $f1 -ge 1 ) || ( ! $f2 -ge 0 ) || ( ! $f3 -ge 0) ]]
then
print_openssl_err
elif [[ ( $f2 -eq 0 ) && ( $f3 -eq 1) ]]
then
print_openssl_err
else
if [[ ( $f1 -eq 1 ) && ($f2 -eq 0 ) && ( $f3 -eq 2 ) ]]
then
if [[ ( ! $f4 -ge 2001 ) ]]
then
print_openssl_err
fi
fi
fi
oslvl=`/usr/bin/oslevel`
aix_730_plus=0
os_f1=$(echo $oslvl | /usr/bin/cut -d"." -f1)
os_f2=$(echo $oslvl | /usr/bin/cut -d"." -f2)
os_f3=$(echo $oslvl | /usr/bin/cut -d"." -f3)
os_f4=$(echo $oslvl | /usr/bin/cut -d"." -f4)
if [[ ( $os_f1 -ge 7 ) && ( $os_f2 -ge 3 ) && ( $os_f3 -ge 0 ) && ( $os_f4 -ge 0 ) ]]
then
aix_730_plus=1
fi
# Check if /tmp has enough space to download rpm.rte & dnf_bundle
# and size for extracting rpm packages.
# For 71_72 bundle it requires around 340 MB of free space.
# 170M for bundle which includes rpm.rte (40M) and rpm packages (130M).
# rpm packages extracted.
if [[ $aix_730_plus -eq 1 ]]
then
typeset -i total_req=`echo "(270)" | bc`
tmp_free=`/usr/bin/df -m /tmp | sed -e /Filesystem/d | awk '{print $3}'`
if [[ $tmp_free -le $total_req ]]
then
echo "Please make sure /tmp has around 270MB of free space to download and"
echo "extract files from dnf_bundle."
exit 1
fi
else
typeset -i total_req=`echo "(340)" | bc`
tmp_free=`/usr/bin/df -m /tmp | sed -e /Filesystem/d | awk '{print $3}'`
if [[ $tmp_free -le $total_req ]]
then
echo "Please make sure /tmp has around 340MB of free space to download and"
echo "extract files from dnf_bundle."
exit 1
fi
fi
# Check if /opt is having enough space to install the packages from dnf_bundle.
# Currently we need around 457MB of free space in /opt filesystem.
typeset -i total_opt=`echo "(512)" | bc`
opt_free=`/usr/bin/df -m /opt | sed -e /Filesystem/d | head -1 | awk '{print $3}'`
if [[ $opt_free -le $total_opt ]]
then
echo "Total free space required for /opt filesystem to install rpms"
echo " from dnf_bundle is around 512MB."
echo "Please increase the size of /opt and retry."
exit 1
fi
# Create a temporary directroy where all downloads should go.
curr_time=`date +%Y%m%d%H%M%S`
mkdir -p /tmp/dnf-$curr_time
tmppath=`echo /tmp/dnf-$curr_time`
cd $tmppath
#Downloads will be done through the perl lwp-download.
if [[ $aix_730_plus -eq 1 ]]
then
echo "Attempting download of dnf_bundle_aix_73.tar ..."
/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/ezinstall/ppc/dnf_bundle_aix_73.tar
if [[ $? -ne 0 ]]
then
echo "Failed to download dnf_bundle_aix_73.tar"
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi
# Do this once rpm.rte for 730 is available on AIX Toolbox.
#/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/INSTALLP/ppc/rpm.rte
#if [[ $? -ne 0 ]]
#then
# echo "Failed to download rpm.rte"
# exit 1
#fi
else
echo "Attempting download of dnf_bundle_aix_71_72.tar ..."
/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/ezinstall/ppc/dnf_bundle_aix_71_72.tar
if [[ $? -ne 0 ]]
then
echo "Failed to download dnf_bundle_aix_71_72.tar"
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 1
fi
#/usr/opt/perl5/bin/lwp-download http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/INSTALLP/ppc/rpm.rte
# if [[ $? -ne 0 ]]
# then
# echo "Failed to download rpm.rte"
# exit 1
# elif [[ -e rpm.rte.txt ]]
# then
# /usr/bin/mv rpm.rte.txt rpm.rte
# fi
fi
#end of perl download
if [[ $aix_730_plus -eq 1 ]]
then
echo "\nExtracting dnf_bundle_aix_73.tar ..."
tar -xvf dnf_bundle_aix_73.tar
else
echo "\nExtracting dnf_bundle_aix_71_72.tar ..."
tar -xvf dnf_bundle_aix_71_72.tar
fi
./install_dnf.sh "$arg" $yum4 $yum3_instd 2
if [[ $? -eq 0 ]]
then
cd - >/dev/null 2>&1
rm -rf $tmppath
exit 0
elif [[ $? -ne 0 ]]
then
echo "You can try installing the downloaded dnf packages from $tmppath manually."
exit 1
fi