Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 23 Sep 2018, 06:37
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
SlocateGUI with apptree
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 3 [36 Posts]   Goto page: Previous 1, 2, 3 Next
Author Message
smokey01


Joined: 30 Dec 2006
Posts: 2765
Location: South Australia :-(

PostPosted: Thu 20 Aug 2015, 19:56    Post subject:  

stemsee, you also need to add slocate to the group file for first time users.
_________________
Software <-> Distros <-> Tips <-> Newsletters
Back to top
View user's profile Send private message Visit poster's website 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Sun 23 Aug 2015, 08:53    Post subject:  

@01smokey

Thanks! I will write a suitable pinstall for the next issue.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Sat 29 Aug 2015, 01:14    Post subject:  

Unbelievable ... I found another bug error in a link command which meant that only sys db was available for searches. How does this happen? I cannot believe I am really so clumsy!! With add to group pinstall.
SlocateGUI-i386.pet
Description 
pet

 Download 
Filename  SlocateGUI-i386.pet 
Filesize  35.76 KB 
Downloaded  167 Time(s) 
slocateGUI-x86_64.pet
Description 
pet

 Download 
Filename  slocateGUI-x86_64.pet 
Filesize  28.92 KB 
Downloaded  167 Time(s) 
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Thu 10 Sep 2015, 03:29    Post subject:  

Finally I spent some time considering how to overcome the problem of duplicates turning up in search results. This error was caused by the fact that i linked default slocate.db to sys and both got searched. Solved by grep --invert-match filtering out sys just before search.

Second problem was that default slocate.db must be searched or fatal error occurred. This meant that you could not search sda5 only, without also searching default db. Solved by renaming default db and touching slocate.db (empty file). Then restoring default db after search. This only occurs when sys is not selected as search db.

Also found missing $ symbol in link command section.
SlocteGUI-100915.pet
Description 
pet

 Download 
Filename  SlocteGUI-100915.pet 
Filesize  35.35 KB 
Downloaded  172 Time(s) 
Back to top
View user's profile Send private message MSN Messenger 
Pelo

Joined: 10 Sep 2011
Posts: 12591
Location: Mer méditerrannée (1 kms°)

PostPosted: Mon 28 Sep 2015, 14:07    Post subject: making a full pet easily : won'it ?  

slocateGui works. please try to explain what mean codes that you type in terminal. English for us is difficult enough, but understand your linuxian language is awfull. try to make the jargon understood.
I know gnewpet, i know pfind.
Does SlocatGui will give me better résults.
My problem with gnewpet are dependancies, apptree will list them and allow me making a full pet easily : won'it ?
What is db ; database ?
Added the ability to link -s file : what is a s file ?
"/etc/updatedb.conf must be edited to remove /mnt from exluded dirs. Then all conneted partitions will be mounted and indexed. If you wish to idex only system then the command is" I want to choose what partition will be searched, not all partitions, how can i choose ?

sh-4.1# apptree
/usr/bin/apptree: line 7: /tmp/name: No such file or directory
sh-4.1#

_________________
Passenger Pelo ! don't ask him to repair the aircraft. Don't use him as a demining dog .... pleeease.
Back to top
View user's profile Send private message Yahoo Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Tue 29 Sep 2015, 05:19    Post subject:  

@pelo

Sorry for my always hurried and abbreviated explanations. Yes I make too many assumptions about the reader.

After you input your search term you then get a gui to select which partition to search 1 or many; system or external partition.

If you want always to search every partition then yes remove /mnt from /etc/updatedb.conf (not recommended!)

The link command format is 'ln -s "/path/file" "/path/file-link-name"', but you do not need to worry about that just choose file to link and then give the link path/name.

apptree is a separate script at the moment. It builds a pet/sfs file from a /root/.packages/'app-name.files' list.

Best is just to install it and try it but be careful with the 'rm' or 'mv' commands, as they work really really well. Worst case scenario is that you might have to reboot with no savefile.

I hope this helps.
stemsee
Back to top
View user's profile Send private message MSN Messenger 
Pelo

Joined: 10 Sep 2011
Posts: 12591
Location: Mer méditerrannée (1 kms°)

PostPosted: Thu 08 Oct 2015, 13:22    Post subject: merci stemsee  

merci stemsee i'am going to test it.
_________________
Passenger Pelo ! don't ask him to repair the aircraft. Don't use him as a demining dog .... pleeease.
Back to top
View user's profile Send private message Yahoo Messenger 
Pelo

Joined: 10 Sep 2011
Posts: 12591
Location: Mer méditerrannée (1 kms°)

PostPosted: Fri 16 Oct 2015, 00:09    Post subject: Musher0, our canadian colleague will explain me more
Subject description: slocate explained in french
 

Musher0, our canadian colleague will explain me more, as he settled in Quebec, and he is bilingual french english Smile
slocate explained in french

_________________
Passenger Pelo ! don't ask him to repair the aircraft. Don't use him as a demining dog .... pleeease.
Back to top
View user's profile Send private message Yahoo Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Wed 13 Jan 2016, 06:04    Post subject:  

Slight update
i386
https://drive.google.com/file/d/0B_gaN1QXLwtkcE9leFl5VzJ6aFU/view?usp=sharing

x64
https://drive.google.com/file/d/0B_gaN1QXLwtkOVJmSHZTVi1IOG8/view?usp=sharing
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Fri 22 Jan 2016, 18:34    Post subject:  

I have sorted out some updating failures, finally!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Sun 24 Jan 2016, 17:09    Post subject:  

slocategui update. Just copy this to /usr/bin/slocategui
Code:
# !/bin/sh
# copyright (c) 2015 Marcos M Contant
# all rights reserved
#yad splash --text "disclaimer use at your own risk. No responsibility accepted.
#Using this app will backup your fstab
#and add entries to /etc/fstab if not already there.
#To reset fstab and remove .db files in term type
#slocategui reset'
#Press Enter"
#read dummy

# set path definition for puppy or debiandog
# lighthouse also has /media
pathdef () {
if [ -d /live* ]; then
   path=media
else
   path=mnt
fi
}
pathdef
#[[ -f /mnt/Home ]] && ln -fs /mnt/Home /mnt/sdz1
#[[ -f /mnt/home ]] && ln -fs /mnt/home /mnt/sdz2
if [ -e /var/lib/slocate/1slocate.db ]; then
   rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
addgroup -S slocate  &> /dev/null
fi
# Restore fstab, remove flags and databases named slocate.db
if [ "$1" = reset ]; then
   for file in `probepart -m  | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
      do
         [[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
         mount -a
         sleep 3
         up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
         if [[ -z "$up" ]]; then
         mount /dev/"$file" /"$path"/"$file"
         fi
         [[ -e /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
         [[ -e /"$path"/"$file"/.did ]] && rm -f /"$path"/"$file"/.did
         [[ -e /"$path"/"$file"/.didex ]] && rm -f /"$path"/"$file"/.didex
   done
   [[ -e $HOME/.did ]] && rm $HOME/.did
   rm -f /var/lib/slocate/*
   [[ -f /etc/fstab-backup ]] && mv /etc/fstab-backup /etc/fstab
   [[ -f /tmp/result ]] && rm /tmp/result
   [[ -f /tmp/*.m3u ]] && rm /tmp/*.m3u
   exit 0
fi

# backup fstab, create blkid.txt for UUID to fstab
[[ ! -f /etc/fstab-backup ]] && cp /etc/fstab /etc/fstab-backup
rm -f /tmp/blkid.txt
blkid  | grep --invert-match  'loop'  > /tmp/blkid.txt
sed -i 's/\"//g' /tmp/blkid.txt

# This function adds partition entries to fstab if not already there.
idfn () {
   while read line
   do
      ud=`echo "$line" | cut -f2 -d ' '`
      fs=`echo "$line" | rev | cut -f1 -d '=' | rev`
      mntpnt=`echo "$line" | cut -f1 -d ':' | rev | cut -f1 -d '/' | rev`
      yn=`cat /etc/fstab | grep "$ud"`
      case "$fs" in
         ntfs)   drvr="ntfs-3g"
                  extra=" defaults,locale=en_GB.utf8              0 0"
                     if [[ -z "$yn" ]]; then
                        echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'   '$extra'   " >> /etc/fstab # ntfs partition fstab entry
                     fi
                     ;;
         ext[2-4])   extra=" defaults               0 2"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # ext filesystem fstab entry
                  fi
                  ;;
         vfat)
                  extra="defaults,user,exec,uid=0,gid=0,dmask=027,umask=137             0 0"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # vfat/fat32 fstab entry
                  fi
                  ;;
         hfsplus) extra="rw,exec,auto,users             0 0"
                     drvr="hfsplus"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # mac hfs+ fstab entry
                  fi
                  ;;
      esac
      sed -i "s/'//g" /etc/fstab
      sed -i 's/"//g' /etc/fstab
      sed -i 's/ntfs-3g    ext/ext/g' /etc/fstab
      sed -i 's/ntfs-3g    vfat/vfat/g' /etc/fstab
      sed -i 's/ntfs-3g    hfsplus/hfsplus/g' /etc/fstab
      touch /"$path"/"$mntpnt"/.didex
   done < /tmp/blkid.txt
   rm -f /tmp/blkid.txt
}
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
if [ ! -e /"$path"/"$file"/.didex ]; then
   idfn
fi
done
# yad gui input search term
filext=`yad --title="Find files by stemsee" --text="What are you looking for?:
e.g. *.mp3" --field="Type file name or extension:" --window-icon="" --entry`
if [[ -z "$filext" ]]; then
   exit 1
fi
# store and format search term
echo $filext > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn () {
   slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db | yad --window-icon=""  --width=300 --title "Creating Database for '/'" --progress --auto-close --pulsate
   chmod a+x  /var/lib/slocate/slocate.db
   ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
   touch $HOME/.did
}
# has root database been created?
if [ ! -e /var/lib/slocate/slocate.db ]; then
   rootdbfn
else
   slocate -u -o /var/lib/slocate/slocate.db &
   ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
fi

# create external partition db and make searchable
extdbfn () {
   for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
      do
      emp=$(ls -A /$path/$file/)
         if [[ -z "$emp" ]]; then
         mkdir /"$path"/"$file"
         mount -a
         sleep 3
         fi
         up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
         if [[ -z "$up" ]]; then
         mount /dev/"$file" /"$path"/"$file"
         sleep 4
         fi
         if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
            slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Creating Database '$file'" &
         elif [[ -e /"$path"/"file"/slocate.db ]]; then
            slocate -U -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Updating Database '$file'"  &
         fi
         ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"   
         touch /"$path"/"$file"/.did
   done
}
extdbfn
sync

#update DBs if in existence
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o slocate.db; done &

# choose database to search
pathfn () {
for F in `ls /var/lib/slocate/* | grep --invert-match  'slocate.db' `
do
    if [ -L "$F" ]; then
        if readlink -q "$F" >/dev/null ; then
            echo
        else
            rm /var/lib/slocate/"$F"
        fi
    fi
done
   pathto=`ls /var/lib/slocate/*  | grep --invert-match  'slocate.db' | yad --geometry=300x600 --list --column="Databases available" --multiple --title="Find files in" --text="Which drive to search?:
   e.g. sdb5 or sys for /." --window-icon="" --separator ' '`
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [  "$YADPID" = 0 ]; then
   pathfn
fi
# checks empty variable
if [ -z "$pathto" ]; then
   exec "$0"
fi

      #if [[ "$pathto" ]]; then
      #   yad splash --text " Please wait:  Now searching \n'$pathto'"  &
      #fi

# search databases
syste=`echo $pathto | grep 'sys'`
if [ ! -z "$syste" ]; then
   echo
else
   rename slocate.db 1slocate.db /var/lib/slocate/slocate.db
   touch /var/lib/slocate/slocate.db
fi
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':' | grep --invert-match 'sys'`
#part=`echo $pathto | cut -f1 -d '\n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result

# multiple file/dir selection gui
select=$(cat /tmp/"$filext"-result | yad --window-icon=""  --title "SlocateGUI" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && exit 0
if [[ $ret -eq 0 ]]; then
# gui command to execute input box
   app=`yad --window-icon="" --title="Type Command + space" --text="command + options+space:
   e.g. vlc " --field="Add £ for multiples\n e.g. petget +£ \n Type command:" --entry`
   if [[ -z "$app" ]]; then
      exit 1
   fi
   echo "$select" > /tmp/list-"$filext".m3u # create file list as 'search-term'.m3u playlist with blank lines in between
   if [[ -h "$select" ]]; then
      select=`realpath $select` # incase of link
   fi
   if [[ "$app" = rm ]]; then # delete files/dirs
      while read line
      do
         rm -rf "$line"
      done < /tmp/list-"$filext".m3u
   elif [[ `echo "$app"| rev | cut -f1 -d ' '` = £ ]]; then # loop over list for given commands + options
      app=`echo "$app" | cut -f1 -d '£'`
      while read line
      do
      dirr=`echo $line | rev | cut -f2,3,4,5,6,7,8,9,10,11,12,13,14 -d '/' | rev`
      line=`echo $line |  rev | cut -f1 -d '/' | rev`
      cd "$dirr"
       "$app""$line"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
         location=`yad --window-icon=""  --geometry=250 --title="Type Path To Destination" --text="Path:
         e.g. /root/my-documents" --field="Type Path:" --entry`
      if [[ -z "$location" ]]; then
         exit 1
      fi
         while read line
         do
            mv "$line" "$location"
         done  < /tmp/list-"$filext".m3u
   elif [[ "$app" = ln ]]; then # link single file
         linknm=`yad --window-icon=""  --geometry=200 --title="Type link name" --entry`
         if [[ -z "$linknm" ]]; then
            exit 1
         fi   
      line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
      ln -s "$select" "$line1"/"$linknm"
   elif [[ "$app" = rename ]]; then # rename single file
      newname=`yad --window-icon=""  --geometry=200 --title="Type new name" --entry`
         if [[ -z "$newname" ]]; then
            exit 1
         fi
      line=`echo $select | cut -f1 -d '/'`
      rename "$line" "$newname" "$select"
   elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
         replace=`yad --window-icon=""  --geometry=440 --title="Format: 'ReplaceThis'WithThis' " --text "But not ' nor /:" --entry`
         if [[ -z "$replace" ]]; then
            exit 1
         fi
      t1=`echo "$replace" | cut -f2 -d "'"`
      t2=`echo "$replace" | cut -f3 -d "'"`
         while read line
         do
            select2=`echo $line | rev | cut -f1 -d '/' | rev`
            rp=`echo "$select2" | tr "$t1" "$t2"`
            rename "$select2" "$rp" "$line"
         done < /tmp/list-"$filext".m3u
   elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
      location=`yad --window-icon=""  --geometry=260 --title="Type Path To Destination" --text="Path:
      e.g. /root/my-documents" --field="Type Path:" --entry`
         if [[ -z "$location" ]]; then
            exit 1
         fi
      while read line
      do
         cp -rf "$line" "$location"
      done  < /tmp/list-"$filext".m3u
   else
      playlist=$(yad --window-icon=""  --width=430 --title "Do you want to open as a playlist? y or n?" --entry)   #gui to open as playlist or  individual files
      case $playlist in
         y) "$app" /tmp/list-"$filext".m3u & # app opens playlist
         ;;
         n) "$app" "$select" & #  execute command on file
         ;;
         g) geany /tmp/list-"$filext".m3u & # open file list in geany
         ;;
      esac
   fi
