~rodsmith/maas-cert-server/static-ip

« back to all changes in this revision

Viewing changes to canonical-certification-precheck

  • Committer: Jeff Lane
  • Author(s): Rod Smith
  • Date: 2016-03-25 19:45:20 UTC
  • mfrom: (49.1.1 010-add-precheck-script)
  • Revision ID: jeff_lane-20160325194520-jkzu3lqavqqc1sgb
Add canonical-certification-precheck to MAAS server's web page and enable SUTs to grab this via preseed file. Also modify maniacs-setup so that the new preseed file is easily installed.

Most of this is a hack to get around temporary packaging issues with getting c-c-p into a Checkbox package. The changes to maniacs-setup should be kept going forward, though.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
logfile=~/install.log
 
4
currentuser=$(logname)
 
5
codename=$(/usr/bin/lsb_release -s -c) 
 
6
arch=$(dpkg --print-architecture)
 
7
debinst="sudo debconf-apt-progress -- aptitude -y install"
 
8
 
 
9
pass(){
 
10
 eval pass${i}=1
 
11
}
 
12
 
 
13
fail(){
 
14
 eval pass${i}=0
 
15
}
 
16
 
 
17
warn(){
 
18
 eval pass${i}=2
 
19
}
 
20
 
 
21
info(){
 
22
 eval pass${i}=3
 
23
}
 
24
 
 
25
 
 
26
 
 
27
steps="Ubuntu_Version Arch EFI_Mode CCS_Version SID_Check Installed_Ram Virtualization_Support NICs_enabled IPERF Network_Subnets KVM_Image_Check" 
 
28
yes=1
 
29
 
 
30
while getopts "i" opt; do
 
31
  case $opt in
 
32
    i) individual="1";;
 
33
  esac
 
34
done
 
35
 
 
36
echoname(){
 
37
    echo -e "\n\e[1;33m============\e[m \e[1;34m$name\e[m \e[1;33m============\e[m"
 
38
}
 
39
 
 
40
Arch(){
 
41
 name="Check architecture"
 
42
 echoname
 
43
 echo -e "Architecture: $arch"
 
44
 eval info${i}=\"$arch\"
 
45
 if [ $arch = i386 ] ; then
 
46
         warn
 
47
 else
 
48
         info
 
49
 fi
 
50
}
 
51
 
 
52
 
 
53
# Display version of canonical-certification-server package installed
 
54
CCS_Version(){
 
55
name="canonical-certification-server version"
 
56
echoname
 
57
ccs=$(apt-cache policy canonical-certification-server|grep Installed|awk '{print $2}')
 
58
eval info${i}=\"$ccs\"
 
59
 
 
60
if [[ $ccs = *none* ]] ; then
 
61
        echo -e " canonical-certification-server might not be installed.\n Would you like to install it now? [Y/n]"
 
62
        read -s -N1 a
 
63
        if [[ $a == "Y" || $a == "y" || -z $a ]]; then
 
64
                echo " Installing canonical-certification-server..."
 
65
                sudo apt-add-repository -y ppa:hardware-certification/public 1>/dev/null
 
66
                sudo apt-get -q update 1>/dev/null
 
67
                sudo apt-get -q install -y maas-cert-server 1>/dev/null
 
68
                CCS_Version
 
69
        elif [[ $a == "N" || $a == "n" ]]; then
 
70
                echo 
 
71
                fail
 
72
        fi
 
73
else
 
74
        echo " canonical-certification-server: $ccs"
 
75
        info
 
76
fi
 
77
}
 
78
 
 
79
# Secure ID is set in /etc/xdg/canonical-certification.conf (?)
 
