Script for monitor porteus folder
Posted: 30 Jun 2017, 11:40
My script for monitor folders in porteus: base,modules,optional and /bin folder
I use it for my good feeling
I use it for my good feeling
Code: Select all
#!/bin/sh
# porteusGuard - porteus directory guard
#
# Copyright (c) 2017 Veselovsky <lukves at gmail.com>
# This software is licensed under the GPL v2 or later.
### BEGIN INIT INFO
# Provides: porteusGuard
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: porteusGuard start/stop script
# Description: Initialize porteusGuard
### END INIT INFO
MD=$(md5sum /etc/rc.d/rc.porteusGuard)
#
# all tests
#
# Try n^x and when files changed in base,modules,optional,
# or /bin then do halt. disconnect wlan0 a eth0, too..
#
# this utility create a 128m ramdisk for store
# listing files
#
prepare_all_tests() {
declare -i TIME
TIME=1
i=0
mkdir /mnt/ramdisk
mount -t tmpfs -o size=128m tmpfs /mnt/ramdisk
ls -l /bin > /mnt/ramdisk/root.lst
ls -l /mnt/sda1/porteus/base > /mnt/ramdisk/base.lst
ls -l /mnt/sda1/porteus/modules > /mnt/ramdisk/modules.lst
ls -l /mnt/sda1/porteus/optional > /mnt/ramdisk/opt.lst
while [ 1 ]; do
# selftest
RD=$(md5sum /etc/rc.d/rc.porteusGuard)
if [ "$MD" = "$RD" ]; then
echo "porteusGuard OK - nothing changed"
else
echo "RC SCRIPT CHANGED!!!"
ifconfig eth0 down
ifconfig wlan0 down
rm /mnt/ramdisk/*.lst
umount /mnt/ramdisk
rmdir /mnt/ramdisk
shutdown -h now
fi
# test for root
ls -l /bin > /mnt/ramdisk/root2.lst
diff /mnt/ramdisk/root.lst /mnt/ramdisk/root2.lst
if [ $? -ne 0 ]; then
echo "FILES IN ROOT ARE CHANGED"
echo "GOES SHUTDOWN!!!"
ifconfig eth0 down
ifconfig wlan0 down
rm /mnt/ramdisk/*.*
umount /mnt/ramdisk
rmdir /mnt/ramdisk
shutdown -h now
else
echo "porteusGuard root OK - nothing changed"
let i=0
fi
# test in base folder
ls -l /mnt/sda1/porteus/base > /mnt/ramdisk/base2.lst
diff /mnt/ramdisk/base.lst /mnt/ramdisk/base2.lst
if [ $? -ne 0 ]; then
echo "FILES IN base ARE CHANGED"
echo "GOES SHUTDOWN!!!"
ifconfig eth0 down
ifconfig wlan0 down
rm /mnt/ramdisk/*.*
umount /mnt/ramdisk
rmdir /mnt/ramdisk
shutdown -h now
else
echo "porteusGuard base OK - nothing changed"
let i=0
fi
# test in modules folder
ls -l /mnt/sda1/porteus/modules > /mnt/ramdisk/modules2.lst
diff /mnt/ramdisk/modules.lst /mnt/ramdisk/modules2.lst
if [ $? -ne 0 ]; then
echo "FILES IN modules ARE CHANGED"
echo "GOES SHUTDOWN!!!"
ifconfig eth0 down
ifconfig wlan0 down
rm /mnt/ramdisk/*.*
umount /mnt/ramdisk
rmdir /mnt/ramdisk
shutdown -h now
else
echo "porteusGuard modules OK - nothing changed"
let i=0
fi
# test in base folder
ls -l /mnt/sda1/porteus/optional > /mnt/ramdisk/opt2.lst
diff /mnt/ramdisk/opt.lst /mnt/ramdisk/opt2.lst
if [ $? -ne 0 ]; then
echo "FILES IN optional ARE CHANGED"
echo "GOES SHUTDOWN!!!"
ifconfig eth0 down
ifconfig wlan0 down
rm /mnt/ramdisk/*.*
umount /mnt/ramdisk
rmdir /mnt/ramdisk
shutdown -h now
else
echo "porteusGuard optional OK - nothing changed"
let i=0
fi
sleep $TIME;
done
# echo $i
}
case "$1" in
status)
cat /etc/porteus-version
;;
stop)
rm /mnt/ramdisk/*.*
umount /mnt/ramdisk
rmdir /mnt/ramdisk
;;
start|\
restart|\
force-reload)
prepare_all_tests &
;;
*)
echo "Usage: $0 start|stop|restart|force-reload|status" 1>&2
exit 3
;;
esac
exit 0