In this tip, I want to demonstrate how to write a shell script to lock a folder on openSUSE desktop. Now suppose that there are many folders on your Desktop and you want to lock down only one or some folders to keep from unwanted user change. This means that user can move, view ,or delete your folder (the locked folder) when they are being on Desktop, but those folder will be back on Desktop again when the computer is restarted.
I think the above idea is similar to
DeepFreeze or
KioskTool concept. but DeepFreeze or KioskTool will lock the whole system or Desktop environment, your can not specify the folder.
Here are the basic steps to do the work as what I described above:
1. Download file
install.sh to somewhere in your computer
2. Go to
Konsole and log in as
root
3. Go to the location of
install.sh then run command
./install
4. Input
folder name that you want to lock then you are done
Here is detail of install.sh file:
#!/bin/bash
#input folder name, suppose that folder is located in desktop
finputbox()
{
dialog --title "Inputbox - To take input from you" --backtitle "Linux Shell\
Script Tutorial" --inputbox "Enter folder name on Desktop please" 8 60 2>/tmp/input.$$
sel=$?
na=`cat /tmp/input.$$`
case $sel in
0) echo "Folder name is $na" ;;
1) echo "Cancel is Press" ;;
255) echo "[ESCAPE] key pressed" ;;
esac
checkdir="/home/$USER/Desktop/$na"
if [ -d "$checkdir" ]
then
num=1
else
num=2
fi
}
#check folder is exist?
num=2
echo $num
while [ $num -eq 2 ]
do
finputbox
done
#create backup file
touch /home/backup.sh
chmod 777 /home/backup.sh
cd /home
echo "#!/bin/bash" > backup.sh
echo "rm -f /root/bakcup_file.tar" >> backup.sh
echo "tar -cpPf /root/bakcup_file.tar /home/$USER/Desktop/$na" >> backup.sh
echo "chmod 777 /root/bakcup_file.tar" >> backup.sh
echo "exit 0" >> backup.sh
#run backup file to back up the folder that you input
./backup.sh
#create restoration file
touch /etc/init.d/restore.sh
chmod 777 /etc/init.d/restore.sh
cd /etc/init.d/
echo "#!/bin/bash" > restore.sh
echo "rm -fR /home/$USER/Desktop/$na" >> restore.sh
echo "tar -xpPf /root/bakcup_file.tar" >> restore.sh
echo "exit 0" >> restore.sh
#Write to boot script: inittab, rc
grep "/etc/init.d/restore.sh" /etc/inittab >/tmp/inittab.$$
grep "/etc/init.d/restore.sh" /etc/init.d/rc >/tmp/rc.$$
ninittab=`cat /tmp/inittab.$$`
nrc=`cat /tmp/rc.$$`
if [ "$ninittab" != "/etc/init.d/restore.sh" ]
then
echo "/etc/init.d/restore.sh" >> /etc/inittab
fi
if [ "$nrc" != "/etc/init.d/restore.sh" ]
then
cd /etc/init.d/
sed -e 's/exit 0//' rc > file.out
echo "/etc/init.d/restore.sh" >> file.out
echo "exit 0" >> file.out
cat file.out > rc
fi
# remove template file
rm -f /tmp/input.$$
rm -f /tmp/ninittab.$$
rm -f /tmp/nrc.$$
exit 0
Naturally, if you want the backup tarball or scripts stored somewhere else or named something else, just modify the scripts to indicate the correct directories and filenames.
Any feedback is warmly welcome