Page 1 of 2

Mount_all3: bash script automounts drives at startup

Posted: Wed 27 Oct 2010, 02:59
by big_bass
this is a script I wrote to auto mount drives at start up
and then place the folders mounted on the desktop

make it executable and
place it in /root/Startup no user interaction


cd and dvd drives are not mounted

the writing to the desktop was tricky generating a new PuppyPin
for whatever drives you have and doing all this without it being event driven fully automatic




if you notice that the code to mount and draw to the desktop is very compact and doesnt use any of these listed below
pmount
gtkdialog
eventmanager
partprobe,
probedisk and a few other small scripts/apps that are used while mounting



special features will be added
here's a nice little trick if you used my code in the mount_all3
a file got generated called PuppyPin-old
so if you need or want to toggle off the folder icons you could by doing this code snip

Code: Select all

rox --pinboard=/root/Choices/ROX-Filer/PuppyPin-old
and to get the folders back again

Code: Select all

rox --pinboard=/root/Choices/ROX-Filer/PuppyPin

MOUNT_ALL3

Code: Select all

#!/bin/bash

# call it  mount_all3 updated 11-06-2010 Joe Arose
# auto_mount all drives non cd and dvd 
# now if you  have to mount stuff from the command line only  here's  one
# don't unmount a drive that has your save file !
# this doesnt depend on xdialog

# added folders to be auto drawn and updated on the desktop
# with auto generating of the xml PuppyPin depending
# on whichever drives are used note that this is not event driven
# it is meant to be placed in /root/Startup so there is no user interaction
# major changes in how a list of drives is generated and multiple
# screen displays are detected

# special thanks to aragon for this code snip below to detect the width and height
#SCW=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
#SCH=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`

# this started as a special request for abushcrafter for something simple to auto mount
# then grew into writing to the desktop  also with multiple screen sizes

# thanks for catching the loop error  amigo


temp_file="/tmp/pin-fix"

rm -f /tmp/pin-fix

rm -f /tmp/NTFS_LIST
rm -f /tmp/FAT_LIST
rm -f /tmp/Linux_LIST

echo >/tmp/list_of_drives


#*************************************************************************
fdisk -l | grep NTFS | cut -f 1 -d ' '| sed 's/\/dev\///'>/tmp/NTFS_LIST
  if [ "$?" == "0" ]; then

      echo "NTFS_LIST written to /tmp/NTFS_LIST"

        NTFS_LIST=$(</tmp/NTFS_LIST)

        for ntfs_drive in  `cat /tmp/NTFS_LIST` ; do
 
        mkdir -p /mnt/$ntfs_drive
        mount -t ntfs-3g /dev/$ntfs_drive /mnt/$ntfs_drive
        cat /tmp/NTFS_LIST >>/tmp/list_of_drives 
         
done
  fi # bypass the mounting if no ntfs drive found


 
#*************************************************************************
fdisk -l | egrep '(FAT32|FAT16)'  | cut -f 1 -d ' '| sed 's/\/dev\///'>/tmp/FAT_LIST
  if [ "$?" == "0" ]; then

     echo "FAT_LIST written to /tmp/FAT_LIST"

       FAT_LIST=$(</tmp/FAT_LIST)
       for fat_drive in  `cat /tmp/FAT_LIST` ; do
 
       mkdir -p /mnt/$fat_drive
       mount -t vfat /dev/$fat_drive /mnt/$fat_drive
       cat /tmp/FAT_LIST >>/tmp/list_of_drives   
       
done 
  fi # bypass the mounting if no fat drives found


#*************************************************************************
fdisk -l | grep Linux | egrep -v "swap" | cut -f 1 -d ' '| sed 's/\/dev\///'>/tmp/Linux_LIST
  if [ "$?" == "0" ]; then

      echo "Linux_LIST written to /tmp/Linux_LIST"

        Linux_LIST=$(</tmp/Linux_LIST)

        for Linux_drive in  `cat /tmp/Linux_LIST` ; do
 
        mkdir -p /mnt/$Linux_drive
        mount  /dev/$Linux_drive /mnt/$Linux_drive
        cat /tmp/Linux_LIST >>/tmp/list_of_drives   
           
 
done
   fi # bypass the mounting if no Linux drive found


# refresh icons
 rox -p /root/Choices/ROX-Filer/PuppyPin   


# set up positions of x and y to print the folder icons on the desktop
# they get repositioned depending on what drives you have. getting added to the right
# by the order they got detected

# preset base values here maybe a test to see what screen size you are using goes here
x_val="64"

c_val="64" #this is the constant