80
SID_Check(){
 
81
name="Secure ID Check"
 
82
echoname
 
83
#if [ -n $secureid ];then
 
84
if grep "^secure_id =" /etc/xdg/canonical-certification.conf ; then
 
85
        secureid=$(grep "^secure_id =" /etc/xdg/canonical-certification.conf|awk '{print $3}')
 
86
        echo " secure_id is configured as $secureid"
 
87
        eval info${i}=\"$secureid\"
 
88
        info
 
89
else
 
90
        echo -e " secure_id is not configured.\n Would you like to configure it now? [Y/n]"
 
91
        read -s -N1 a
 
92
        if [[ $a == "Y" || $a == "y" || -z $a ]]; then
 
93
                read -e -p "Type the secure_id of your SUT: " sid 
 
94
                sudo sed -i "s/#secure_id =.*/secure_id = $sid/g" /etc/xdg/canonical-certification.conf
 
95
                SID_Check
 
96
        elif [[ $a == "N" || $a == "n" ]]; then
 
97
                eval info${i}=\"Not Set\"
 
98
                info
 
99
        fi
 
100
fi
 
101
}
 
102
 
 
103
# Check local availability of KVM image & possibly download from MAAS server if it’s available there, rather than have Checkbox pull from Internet, which tends to be slow
 
104
KVM_Image_Check(){
 
105
name="KVM Image Check"
 
106
echoname
 
107
kvmurl="http://cloud-images.ubuntu.com/$codename/current/$codename-server-cloudimg-$arch-disk1.img"
 
108
if grep "^KVM_IMAGE =" /etc/xdg/canonical-certification.conf >/dev/null; then
 
109
         kvmurl=$(grep ^KVM_IMAGE /etc/xdg/canonical-certification.conf|awk '{print $3}')
 
110
         if curl --output /dev/null --silent --head --fail "$kvmurl"; then
 
111
                 echo -e " We can get our image from $kvmurl.\n Continuing to use this image"
 
112
                 pass
 
113
         elif [ -f $kvmurl ] ; then
 
114
                 echo " Local image $kvmurl exists."
 
115
                 pass
 
116
         else
 
117
                 echo " We cannot access $kvmurl." 
 
118
                 fail
 
119
         fi
 
120
                
 
121
else
 
122
        if curl --output /dev/null --silent --head --fail "$kvmurl"; then
 
123
                echo -e " We can get our image from $kvmurl.\n Continuing to use this image"
 
124
                pass
 
125
        else
 
126
                echo -e " Cannot access $kvmurl.\n Checking local image configuration."
 
127
                echo -e " KVM_IMAGE is not configured.\n Would you like to configure it now? [Y/n]"
 
128
                read -s -N1 a
 
129
                if [[ $a == "Y" || $a == "y" || -z $a ]]; then
 
130
                        read -e -p "Type the path of your KVM Image: " kvm 
 
131
                        sudo sed -i "s,#KVM_IMAGE =.*,KVM_IMAGE = $kvm,g" /etc/xdg/canonical-certification.conf
 
132
                        kvmurl=$(grep ^KVM_IMAGE /etc/xdg/canonical-certification.conf|awk '{print $3}')
 
133
                        if curl --output /dev/null --silent --head --fail "$kvmurl" || [ -f $kvmurl ]; then
 
134
                                echo " We can get our image from $kvmurl. Continuing to use this image"
 
135
                                pass
 
136
                        else
 
137
                                fail
 
138
                        fi
 
139
                elif [[ $a == "N" || $a == "n" ]]; then
 
140
                        fail
 
141
                fi
 
142
        fi
 
143
fi
 
144
}
 
145
 
 
146
#Correct Ubuntu version installed (could be tricky to determine, so maybe too much effort -- or maybe just display the Ubuntu version and, if the script is interactive, ask the user to verify that it’s what was intended)
 
147
Ubuntu_Version(){
 
148
 name="Ubuntu Version"
 
149
 echoname
 
150
 release=$(/usr/bin/lsb_release -s -d)
 
151
 eval info${i}=\"$release\"
 
152
 if [[ $release == *LTS* ]] ; then
 
153
        echo " $release is an LTS version of Ubuntu"
 
154
        info
 
155
 else
 
156
        echo " $release is a non-LTS version of Ubuntu"
 
157
        warn
 
158
 fi
 
159
}
 