fi
if [ -e /var/lib/slocate/1slocate.db ]; then
   rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi

rm /tmp/result # remove search results list
rm /tmp/"$filext"-result
for i in "$pathto"; do slocate -U /"$path"/"$i" -o slocate.db; done &
sync
exec "$0" & # open again for convenience to search new term

Last edited by stemsee on Wed 27 Jan 2016, 05:29; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Mon 25 Jan 2016, 18:01    Post subject:  

I could do with some help to simplify adding slocate group to /etc/group
This is the code I have that greps for slocate and if not found adds with a set number 159.
Code:
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
echo "slocate:x:159:" >> /etc/group
fi

Ideally I want the code to also check for a spare number but I couldn't work out how to code it. But something like while slocate is not in /etc/group and 159 is not in group then add line slocate:x:159: to /etc/group. If 159 is used then add 1 to 159 and to the sum of that until a free number is found than add the line with that value.
Back to top
View user's profile Send private message MSN Messenger 
gcmartin

Joined: 14 Oct 2005
Posts: 6730
Location: Earth

PostPosted: Mon 25 Jan 2016, 19:59    Post subject:  

I thought groupadd would be useful, but see that on my running PUP, the adduser/useradd, addgroup/groupadd, and delete features are missing.
_________________
Get ACTIVE Create Circles; Do those good things which benefit people's needs!
We are all related ... Its time to show that we know this!
3 Different Puppy Search Engines or use DogPile
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Tue 26 Jan 2016, 03:44    Post subject:  