#the y_val="" gets auto detected and then adjusted here
SCW=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
SCH=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`
echo "screen width" $SCW x "height" $SCH


 

 if [[ $SCH = "480" ]]; then
               echo " the condition is true  --->  $SCH "   
             
               #do something here
               y_val="340"
 
 
 
 
 elif [[ $SCH = "600" ]]; then
               echo " the condition is true  --->  $SCH "   
               
               #do something here
               y_val="472"
 
 
 
 
 
 elif [[ $SCH = "768" ]]; then
               echo " the condition is true  --->  $SCH "   
               
               #do something here
               y_val="628"
 
 
 
 
 
 
 elif [[ $SCH = "864" ]]; then
               echo " the condition is true  --->  $SCH "   
               
               #do something here
                y_val="726"
 
 
 
 
 elif [[ $SCH = "960" ]]; then
               echo " the condition is true  --->  $SCH "   
               
               #do something here
                 y_val="822"
 
 
 
 elif [[ $SCH = "1024" ]]; then
               echo " the condition is true  --->  $SCH "   
               
               #do something here
                y_val="882"
 
 
 
 fi



# to remove any chance of double writes to screen
cat /tmp/list_of_drives | sort -u >/tmp/list_of_drives

for drive in  `cat /tmp/list_of_drives` ; do

#    edit this with much care it was tedious to format it. Save a copy first  of your PuppyPin !
         
     echo "  <"icon x='"'$x_val'"' y='"'$y_val'"' label='"'$drive'"'">"/mnt/$drive"<"/icon">" >>$temp_file
   
#    keep adding 64 to the x number to allow for spacing of the icons to be uniform
     let x_val="$x_val + $c_val"
       
     
done

#----------------------------------------------------
#Append content of file year.txt at line  3 of data.txt.

#sed '3 r year.txt' data.txt > newdata.txt

#year.txt=/tmp/pin-fix    data.txt=/root/Choices/ROX-Filer/PuppyPin  newdata.txt=/root/Choices/ROX-Filer/PuppyPin4
#----------------------------------------------------

#remove out the /mnt/$drive  because it keeps getting appended this wipes it clean each time
cat /root/Choices/ROX-Filer/PuppyPin   | egrep -v "/mnt" >/root/Choices/ROX-Filer/PuppyPin1
mv /root/Choices/ROX-Filer/PuppyPin1  /root/Choices/ROX-Filer/PuppyPin


sed '10 r /tmp/pin-fix' /root/Choices/ROX-Filer/PuppyPin > /root/Choices/ROX-Filer/PuppyPin4
mv /root/Choices/ROX-Filer/PuppyPin /root/Choices/ROX-Filer/PuppyPin-old
mv /root/Choices/ROX-Filer/PuppyPin4  /root/Choices/ROX-Filer/PuppyPin

   
rox -p /root/Choices/ROX-Filer/PuppyPin 



 

 







Joe

Posted: Wed 27 Oct 2010, 08:53
by sc0ttman
awesome!

Posted: Wed 27 Oct 2010, 15:24
by aragon
hi big_bass,

i know you know but maybe it saves some seconds:

Code: Select all

SCW=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
SCH=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`
aragon

Posted: Thu 28 Oct 2010, 13:14
by big_bass
Hey aragon


I like it :D
a very linux way of doing it and I will use it
thanks

Code: Select all

#!/bin/bash

# 
# simple   test  using Xdialog


SCW=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
SCH=`xwininfo -root | grep '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`
echo "screen width" $SCW x "height" $SCH



Xdialog --title "sceen size check " \
                --infobox "\n screen width $SCW x height $SCH\n" 0 0 4000




the "puppy way" would be to read this file
/etc/videomode

if you notice that the code above to mount and draw to the desktop is very compact and doesnt use any of these listed below
pmount
gtkdialog
eventmanager
partprobe,
probedisk and a few other small scripts/apps that are used while mounting

*I dont like to use "PuppyPin" but on the standard versions I will fix that

special features will be added
here's a nice little trick if you used my code in the mount_all2
a file got generated called PuppyPin-old
so if you need or want to toggle off the folder icons you could by doing this code snip

Code: Select all

rox --pinboard=/root/Choices/ROX-Filer/PuppyPin-old
thanks aragon


Joe

Posted: Thu 28 Oct 2010, 15:41
by amigo
Another small thing, Joe. I wouldn't mount the drives as 'loop' mounts since they are real partitions. Mounting them with the 'loop' option will disable any DMA access to the drives. 'loop' is only needed for partition images which you are filtering out of the list.

impressive

Posted: Thu 28 Oct 2010, 20:02
by vovchik
Dear Joe and aragon,

This is starting to look very good. Thanks....

With kind regards,
vovchik

Posted: Fri 29 Oct 2010, 02:31
by big_bass
Hey amigo!

Thanks I'll fix it and remove the "loop" I recycled a snip of code from my dragNdrop SFS mounter a cut and paste :oops:

Thanks for catching that and taking the time to post

