/bin/umount

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

/bin/umount

#1 Post by Karl Godt »

Style in bash using arrays
as here : http://murga-linux.com/puppy/viewtopic.php?t=86617
for that remark in the original
/bin/umount :
FULLCMD="`echo -n " $*" | sed -e 's/ \-n / /g'`" #unsatisfactory!

Code: Select all

#!/bin/bash
# Karl Reimer Godt July 2013

[ "$*" ] || exec busybox umount

sync

USE_FULL='';

ARGS=`set | grep -E 'ARGV|ARGC'`
ARGSV=`echo "$ARGS" | grep -m1 ARGV | grep -o '(.*)$' | sed 's|^(||;s|)$||' `
ARGSC=`echo "$ARGS" | grep -m1 ARGC | cut -f2 -d'"'`
c=$ARGSC

while read p
do
p="${p#*=}"
p="${p/#\"/}"
p="${p/%\"/}"
P[$c]="$p"
(( c-- ))
done<<EOI
$(echo "$ARGSV" | sed 's|" \[|"\n\[|g')
EOI

function_rox_n_fuser(){
 [ -e "${*}" ] || return 0
 (pidof ROX-Filer || pidof rox) && rox -D "${*}"
 sleep 0.02 #change if req
 busybox fuser -m "${*}"
 sleep 0.02 #change if req
}

for k in `seq 1 1 $ARGSC`
do
case "${P[$k]}"
in
/*)
if [ -d "${P[$k]}" ] ; then
 MNTPTS_ALL=`awk '{print $1"+++"$2}' /proc/mounts`
 MNTPTS_ALL=`busybox echo -e "$MNTPTS_ALL"`
 DEVNAMEP=`echo "$MNTPTS_ALL" | grep -m1 -w "${P[$k]}"`
 DEVNAMEP="${DEVNAMEP%%+++*}"
 MNTPT_M="${P[$k]}"
 function_rox_n_fuser "$DEVNAMEP"
elif [ -b "${P[$k]}" ] ; then
 function_rox_n_fuser "${P[$k]}"
 MNTPTS_ALL=`awk '{print $1"+++"$2}' /proc/mounts`
 MNTPTS_ALL=`busybox echo -e "$MNTPTS_ALL"`
 MNTPT_D=`echo "$MNTPTS_ALL" | grep -m1 -w "${P[$k]}"`
 MNTPT_D="${MNTPT_D#*+++}"
 DEVNAMEP="${P[$k]}"
fi
;;
--version)
echo "$0 : Puppy Linux Wrapper bash shell script:"
busybox umount --help
echo "$0 : defaults using -dr"
echo "$0 : OR /bin/umount-FULL:"
USE_FULL=YES
;;
--*) #exec umount-FULL ${P[@]} ;;
USE_FULL=YES
;;
esac
done

[ "$MNTPT_M" -o "$MNTPT_D" ] || MOUNTEDSB=`tac /proc/mounts`

[ "$USE_FULL" ] && {
umount-FULL "${P[@]}"
RETVAL=$?
} || {
busybox umount -dr "${P[@]}"
RETVAL=$?
}

sleep 0.02s #change if req
IFS='. ' read UPtime restU RUNtime restR </proc/uptime
dmesg | tail | grep -w "$UPtime"

[ $RETVAL = 0 ] || exit $RETVAL

  if [ "$MNTPT_M" ] ; then OLDMOUNTPT="$MNTPT_M"
elif [ "$MNTPT_D" ] ; then OLDMOUNTPT="$MNTPT_D"
else
sleep 0.02s #change if req
[ -f /proc/mounts ] || { echo "No /proc/mounts ." ; exit $RETVAL ; } ##+++2013-08-10 in case of umount -a 
MOUNTEDSA=`tac /proc/mounts`
OLDMOUNTS=`echo "$MOUNTEDSB" | grep -v "$MOUNTEDSA"`
OLDMOUNTPT=`echo "$OLDMOUNTS" | awk '{print $2}'`
OLDMOUNTPT=`echo -e "$OLDMOUNTPT" | head -n1`
  fi

[ "$MNTPT_M" -o "$MNTPT_D" ] || {
[ "$MOUNTEDSB" -a "$MOUNTEDSA" -a "$MOUNTEDSB" = "$MOUNTEDSA" ] && {
echo "NO CHANGES.";exit $RETVAL; } || {
[ "$MOUNTEDSB" -a "$MOUNTEDSA" -a "$MOUNTEDSB" != "$MOUNTEDSA" ] || {
echo "NO CHANGES.";exit $RETVAL; }; }; }

[ "$OLDMOUNTPT" -a -d "$OLDMOUNTPT" -a ! "`ls -A "$OLDMOUNTPT"`" ] && rmdir "$OLDMOUNTPT"

[ "$DISPLAY" ] || { echo "NO DISPLAY.";exit $RETVAL; }

#. /etc/eventmanager
#[ "$ICONDESK" = true ] || exit $RETVAL
#[ "$ICONPARTITIONS" = true ] || exit $RETVAL

[ "$DEVNAMEP" ] || {
DEVNAMEP=`echo "$OLDMOUNT" | awk '{print $1}'`
DEVNAMEP=`echo -e "$DEVNAMEP"`
}
echo "${DEVNAMEP##*/}"
[ -d /root/.pup_event/drive_"${DEVNAMEP##*/}" ] || { echo "NO drive_${DEVNAMEP##*/} Directory.";exit $RETVAL ; }