Thanks addgroup (busybox) does it.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 2262
Location: In The Way

PostPosted: Sat 30 Jan 2016, 07:06    Post subject:  

Perfected! Finally!!

So now you can search multiple partitions or the running / sys(-tem) ... not both! Although it is possible to have all file data stored in sys db.

Code:
# !/bin/sh
# copyright (c) 2015 Marcos M Contant
# all rights reserved
# for i in `ls /mnt/`; do slocate -U /mnt/"$i" -o slocate.db; done
#yad splash --text "disclaimer use at your own risk. No responsibility accepted.
#Using this app will backup your fstab
#and add entries to /etc/fstab if not already there.
#To reset fstab and remove .db files in term type
#slocatgui reset'
#Press Enter"
#read dummy

# set path definition for puppy or debiandog
# lighthouse also has /media
pathdef () {
if [ -d /live* ]; then
   path=media
else
   path=mnt
fi
}
pathdef
#[[ -f /mnt/Home ]] && ln -fs /mnt/Home /mnt/sdz1
#[[ -f /mnt/home ]] && ln -fs /mnt/home /mnt/sdz2
if [ -e /var/lib/slocate/1slocate.db ]; then
   rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi
added=`cat /etc/group | grep 'slocate'`
if [ -z "$added" ]; then
echo "slocate:x:159:" >> /etc/group
fi