as always any suggestions are always very welcomed
I am adding the correct file system checking for the mount
thanks
Joe

Posted: Sun 31 Oct 2010, 14:45
by abushcrafter
The new version is a big improvement with the refreshing of "PuppyPin". So I have commented out the separate drive icon code. There is one big bug though. The puppy home partition drive icon has the wrong icon and when clicked on give me three Rox-Filer windows. Two are at "/mnt/sda1" the other one is at "/initrd/mnt/dev_save".
big_bass wrote:this started as a special request
I know and I am very gratefully.

Perhaps the simplest thing would be some thing like this:
This only works with drive partition icons enabled to my knowledge.

Code: Select all

#!/bin/bash
# Half the code is from the "mount_all2" script by "big_bass"

#----------------------------------------
# generate  /tmp/list_of_drives
#----------------------------------------
#to be safe remove out the loop mounted stuff and the swap partion if there is one from the list
blkid  | egrep '(hd|sd)' | egrep -v "/dev/loop*" | egrep -v "swap" | cut -f 1 -d ':' | sed 's/\/dev\///'>/tmp/list_of_drives 

for drive in  `cat /tmp/list_of_drives` ; do
	#Insert code here for extracting "args" parameter of drive partition icons from "/root/Choices/ROX-Filer/PuppyPin" and setting it to the variable "$driveargs".

	/root/.pup_event/drive_$drive/AppRun "$driveargs"
done

Posted: Tue 02 Nov 2010, 18:03
by big_bass
ok here is the latest version 3
I will update the first post

I had to go about this differently to get the correct mount command
for each drive

@Hey vovchik good to hear from you

*mount does well guessing a linux partition but not for fat and ntfs correctly
if you find something that needs adjusting let me know this is working correctly for me

Joe



special features will be added
here's a nice little trick if you used my code in the mount_all3
a file got generated called PuppyPin-old
so if you need or want to toggle off the folder icons you could by doing this code snip

Code: Select all

rox --pinboard=/root/Choices/ROX-Filer/PuppyPin-old
and to get the folders back again

Code: Select all

rox --pinboard=/root/Choices/ROX-Filer/PuppyPin

Posted: Wed 03 Nov 2010, 10:11
by esmourguit
Bonjour à tous,
Very good job. I tested version 3 in Quirky 1.3.0,
It works wonderfully.
But there is still a part of the bug which abushcrafter was talking about in previous post.
There is one big bug though............ and when clicked on give me three Rox-Filer windows. Two are at "/mnt/sda1" the other one is at "/initrd/mnt/dev_save".
Cordialement ;)

Posted: Wed 03 Nov 2010, 15:49
by big_bass
I posted the wrong code :? its fixed I am testing live cd now as I write

I cant reproduce that error but I am trying to get it

my home directory is correct on my installed version

what does your symlink read when you hover over it with the mouse for home ?
Joe

Posted: Wed 03 Nov 2010, 16:03
by abushcrafter
Its with the original drive icon not yours created by mount_all2/3.

Posted: Wed 03 Nov 2010, 16:10
by abushcrafter
There is a screen shot.

Posted: Wed 03 Nov 2010, 16:18
by big_bass
ok now I get it I'll fix that
thanks for posting

Joe

Posted: Thu 04 Nov 2010, 16:41
by big_bass
well the conflict is in the / root/.pup_event/drive_hda1/AppRun
in your case sda1

*I dont know if the AppRun in your version differs than mine so I posted just the code
I added starting with the single plus"+" sign starting on line 186

what happens there is every thing gets mounted thats why the three folders
caused by the AppRun code (non related to the code I wrote)

I have to really dig in that and make a filter for any drives getting mounted in more than one place in the AppRun and have it select only one

I got a simple test working but needs to be improved if even more mounts are present
with the same hard drive number

here's what I got for a temp fix so far (suggestions welcomed)
this does eliminate the problem for me on my box with my drive selection
note :I am running live cd so I dont have a save file

Code: Select all

--- /root/.pup_event/drive_hda1/AppRun-old	2008-10-20 07:12:48.000000000 +0800
+++ /root/.pup_event/drive_hda1/AppRun	2010-10-04 10:14:55.000000000 +0800
@@ -183,7 +183,13 @@ if [ "$FSTYPE" != "" ];then
    [ "`readlink /mnt/home`" = "$MNTPT" ] && MNTPT="/mnt/home"
   fi
   #exec rox -x /mnt/$ONEDRVNAME -d /mnt/$ONEDRVNAME
+  mount | grep "/initrd/mnt/dev_ro2" && mount | grep "/mnt/$ONEDRVNAME" 
+  if [[ "$?" == 0 ]];then
+  echo "mounted on more than one place open only one rox folder"
+  exec rox -d /initrd/mnt/dev_ro2 
+  else 
   exec rox -x $MNTPT -d $MNTPT
