Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

Daemon for rox-filler

$
0
0
Hi to all friends .On my suse 13.1 i use rox-filler as default filemager .For mount unmount removable device, i found for any filesystem is need a different options and a right line on
/etc/fstab . On repository i don't found any right application to do this . Then I have decided to write the following script
------------start script ---------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
#################################################
# licenza LGPLv3 8/2014 gumo73@virgilio.it version 0.1 anfstab means a new fstab
# daemon to change just in time fstab for removable media /dev/sdp9
#################################################
#
#
#remove from anfstab.conf wrong lines
new_anfstab_conf()
{
nice grep -v "$1" /etc/anfstab.conf > /etc/anfstab.old
nice cp /etc/anfstab.old /etc/anfstab.conf
}
#delete line on fstab
new_fstab()
{
nice echo "new fstab remove /dev/sd$1" > /etc/fstab.old
nice grep -v ^/dev/sd$1 /etc/fstab > /etc/fstab.old
nice cp /etc/fstab.old /etc/fstab
}
#test filesystem of a new device ....
testdevice ()
{
if [ ! -n "$(cat /etc/anfstab.conf | grep ^"device" | cut -f 3 -d : | grep "sd$1" )" ]
then
nice mount -o ro,nosuid /dev/sd$1 /media/test/
fi
if [ -n "$(nice mount | grep /dev/sd$1 )" ]
then
for i in vfat ext2 ext3 ext4 xfs
do
if [ -n "$(nice df -t $i /media/test/ | grep /media/test)" ]
then
rsp=$i
break
fi
done
else
nice echo "error on test mount point for /dev/sd$1" >> /var/log/anfstab.log
unset rsp
fi
if [ -n "$( nice mount | grep "/media/test" )" ]
then
nice umount /media/test
fi
}
#if need add a new mount point and add right line to fstab
add_mountp()
{
testdevice "$1"
if [ -n "$rsp" ]
then
usr=$(nice who -u | grep " :0 " | cut -f 1 -d " ")
grp=$(nice cat /etc/anfstab.conf | grep "$rsp" | cut -f 1 -d ":" )
if [ -n "$( nice cat /etc/group | grep ^"$grp" | grep "$usr")" ]
then
opt=$(nice cat /etc/anfstab.conf | grep "$rsp" | cut -f 4 -d ":" )
if [ "yes_user" = "$(nice cat /etc/anfstab.conf | grep "$rsp" | cut -f 2 -d ":")" ]
then
opt="$opt,uid=$usr"
fi
if [ -n "$grp" ] && [ -n "$usr" ] && [ -n "$opt" ]
then
mkdir /mnt/usb$1
nice echo "/dev/sd$1 /mnt/usb$1 "$rsp" "$opt" 0 0" >> /etc/fstab
fi
fi
unset usr
unset grp
fi
}
#check if device is mounted or not ....
amusb()
{
for i in a b c d e f g h k i l m n o p
do
for j in 1 2 3 4 5 6 7 8 9
do
if [ -e /dev/"sd$i$j" ]
then
if [ ! -n "$( nice mount | grep "sd$i$j")" ]
then
if [ ! -e /mnt/"usb$i$j" ]
then
add_mountp "$i$j"
fi
fi
fi
done
done
}
#delete a unused mount point if device is not present...
del_mountp()
{
for i in a b c d e f g h k i l m n o p
do
for j in 1 2 3 4 5 6 7 8 9
do
if [ -d /mnt/usb$i$j ]
then
if [ ! -e /dev/"sd$i$j" ]
then
rm -r /mnt/usb$i$j
fi
fi
if [ ! -e "/dev/sd$i$j" ] && [ -n "$(cat /etc/fstab | grep ^/dev/sd$i$j )" ]
then
new_fstab "$i$j"
fi
done
done
}
#verifing configuration file
control_conf ()
{
for i in vfat ext2 ext3 ext4 xfs
do
if [ -n "$(nice cat /etc/anfstab.conf | grep $i | cat -n | grep 2)" ]
then
nice echo "error double filesystem option on $i" >> /var/log/anfstab.log
new_anfstab_conf "$i"
fi
if [ -n "$(nice cat /etc/anfstab.conf | grep $i )" ]
then
if [ "$(nice cat /etc/anfstab.conf | grep $i | cut -f 5 -d ":")" != "x" ]
then
nice echo "error number fields do not correct on $i line" >> /var/log/anfstab.log
nfstab_conf "$i"
fi
fi
rsp=$(nice cat /etc/anfstab.conf | grep $i | cut -f 1 -d ":" )
if [ ! -n "$(nice cat /etc/group- | grep ^$rsp )" ]
then
nice echo "error no valid group $grp for $i line">> /var/log/anfstab.log
new_anfstab_conf "$i"
fi
if [ -n "$(nice cat /etc/anfstab.conf | grep $i )" ] && [ ! -n "$(nice cat /etc/anfstab.conf | grep $i | cut -f 4 -d : )" ]
then
nice echo "error no optinos found for $i" >> /var/log/anfstab.log
fi
done
if [ -n "$(nice cat /etc/anfstab.conf | grep ^device )" ]
then
if [ ! -n "$(nice cat /etc/anfstab.conf | grep ^device | cat -n | grep 2)" ]
then
if [ "$(nice cat /etc/anfstab.conf | grep ^"device" | cut -f 2 -d :)" = "banned" ]
then
if [ ! -n "$(nice cat /etc/anfstab.conf | grep ^"device" | cut -f 4 -d :)" ]
then
if [ "$(nice cat /etc/anfstab.conf | grep ^"device" | cut -f 5 -d :)" = "x" ]
then
if [ ! -n "$(nice cat /etc/anfstab.conf | grep ^"device" | cut -f 3 -d : )" ]
then
new_anfstab_conf "device"
nice echo "error of syntax line: wrong sdx" >> /var/log/anfstab.log
fi
else
new_anfstab_conf "device"
nice echo "error of syntax line: wrong end letter " >> /var/log/anfstab.log
fi
else
nice echo "errror blank unrechable in line:device" >> /var/log/anfstab.log
new_anfstab_conf "device"
fi
else
nice echo "error of syntax device:banned:" >> /var/log/anfstab.log
new_anfstab_conf "device"
fi
else
nice echo "error of syntax device:line multiplies " >> /var/log/anfstab.log
new_anfstab_conf "device"
fi
fi
}
####################################################
#Main
####################################################
pd="$$"
echo -n "$pd" > /var/run/anfstab.pid
unset pd
if [ -f /var/log/anfstab.log ]
then
cp /var/log/anfstab.log /var/log/anfstab.log.old
echo "new log" > /var/log/anfstab.log
else
echo "new log" > /var/log/anfstab.log
fi
if [ ! -e /etc/anfstab.conf ]
then
echo "#Group:mount as user yes_user/no_user:type of filesystem:options to write on fstab:x:" > /etc/anfstab.conf
echo "#Device:banned:sdx,sdy::x:" >> /etc/anfstab.conf
echo "device:banned:sdz::x:" >> /etc/anfstab.conf
echo "cdrom:yes_user:vfat:users,uid=100,nosuid,rw,sync:x:" >> /etc/anfstab.conf
fi
if [ ! -f /etc/fstab.save ]
then
cp /etc/fstab /etc/fstab.save
fi
while [ -e /var/run/anfstab.pid ]
do
if [ ! -d /media/test/ ]
then
mkdir /media/test
fi
sleep 1
control_conf
sleep 1
amusb
sleep 1
del_mountp
sleep 2
done
exit 0;
-----------------------------------------------------------end script --------------------------------------------------------------------------------------------
I put it on /bin/anfstab . But i need help for best support on suse .
I have also written the start / stop utility
--------------------------start script ------------------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
#################################
# anfstab start/stop lgplv3 gumo73@virgilio.it
#################################
case $1 in
start )
nice /bin/anfstab &
sleep 2
if [ -f /var/run/anfstab.pid ]
then
echo "ANFSTAB START!"
else
echo "ANFSTAB DON'T START "
fi
;;
stop )
if [ -f /var/run/anfstab.pid ]
then
echo "ANFSTB STOP!!"
rm /var/run/anfstab.pid
fi
;;
restart )
if [ -f /var/run/anfstab.pid ]
then
echo "ANFSTB STOP!!"
rm /var/run/anfstab.pid
fi
nice /bin/anfstab &
sleep 2
if [ -f /var/run/anfstab.pid ]
then
echo "ANFSTAB START"
else
echo "ANFSTAB DON'T START "
fi
;;
status )
if [ -f /var/run/anfstab.pid ]
then
echo "ANFSTAB RUNNING! "
else
echo "ANFSTAB DON'T RUNNING"
fi
;;
esac
exit 0
----------------------------------------------end Script ----------------------------------------------------------------------------------------------------------------------------------------------

put it on /etc/init.d/local and link it ln -s /etc/init.d/local /etc/init.d/rc5.d/S99local
The permissions of execution are obligatory on /etc/init.d/local and /bin/anfstab
Demon need run as root . Daemon create a conf file on /etc/anfstab.conf and you can edit it for any filesystem vfat ext2 -3-4 xfs

The bug are how to restore saved fstab ,In case of anomalous turning off

thanks to all for the help O_o

Viewing all articles
Browse latest Browse all 40713

Trending Articles