# Restore fstab, remove flags and databases named slocate.db
if [ "$1" = reset ]; then
   for file in `probepart -m  | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
      do
         [[ ! -d /"$path"/"$file" ]] && mkdir /"$path"/"$file"
         mount -a
         sleep 3
         up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
         if [[ -z "$up" ]]; then
            mount /dev/"$file" /"$path"/"$file"
         fi
         [[ -e /"$path"/"$file"/slocate.db ]] && rm -f /"$path"/"$file"/slocate.db
         [[ -e /"$path"/"$file"/.did ]] && rm -f /"$path"/"$file"/.did
         [[ -e /"$path"/"$file"/.didex ]] && rm -f /"$path"/"$file"/.didex
   done
   [[ -e $HOME/.did ]] && rm $HOME/.did
   rm -f /var/lib/slocate/*
   [[ -f /etc/fstab-backup ]] && mv /etc/fstab-backup /etc/fstab
   [[ -f /tmp/result ]] && rm /tmp/result
   [[ -f /tmp/*.m3u ]] && rm /tmp/*.m3u
   exit 0
fi

# backup fstab, create blkid.txt for UUID to fstab
[[ ! -f /etc/fstab-backup ]] && cp /etc/fstab /etc/fstab-backup
rm -f /tmp/blkid.txt
blkid  | grep --invert-match  'loop'  > /tmp/blkid.txt
sed -i 's/\"//g' /tmp/blkid.txt

# This function adds partition entries to fstab if not already there.
idfn () {
   while read line
   do
      ud=`echo "$line" | cut -f2 -d ' '`
      fs=`echo "$line" | rev | cut -f1 -d '=' | rev`
      mntpnt=`echo "$line" | cut -f1 -d ':' | rev | cut -f1 -d '/' | rev`
      yn=`cat /etc/fstab | grep "$ud"`
      case "$fs" in
         ntfs)   drvr="ntfs-3g"
                  extra=" defaults,locale=en_GB.utf8              0 0"
                     if [[ -z "$yn" ]]; then
                        echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'   '$extra'   " >> /etc/fstab # ntfs partition fstab entry
                     fi
                     ;;
         ext[2-4])   extra=" defaults               0 2"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # ext filesystem fstab entry
                  fi
                  ;;
         vfat)
                  extra="defaults,user,exec,uid=0,gid=0,dmask=027,umask=137             0 0"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # vfat/fat32 fstab entry
                  fi
                  ;;
         hfsplus) extra="rw,exec,auto,users             0 0"
                     drvr="hfsplus"
                  if [[ -z "$yn" ]]; then
                     echo "'$ud'    /'$path'/'$mntpnt'    '$drvr'    '$fs'  '$extra'   " >> /etc/fstab # mac hfs+ fstab entry
                  fi
                  ;;
      esac
      sed -i "s/'//g" /etc/fstab
      sed -i 's/"//g' /etc/fstab
      sed -i 's/ntfs-3g    ext/ext/g' /etc/fstab
      sed -i 's/ntfs-3g    vfat/vfat/g' /etc/fstab
      sed -i 's/ntfs-3g    hfsplus/hfsplus/g' /etc/fstab
      touch /"$path"/"$mntpnt"/.didex
   done < /tmp/blkid.txt
   rm -f /tmp/blkid.txt
}
for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
do
if [ ! -e /"$path"/"$file"/.didex ]; then
   idfn
fi
done
# yad gui input search term
filext=`yad --title="Find files by stemsee" --text="What are you looking for?:
e.g. *.mp3" --field="Type file name or extension:" --window-icon="" --entry`
if [[ -z "$filext" ]]; then
   exit 1
