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 Tue 30 Sep 2014, 02:44
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
command line pet uninstall
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Fri 03 Sep 2010, 07:14    Post subject:  command line pet uninstall  

Quick safe pet uninstaller script. Finds package with searchword, removes only files; prompts before removing each item.
note: close programs before uninstalling

Usage: "uninstall [searchword]" (if script is saved as "uninstall")

Also good for stripping docs, etc (like from deb installs)

Edit: added option to remove from Puppy Package Manager

1/1/11: added prompt for removing open directories

Code:

#!/bin/bash -a


##  jpeps   Ver 2.0  Jan/2011

## Uninstalls files as listed in /root/.package dir   
## Options:
##           -s            show usr-installed-packages
##           package       default: uninstall with prompts
##           package -f    force: uninstall without prompts
##           package -c    check to see if in use
##           package -s    view package files
##           package [-f] -o  overrides in-use function

FLAG="0"  ## checks if main program is run (vs. a check)

## Function to remove open directories

flagOpen=""
RemOpenDir(){
for item in "$(ls ${OLDPATH})"; do
   if [ "$item" ]; then
     flagOpen="1"
   else
      rm -r ${OLDPATH}
     echo "Removed: ${OLDPATH}" >>/tmp/uninstall.log
     OLD="$(basename ${OLDPATH})"
     NEWPATH="$(echo ${OLDPATH} | sed -e "s@\/${OLD}@@")"
     OLDPATH="$NEWPATH"
   fi   
done
}

export -f RemOpenDir

### Check if app is in use before deleting

INUSE(){

[ -f /tmp/files ] && rm /tmp/files
[ -f /tmp/test ] && rm /tmp/test
CEXEC="$(find | grep -i "$1" | grep -v "builtin")"

echo "Checking: $CEXEC"

if [ "$CEXEC" ]; then

CFILES="$(cat "$CEXEC" | grep -e "\/bin\/" -e "\/games\/" -e "\/sbin\/" | sed '1d' )"

for I in "$CFILES"; do
  echo -e "$I\n" >>/tmp/files
 done
for I in `cat /tmp/files`; do
   ps | grep `basename "$I"` | grep -v "grep" | grep -v "$0" >>/tmp/test
done
fi
 [ -f /tmp/test ] && USE="$(cat /tmp/test)"   
## cleanup
[ -f /tmp/test ] && rm /tmp/test
[ -f /tmp/files ] && rm /tmp/files
if [ "$USE" ]; then
  echo -e $CYAN"\nIn Use:
${USE}"
  exit
fi

[ "$FLAG" = "0" ] &&  exit

}
export -f INUSE

#########################
if [ -z "$1" ]; then
    echo -e "              Usage: 'uninstall [mypackage]'      with prompts\n \
                    'uninstall -s'               view user-installed packages\n \
                    'uninstall [package] -f'      no prompts\n \
                    'uninstall [package] -c'      check for usage
                     'uninstall [package] -s'      view package files
                     'uninstall [package] [-f] -o'  overrides in-use function"
    exit
fi
cd /root/.packages

RM="rm -i"  ## default: remove with prompt

## Show user-installed-packages option

[ "$1" = "-s" ] &&  ls | grep "\.files" | sed -e 's/\.files//g' && exit
[ "$2" = "-f" ] &&  RM="rm"    ### force option (remove without prompt).
[ "$2" = "-c" ] &&  INUSE $1

PACKAGE="$(find | grep -i "$1" | grep -v "builtin_files")"
PET="$(echo "$PACKAGE" | sed -e 's/\.files/\.pet/' | cut -d/ -f2)"
NAME="$(echo ${PET} | sed -e 's/\.pet//')" 

## Option to show package
[ "$2" = "-s" ] && cat "$PACKAGE" && exit

[ "$PACKAGE" ] && FILES="$(cat "$PACKAGE")"
if [ "$FILES" ]; then
 FLAG="1"
[ "$3" = "-o" -o "$2" = "-o" ] || INUSE $1
for ITEM in "$FILES"; do
$RM  $ITEM
done

## Option to remove open directories
   
   echo -e "\nRemove Open Directories? (y/n)"
   read ans
   if [ "$ans" == "y" ]; then
    [ -f /tmp/uninstall.log ] &&  rm /tmp/uninstall.log
      while read line; do
          if [ -d "$line" ]; then 
              OLDPATH="$line"
          elif  [ -f "$line" ]; then
            VAR="$(basename ${line})"         
             OLDPATH="$( echo ${line} | sed -e  "s@${VAR}@@")"
          fi
        RemOpenDir
      done < "$PACKAGE"
    fi
## Remove Listings

echo -e "\nRemoving listing from .packages"
$RM "$PACKAGE"

 if [ "$RM" = "rm -i" ]; then 
echo -e "\nRemove listing from Puppy Package Manager? (y/n)"
  read ans