( pidof ROX-Filer || pidof rox ) || { echo "ROX-Filer or rox not running.";exit $RETVAL ; }
pidof pup_event_frontend_d || { echo "pup_event_frontend_d not running.";exit $RETVAL ; }

case ${DEVNAMEP##*/} in
fd*)      CATEGORY=floppy  ;;
scd*|sr*) CATEGORY=optical ;;
mmc*|sd*|hd*)
DEVNAME=`echo "$DEVNAMEP" | sed 's%p[0-9]*$%%;s%[0-9]*$%%'`
PROBEDISK2=`probedisk2`
CATEGORY=`echo "$PROBEDISK2" | grep -m1 -w "$DEVNAME" | cut -f2 -d'|'`
;;
*) echo "Not a block device for pup_event* ICONDESK.";exit $RETVAL ;;
esac

DISK_FREE=`df`

. /etc/rc.d/functions4puppy4
echo "$DISK_FREE" | grep -w "^$DEVNAMEP" | grep -E ' /initrd/| /$' &&
{
      icon_mounted_func "${DEVNAMEP##*/}" $CATEGORY; } || {  #see functions4puppy4
      icon_unmounted_func "${DEVNAMEP##*/}" $CATEGORY;
}

exit $RETVAL
edit 2013-08-10 : Added test if /proc/mounts exists in case of umount -a
Last edited by Karl Godt on Sat 10 Aug 2013, 19:24, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Hello, Karl.

I tried your script and nothing happened.
I probably misunderstood something.
(See attached picture.)

Best regards.

musher0
Attachments
umount-krg_sh-2013-07-09.jpg
(74.96 KiB) Downloaded 212 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

Hey, Christian . Sorry, if you misunderstood something .

It is a re-written /bin/umount .

Code: Select all

umount &
does it do something extra ( eg unmounting of all drives ? ) in your OS ?

If so , you probably may run fatdog , lighthouse , saluki or igu's roar-ng .
These derivates tend to have several until lots of code changes .

bash-3.00# filemnt /JUMP-2/pup-430.sfs
- /usr/sbin/filemnt as an example that calls /bin/umount, if the .sfs is mounted -
should give some output like
----------------------------------------------------------------------
IMGBASE='pup-430.sfs' imgFileBASE='pup-430.sfs'
Warning: Input Method Open Failed
Warning: Unable to load any usable fontset
1 /mnt/pup\-430\.sfs\.18022
2 /dev/loop0
3
4
------------
9544
13 305 308 518 520 522 772 6702 6719 6727 6741 6744 6746 6749 6758 6759 6776 8018 8050 8053 8096 8098 8099 8276 9382 9484 9485 9489 9515 9521 9529 9530 9531 9535 9537 9539 9544 9623 9624 9626 10958 11103 11106 11107 12723 13113 13320 13507 13570 16489 19434
loop0
NO drive_loop0 Directory.
------------
/usr/sbin/filemnt UnMount: /JUMP-2/pup-430.sfs
bash-3.00#
- though my filemnt is also hacked a bit to give some more verbosity -
.

Post Reply