fi
# store and format search term
echo $filext > /tmp/name
sed -i 's/^/nm=/' /tmp/name
# create root db and make searchable
rootdbfn () {
   slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db | yad --window-icon=""  --width=300 --title "Creating Database for '/'" --progress --auto-close --pulsate
   chmod a+x  /var/lib/slocate/slocate.db
   ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
   touch $HOME/.did
}
# has root database been created?
if [ ! -e /var/lib/slocate/slocate.db ]; then
   rootdbfn
   exec "$0"
   exit 0
else
   slocate -u -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /var/lib/slocate/slocate.db &
   ln -fs /var/lib/slocate/slocate.db /var/lib/slocate/sys
fi

# create external partition db and make searchable
extdbfn () {
   for file in `probepart -m | grep --invert-match 'none' | cut -f1 -d '|' | cut -f3 -d '/' | grep --invert-match 'sr0' | tr '\n' ' '`
      do
      emp=$(ls -A /$path/$file/)
         if [[ -z "$emp" ]]; then
         mkdir /"$path"/"$file"
         mount -a
         sleep 3
         fi
         up=`mount -l | grep -e 'sd[a-z][1-9]' | grep "$file"`
         if [[ -z "$up" ]]; then
         mount /dev/"$file" /"$path"/"$file"
         sleep 4
         fi
         if [[ ! -e /"$path"/"$file"/slocate.db ]]; then
            slocate -U /"$path"/"$file"/ -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Creating Database '$file'" &
         elif [[ -e /"$path"/"file"/slocate.db ]]; then
            slocate -U -o /"$path"/"$file"/slocate.db | yad --progress --auto-close --pulsate --window-icon="" --width=300 --title "Updating Database '$file'"  &
         fi
         ln -fs /"$path"/"$file"/slocate.db /var/lib/slocate/"$file"   
         touch /"$path"/"$file"/.did
   done
}
extdbfn
sync