case "$ans" in
 y ) sed -i "/${NAME}/d" ./user-installed-packages ;;
 n ) echo "listing NOT removed" ;;
 * ) echo "answer should be 'y' or 'n'" ;;
esac
 else
    sed -i "/${NAME}/d" ./user-installed-packages
  fi
echo  "Done!"

fi


Last edited by jpeps on Sat 01 Jan 2011, 18:16; edited 2 times in total
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sun 05 Sep 2010, 14:54    Post subject:  

Safer version;
checks /bin files that are in use (displays & exits if in use) before allowing uninstall. (override this function with -o). Check can also be run alone "uninstall [package] -c"
View installed pets with '-s' option.

EDIT: Posted Above.

Last edited by jpeps on Sat 01 Jan 2011, 18:11; edited 1 time in total
Back to top
View user's profile Send private message 
frefel

Joined: 26 Feb 2009
Posts: 178
Location: Eugene, Ore., US

PostPosted: Thu 30 Dec 2010, 23:10    Post subject:  

This looks like what I need to uninstall a KeePassX pet I added to my frugal 511 Puppy on a usb stick but that does not show up in the PM list of installed pets. Since I have not done this kind of thing before and do not want to screw up my settings I am hoping someone could give me a few more details on how to proceed:

I assume I copy > paste the code to Geany, name it and then save it. Presently my Geany (/initrd/mnt/dev_save) opens with "sdb1,vfat,/lupusave-T42Dec10-2.2fs" on the first line. Do I just add it to that? I see the reco to save as "uninstall" and the options so it looks like I just go to Terminal and type in the parameters and it then will run.
Any other tips are greatly appreciated.
Thanks.
Back to top
View user's profile Send private message AIM Address 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Fri 31 Dec 2010, 04:56    Post subject:  

frefel wrote:
This looks like what I need to uninstall a KeePassX pet I added to my frugal 511 Puppy on a usb stick but that does not show up in the PM list of installed pets. Since I have not done this kind of thing before and do not want to screw up my settings I am hoping someone could give me a few more details on how to proceed:

I assume I copy > paste the code to Geany, name it and then save it. Presently my Geany (/initrd/mnt/dev_save) opens with "sdb1,vfat,/lupusave-T42Dec10-2.2fs" on the first line. Do I just add it to that? I see the reco to save as "uninstall" and the options so it looks like I just go to Terminal and type in the parameters and it then will run.
Any other tips are greatly appreciated.
Thanks.


1. Copy and paste into an editor (geany is fine)
2. Save script somewhere in PATH: example: /usr/local/bin/uninstall.
3. Give exec permissions: example:
"cd /usr/local/bin"
"chmod +x ./uninstall"

That should do it! Typing "uninstall -s" should show you installed packages.
Back to top
View user's profile Send private message 
frefel

Joined: 26 Feb 2009
Posts: 178
Location: Eugene, Ore., US

PostPosted: Fri 31 Dec 2010, 17:36    Post subject:  

Thanks a lot jpeps - worked beautifully with the -f option. I had to go back to manually delete a couple of empty files/folders but that was easy.

Nice piece of creativity that I think should be included in Puppy as a built-in app.
Back to top
View user's profile Send private message AIM Address 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Fri 31 Dec 2010, 18:56    Post subject:  

frefel wrote:
Thanks a lot jpeps - worked beautifully with the -f option. I had to go back to manually delete a couple of empty files/folders but that was easy.

Nice piece of creativity that I think should be included in Puppy as a built-in app.


Thanks for testing. Yes, deliberately doesn't delete folders, but tells you which ones so you can get them later if they're app specific.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Fri 31 Dec 2010, 23:24    Post subject:  

Woof built puppies now have the ability to remove preinstalled packages via ppm.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Sat 01 Jan 2011, 18:14    Post subject:  

Added function to remove open directories; prompts after removing files.
Logs removed open directories to /tmp/uninstall.log
Back to top
View user's profile Send private message 
vtpup


Joined: 15 Oct 2008
Posts: 1136
Location: Republic of Vermont

PostPosted: Wed 06 Jun 2012, 14:42    Post subject:  

Thanks for that jpeps, it saved a frugal installation with a wrong xorg .pet I'd installed. Couldn't use X but booted pfix=nox after installing your Uninstall script and ran -s to find the name of the file, then uninstalled it. Re-booted and X started. Most everything was good except I'd inadvertently uninstalled a couple of files needed for GLX. Then ran pfix=clean, and Xorgwizard and everything was back to normal.
_________________
Acer Aspire 5349-2635 laptop dual proc, 4gb ram, frugal Racy 5.5.
1999 Thinkpad 600e hacked Pent 3, overclocked 800 mHz, 490 kb running Lupu 528

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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.0773s ][ Queries: 12 (0.0039s) ][ GZIP on ]