#!/bin/bash ################################### #Name: Lab2Check1.sh #Purpose: Script that checks the first part of OPS235 - Lab 2 (Seneca College) #Written by: Philip Ianni #Last Edited: 18 January 2016 ################################## #Ensure root if [[ $(whoami) != "root" ]] then echo "Please run this as root!" exit 1 fi #List required software RequiredSoftware=("qemu-kvm" "qemu-img" "virt-manager" "libvirt" "libvirt-python" "python-virtinst" "libvirt-client" "virt-install" "virt-viewer" "bridge-utils" "iptables-services") #Grab list of installed software, store in variable. We do this to reduce overhead from system continously executing rpm command InstalledSoftware=$(rpm -qa) #Foreach loop to test if software is actually installed, exit with message at end of loop if all not required for package in ${RequiredSoftware[@]} do echo "$InstalledSoftware" | grep -q $package if [[ $? -ne 0 ]] then MissingSoftware=("${MissingSoftware[@]}" "$package") fi done #Check if missing software variable contains data, if so echo and exit if [[ -n ${MissingSoftware[@]} ]] then echo "It seems you are missing the following yum package(s)" echo "${MissingSoftware[@]}" # Uncomment this later exit 2 fi #Check firewall/iptables status FirewalldStatus=$(systemctl status firewalld) IptablesStatus=$(systemctl status iptables) if ! [[ "$FirewalldStatus" =~ masked ]] then echo "The build-in firewalld service is not masked. Hint: systemctl ... ..." exit 2 elif ! [[ "$FirewalldStatus" =~ inactive ]] then echo "The build-in firewalld service is not stop. Hint: systemctl ... ..." exit 3 elif ! [[ "$IptablesStatus" =~ loaded ]] then echo "The iptables service is not loaded. Hint: systemctl ... ..." exit 4 elif ! [[ "$IptablesStatus" =~ Active:\ active ]] then echo "The iptables service is not active. Hint: systemctl ... ..." exit 5 elif ! [[ "$IptablesStatus" =~ enabled ]] then echo "The iptables service is not enabled. Hint: systemctl ... ..." exit 6 fi