#update DBs if in existence
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -e /dev,/proc,/tmp,/aufs,/usr/tmp,/var/tmp,/var/run,/initrd,/"$path", -o /"$path"/"$i"/slocate.db; done &

# choose database to search
pathfn () {
for F in `ls /var/lib/slocate/* | grep --invert-match  'slocate.db' `
do
    if [ -L "$F" ]; then
        if readlink -q "$F" >/dev/null ; then
            echo
        else
            rm /var/lib/slocate/"$F"
        fi
    fi
done
   pathto=`ls /var/lib/slocate/*  | grep --invert-match  'slocate.db' | yad --geometry=300x400 --list --column="Search partition/s or sys(-tem)?" --multiple --title="Find files in these partitions?" --window-icon="" --separator ' '`
}
YADPID=$(ps -eo pid,cmd | grep -v grep | grep "yad --progress" | tr ' ' '\n' | wc -l )
if [  "$YADPID" = 0 ]; then
   pathfn
fi
# checks empty variable
if [ -z "$pathto" ]; then
   exec "$0"
fi

      #if [[ "$pathto" ]]; then
      #   yad splash --text " Please wait:  Now searching \n'$pathto'"  &
      #fi

# search databases
syste=`echo $pathto | grep 'sys'`
if [ ! -z "$syste" ]; then
   echo
else
   rename slocate.db 1slocate.db /var/lib/slocate/slocate.db
   touch /var/lib/slocate/slocate.db
fi
pathto=`echo $pathto | tr ' ' ':' | tr '\n' ':' | grep --invert-match 'sys'`
#part=`echo $pathto | cut -f1 -d '\n'`
slocate -i "$filext" --database="$pathto" > /tmp/"$filext"-result

