command line pet uninstall

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

command line pet uninstall

#1 Post by jpeps »

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: Select all

#!/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, 22:16, edited 2 times in total.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#2 Post by jpeps »

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, 22:11, edited 1 time in total.

frefel
Posts: 178
Joined: Thu 26 Feb 2009, 22:32
Location: Eugene, Ore., US

#3 Post by frefel »

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.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#4 Post by jpeps »

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.

frefel
Posts: 178
Joined: Thu 26 Feb 2009, 22:32
Location: Eugene, Ore., US

#5 Post by frefel »

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.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#6 Post by jpeps »

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.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

Woof built puppies now have the ability to remove preinstalled packages via ppm.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#8 Post by jpeps »

Added function to remove open directories; prompts after removing files.
Logs removed open directories to /tmp/uninstall.log

User avatar
vtpup
Posts: 1420
Joined: Thu 16 Oct 2008, 01:42
Location: Republic of Vermont
Contact:

#9 Post by vtpup »

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.
[color=darkblue]Acer Aspire 5349-2635 laptop Tahrpup.[/color]
[color=blue]Acer R11 and C720 Chromebks Bionicpup64[/color]
[color=olive]Acer Iconia A1-830 tablet no pup[/color]
[color=orange]www.sredmond.com[/color]

Post Reply