160
 
 
161
 
 
162
# All NICs are on the same network segment, to flag cabling, switch, or configuration errors (??)
 
163
Network_Subnets(){
 
164
name="Netork Subnets"
 
165
echoname
 
166
check_bcast=$(for nic in `cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|egrep -v "lo|lxcbr|bridge"`
 
167
        do
 
168
                ip addr show dev $nic | grep "inet "|awk '{print $4}'
 
169
done|uniq|wc -l)
 
170
for nic in `cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|egrep -v "lo|usb"`
 
171
        do
 
172
                echo  " $nic - $(ip addr show dev $nic | grep "inet "|awk '{print $2, $4}')"
 
173
done
 
174
echo
 
175
if [ $check_bcast = 1 ]; then
 
176
        pass
 
177
        echo " All interfaces seem to be on the same subnet"
 
178
else
 
179
        echo " One or more interfaces are on separate subnets"
 
180
        fail
 
181
fi
 
182
 
 
183
}
 
184
 
 
185
# iperf and iperf3 are available on server specified in /etc/xdg/canonical-certification.conf (NOTE: iperf (2) will eventually become irrelevant)
 
186
IPERF(){
 
187
name="Iperf"
 
188
echoname
 
189
if [ $(grep ^TEST_TARGET_IPERF /etc/xdg/canonical-certification.conf|wc -l) = 1 ];then
 
190
        echo " IPERF is configured"
 
191
        pass
 
192
elif [ $(grep ^TEST_TARGET_IPERF /etc/xdg/canonical-certification.conf|wc -l) = 0 ];then
 
193
        echo -e " TEST_TARGET_IPERF is not configured.\n Would you like to configure it now? [Y/n]"
 
194
        read -s -N1 a
 
195
        if [[ $a == "Y" || $a == "y" || -z $a ]]; then
 
196
                read -e -p "Type the IP Address of the Iperf server: " ip
 
197
                sudo sed -i "s/#TEST_TARGET_IPERF = .*/TEST_TARGET_IPERF = $ip/g" /etc/xdg/canonical-certification.conf
 
198
        IPERF
 
199
        elif [[ $a == "N" || $a == "n" ]]; then
 
200
                fail
 
201
        fi
 
202
fi
 
203
local iperf2found=0
 
204
local iperf3found=0
 
205
for iperfserver in $(grep ^TEST_TARGET_IPERF /etc/xdg/canonical-certification.conf | cut -d = -f 2 | sed s/,/\\n/g)
 
206
        do
 
207
                echo " Testing $iperfserver"
 
208
                local iperffound=0
 
209
                nc -z $iperfserver 5001
 
210
                if [ $? = 0 ]; then
 
211
                        echo " Iperf server found on port 5001 on $iperfserver"
 
212
                        iperf2found=1
 
213
                        iperffound=1
 
214
                fi
 
215
                iperf3 -c $iperfserver -n 1 &> /dev/null
 
216
                if [ $? = 0 ]; then
 
217
                        echo " Iperf3 server found on port 5201 on $iperfserver"
 
218
                        iperf3found=1
 
219
                        iperffound=1
 
220
                fi
 
221
                if [ $iperffound = 0 ]; then
 
222
                        echo " No Iperf (2) or iperf3 server found on $iperfserver"
 
223
                fi
 
224
done
 
225
if [[ $iperf2found == 0 ]]; then
 
226
        echo " No iperf (2) server found"
 
227
        fail
 
228
fi
 
229
if [[ $iperf3found == 0 ]]; then
 
230
        echo " No iperf3 server found"
 
231
        fail
 
232
fi
 
233
}
 
234
 
 
235
# All NICs are enabled
 