# multiple file/dir selection gui
select=$(cat /tmp/"$filext"-result | yad --window-icon=""  --title "SlocateGUI" --list --multiple --center --height="400" --width="300" --column="$filext:" --print-column="1" --separator="\n")
ret=$?
[[ $ret -eq 1 ]] && exit 0
if [[ $ret -eq 0 ]]; then
# gui command to execute input box
   app=`yad --window-icon="" --title="Type Command + space" --text="command + options+space:
   e.g. vlc " --field="Add £ for multiples\n e.g. petget +£ \n Type command:" --entry`
   if [[ -z "$app" ]]; then
      exit 1
   fi
   echo "$select" > /tmp/list-"$filext".m3u # create file list as 'search-term'.m3u playlist with blank lines in between
   if [[ -h "$select" ]]; then
      select=`realpath $select` # incase of link
   fi
   if [[ "$app" = rm ]]; then # delete files/dirs
      while read line
      do
         rm -rf "$line"
      done < /tmp/list-"$filext".m3u
   elif [[ `echo "$app"| rev | cut -f1 -d ' '` = £ ]]; then # loop over list for given commands + options
      app=`echo "$app" | cut -f1 -d '£'`
      while read line
      do
      dirr=`echo $line | rev | cut -f2,3,4,5,6,7,8,9,10,11,12,13,14 -d '/' | rev`
      line=`echo $line |  rev | cut -f1 -d '/' | rev`
      cd "$dirr"
       "$app""$line"
      done < /tmp/list-"$filext".m3u
   elif [[ "$app" = mv ]]; then # move files/dirs to 'gui input box'
         location=`yad --window-icon=""  --geometry=250 --title="Type Path To Destination" --text="Path:
         e.g. /root/my-documents" --field="Type Path:" --entry`
      if [[ -z "$location" ]]; then
         exit 1
      fi
         while read line
         do
            mv "$line" "$location"
         done  < /tmp/list-"$filext".m3u
   elif [[ "$app" = ln ]]; then # link single file
         linknm=`yad --window-icon=""  --geometry=200 --title="Type link name" --entry`
         if [[ -z "$linknm" ]]; then
            exit 1
         fi   
      line1=`echo $select | cut -f2,3,4,5,6,7,8,9,10 -d '/'`
      ln -s "$select" "$line1"/"$linknm"
   elif [[ "$app" = rename ]]; then # rename single file
      newname=`yad --window-icon=""  --geometry=200 --title="Type new name" --entry`
         if [[ -z "$newname" ]]; then
            exit 1
         fi
      line=`echo $select | cut -f1 -d '/'`
      rename "$line" "$newname" "$select"
   elif [[ "$app" = replace ]]; then # replace string or symbol except apostrophe and backslash (but possible)
         replace=`yad --window-icon=""  --geometry=440 --title="Format: 'ReplaceThis'WithThis' " --text "But not ' nor /:" --entry`
         if [[ -z "$replace" ]]; then
            exit 1
         fi
      t1=`echo "$replace" | cut -f2 -d "'"`
      t2=`echo "$replace" | cut -f3 -d "'"`
         while read line
         do
            select2=`echo $line | rev | cut -f1 -d '/' | rev`
            rp=`echo "$select2" | tr "$t1" "$t2"`
            rename "$select2" "$rp" "$line"
         done < /tmp/list-"$filext".m3u
   elif [[ "$app" = cp ]]; then # copy files/dirs to 'gui input box'
      location=`yad --window-icon=""  --geometry=260 --title="Type Path To Destination" --text="Path:
      e.g. /root/my-documents" --field="Type Path:" --entry`
         if [[ -z "$location" ]]; then
            exit 1
         fi
      while read line
      do
         cp -rf "$line" "$location"
      done  < /tmp/list-"$filext".m3u
   else
      playlist=$(yad --window-icon=""  --width=430 --title "Do you want to open as a playlist? y or n?" --entry)   #gui to open as playlist or  individual files
      case $playlist in
         y) "$app" /tmp/list-"$filext".m3u & # app opens playlist
         ;;
         n) "$app" "$select" & #  execute command on file
         ;;
         g) geany /tmp/list-"$filext".m3u & # open file list in geany
         ;;
      esac
   fi
fi
if [ -e /var/lib/slocate/1slocate.db ]; then
   rename 1slocate.db slocate.db /var/lib/slocate/1slocate.db
fi

rm /tmp/result # remove search results list
rm /tmp/"$filext"-result
for i in `ls "$path"`; do slocate -U /"$path"/"$i" -o /"$path"/"$i"/slocate.db; done &
sync
exec "$0" & # open again for convenience to search new term
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 2 of 3 [36 Posts]   Goto page: Previous 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1010s ][ Queries: 12 (0.0081s) ][ GZIP on ]