+  fi
  fi
 fi
 
I realize your folders are produced with
/initrd/mnt/dev_save


so your fix would be instead using this

Code: Select all

+  mount | grep "/initrd/mnt/dev_save" && mount | grep "/mnt/$ONEDRVNAME" 
+  if [[ "$?" == 0 ]];then
+  echo "mounted on more than one place open only one rox folder"
+  exec rox -d /initrd/mnt/dev_save 
+  else 
   exec rox -x $MNTPT -d $MNTPT
+  fi
  fi
 fi

Posted: Thu 04 Nov 2010, 17:57
by abushcrafter
Your fix works :D. To apply this for remasters/installs (.E.G. USB Flash Drive install.) where you want it to work on whatever setup it is plugged into. Do this (Though I have not tested it.):

The drive icons scripts in "/root/.pup_event" are all the same. The difference is the parameters they are given when they are run. The source script they are copied from is "/usr/local/bin/drive_all". So apply the fix to that one. If you are doing this on the system you are booted in. You will need to regenerate your drive icons. By a reboot maybe? Or deleting the contents of "/root/.pup_event" then restarting X?

Posted: Fri 05 Nov 2010, 07:51
by esmourguit
Bonjour à tous,

I think I did not know how to apply the change in the script because I have not had the desired result.
My "home" partition is sda2.

Cordialement ;)

Posted: Fri 05 Nov 2010, 14:22
by big_bass
esmourguit wrote:Bonjour à tous,

I think I did not know how to apply the change in the script because I have not had the desired result.
My "home" partition is sda2.

Cordialement ;)
Hey esmourguit




run this in a terminal
tar gzip the file drive_all then move it to root

Code: Select all

tar -czf /usr/local/bin/drive_all.tar.gz  /usr/local/bin/drive_all
mv /usr/local/bin/drive_all.tar.gz /root
attach your file to the forum
I will patch it and send it back
then please let me know if it works or not correctly

*I made some more improvements since the first patch

thanks for the feedback
Joe
-------------------what was changed ---------------------------------

Code: Select all

--- /usr/local/bin/drive_all	2008-10-20 07:12:48.000000000 +0800
+++ /mnt/hda4/drive_all	2010-10-05 07:49:56.000000000 +0800
@@ -11,6 +11,11 @@
 #v403 icon menu, can call with 'unmount', 'eventmanager' and 'pmount_<DRV_CATEGORY>' params.
 #v411 added 'quiet' option for vfat, suppresses error msg when file attribs not preserved on copy.
 
+
+##big_bass  add filtering for /initrd/mnt/dev_ro2 and /initrd/mnt/dev_save
+#when this drive is also mounted on /mnt/   to remove multiple rox windows opening 
+
+
 FSTYPE=""
 [ $2 ] && FSTYPE="$2" #see pup_eventd
 
@@ -183,9 +188,28 @@ if [ "$FSTYPE" != "" ];then
    [ "`readlink /mnt/home`" = "$MNTPT" ] && MNTPT="/mnt/home"
   fi
   #exec rox -x /mnt/$ONEDRVNAME -d /mnt/$ONEDRVNAME
+  
+  #big_bass  add filtering for /initrd/mnt/dev_ro2 and /initrd/mnt/dev_save
+  #when this drive is also mounted on /mnt/   to remove multiple rox windows opening 
+  mount | grep "/initrd/mnt/dev_ro2" && mount | grep "/mnt/$ONEDRVNAME"
+  if [[ "$?" == 0 ]];then
+  echo "mounted on more than one place open only one rox folder"
+  exec rox -d /initrd/mnt/dev_ro2
+  fi
+  
+  mount | grep "/initrd/mnt/dev_save" && mount | grep "/mnt/$ONEDRVNAME"
+  if [[ "$?" == 0 ]];then
+  echo "mounted on more than one place open only one rox folder"
+  exec rox -d /initrd/mnt/dev_save
+  
+  else
   exec rox -x $MNTPT -d $MNTPT
+  fi
  fi
 fi
+ 
+
+
 
 
 #NOTE: if pmount already running, don't really want to kill then restart,

Posted: Fri 05 Nov 2010, 17:48
by esmourguit
Bonjour à tous,
Thank you for your help.
Here is the mount_all3 file.
Cordialement ;)

Posted: Sat 06 Nov 2010, 00:45
by big_bass
run this in a terminal
tar gzip the file drive_all then move it to root

Code: Select all

tar -czf /usr/local/bin/drive_all.tar.gz  /usr/local/bin/drive_all
mv /usr/local/bin/drive_all.tar.gz /root
attach your file to the forum
I will patch it and send it back


you sent me the mount_all3 that doesnt need the patch

the file that needs patching is called drive_all
it is also the AppRun thats where the trouble is

Thanks