236
NICs_enabled(){
 
237
name="All NICs enabled"
 
238
echoname
 
239
for nic in `cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|grep -v lo`
 
240
        do
 
241
                state=$(cat /sys/class/net/$nic/operstate)
 
242
                if [ $state = "up" ]; then
 
243
                        echo " Interface $nic is $state"
 
244
                        pass
 
245
                elif [ $state = "down" ]; then
 
246
                        echo " Interface $nic is $state"
 
247
                        nicfail=1
 
248
                fi
 
249
done
 
250
if [ "$nicfail" = "1" ]; then
 
251
        fail
 
252
fi
 
253
}
 
254
 
 
255
#### Installed RAM (STG says 4GiB minimum) ###
 
256
Installed_Ram(){
 
257
name="Check Installed Ram"
 
258
echoname
 
259
mem=$(cat /proc/meminfo |grep MemTotal|awk '{print $2}')
 
260
eval info${i}="$mem "
 
261
if [ $mem -lt 4096000 ] ; then
 
262
        echo " $mem is less than 4G"
 
263
        warn
 
264
else
 
265
        echo " $mem is greater than 4G"
 
266
        pass
 
267
fi
 
268
}
 
269
 
 
270
#CPU virtualization support (VMX/SVM)
 
271
Virtualization_Support(){
 
272
name="Virtualization Support"
 
273
echoname
 
274
cat /proc/cpuinfo |egrep "vmx|svm" >/dev/null
 
275
if [ $? = 0 ]; then
 
276
 echo " System has virtualization support"
 
277
 pass
 
278
else
 
279
 echo " System does not have virtualization support"
 
280
 fail
 
281
fi
 
282
}
 
283
 
 
284
#EFI-mode installation (redundant with Checkbox test for same, but maybe good to warn about this issue before running Checkbox)
 
285
EFI_Mode(){
 
286
name="EFI-mode installation"
 
287
echoname
 
288
if [ -d /sys/firmware/efi ]; then
 
289
        efi='This is an EFI Mode installation'
 
290
        echo " $efi"
 
291
        eval info${i}=\"$efi\"
 
292
        info
 
293
elif [ ! -d /sys/firmware/efi ]; then
 
294
        efi='This is not an EFI Mode installation'
 
295
        echo " $efi"
 
296
        eval info${i}=\"$efi\"
 
297
        info
 
298
fi
 
299
}
 
300
 
 
301
runchoices() {
 
302
 echo 
 
303
 for i in $steps
 
304
  do
 
305
   eval "status=\$check${i}"
 
306
   if [[ $status == "y" ]] || [[ "$yes" == "1" ]]; then
 
307
    "$i"
 
308
   else
 
309
    echo -e "\e[1;31mskipping\e[m \e[1;34m$i\e[m"
 
310
   fi
 
311
 done
 
312
}
 
313
 
 
314
report() {
 
315
    echo -e "\n\e[1;33m============\e[m \e[1;34mReport\e[m \e[1;33m============\e[m\n"
 
316
 for i in $steps
 
317
  do
 
318
   eval "status=\$pass${i}"
 
319
   if [ $status = "1" ];then
 
320
    printf "%30s" "$i  "
 
321
    printf "%0.1s" "-"{1..20}
 
322
    printf "\e[1;32m  Passed\e[m\n"
 
323
   elif [ $status = "0" ];then
 
324
    printf "%30s" "$i  "
 
325
    printf "%0.1s" "-"{1..20}
 
326
    printf "\e[1;31m  Failed\e[m\n"
 
327
   elif [ $status = "2" ];then
 
328
    eval "detail=\$info${i}"
 
329
    printf "%30s" "$i  "
 
330
    printf "%0.1s" "-"{1..20}
 
331
    printf "\e[1;33m  $detail\e[m\n"
 
332
   elif [ $status = "3" ];then
 
333
    eval "detail=\$info${i}"
 
334
    printf "%30s" "$i  "
 
335
    printf "%0.1s" "-"{1..20}
 
336
    printf "\e[1;37m  $detail\e[m\n"
 
337
   fi
 
338
 done
 
339
}
 
340
 
 
341
runchoices
 
342
report