Application removal script


Forum: Programming and Scripting
Topic: Application removal script
started by: mikshaw

Posted by mikshaw on Nov. 10 2006,18:11
This is a preliminary, pre-beta, not-for-serious-use script! I haven't tested it at all, except to check the command syntax.

This script will be used for traditional harddrive installs and for remastering, to remove unwanted applications.

Code Sample
#!/bin/sh

[ -d "$1" ] && cd "$1"

applist=`whiptail --separate-output --checklist select\ applications\ you\ want\ to\ remove 20 72 12 \
aterm           terminal\ emulator\ and\ xterm\/rxvt\ symlinks  0 \
beaver          gui\ text\ editor                               0 \
dillo           dillo\ web\ browser                             0 \
emelfm          gui\ file\ manager                              0 \
firefox         firefox\ web\ browser                           0 \
fluxbox         window\ manager                                 0 \
games           card\ games\ and\ tetris                        0 \
gphone          internet\ phone                                 0 \
grun            application\ launcher                           0 \
gtkfind         find\ files\ gui                                0 \
jwm             window\ manager                                 0 \
mc              midnight\ commander\ text-based\ file\ manager  0 \
nano            text-based\ text\ editor                        0 \
netrik          text-based\ web\ browser                        0 \
perl            perl\ script\ interpreter                       0 \
rdesktop        remote\ NT\ desktop                        0 \
siag            spreadsheet\ application                        0 \
smbclient       connect\ to\ SMB\ shares                        0 \
sqlite          database                                        0 \
sylpheed        email\ client                                   0 \
ted             word\ processor                                 0 \
telnet          telnet                                          0 \
torsmo          desktop\ system\ monitor                        0 \
vnc             VNC\ client                                     0 \
xmms            X\ multimedia\ system                           0 \
xpaint          image\ editor                                   0 \
xpdf            pdf\ viewer                                     0 \
xtdesk          desktop\ icons                                  0 \
xzgv            image\ viewer                                   0 \
3>&1 1>&2 2>&3`

if [ $? -eq 1 ]; then exit; fi

cat << EOF
You are about to remove the selected applications and their related files.
The script may leave a few stray files behind, since I ain't perfect.
No guarantee is made about the condition of your system after you complete
the following process. The removal of some applications may cause failure
in other applications. Proceed at your own risk.
Type YES (all caps) to continue.
EOF
read anykey
if [ "$anykey" != "YES" ]; then exit; fi

for i in $applist; do
echo "removing $i"
case $i in
aterm) echo rm -rf usr/bin/{aterm,rxvt,xterm} usr/include/rxvtlib.h usr/lib/librxvt*;;
beaver) echo rm -rf usr/bin/beaver;;
dillo) echo rm -rf etc/dillorc usr/local/{bin,lib}/dillo* usr/local/bin/dpid* usr/local/etc/{dillorc,dpidrc};;
emelfm) echo rm -rf usr/X11R6/bin/emelfm* usr/lib/emelfm;;
firefox) echo rm -rf usr/local{,/bin}/firefox;;
fluxbox) echo rm -rf usr/bin/flux* usr/share/fluxbox;;
games) echo rm -rf usr/games;;
gphone) echo rm -rf usr/bin/gphone;;
grun) echo rm -rf usr/bin/grun;;
gtkfind) echo rm -rf usr/bin/gtkfind;;
jwm) echo rm -rf usr/bin/jwm;;
mc) echo rm -rf usr/local/bin/{mc,mc.bin};;
nano) echo rm -rf bin/nano*;;
netrik) echo rm -rf usr/local/bin/netrik;;
perl) echo rm -rf usr/{bin,lib}/perl* usr/lib/libperl* usr/share/perl*;;
rdesktop) echo rm -rf usr/{bin,share}/rdesktop usr/local/bin/rdesktop.lua;;
siag) echo rm -rf usr/lib/libMowitz* usr/local/{lib,share}/{siag,libMowitz*} usr/local/bin/{mowitz-config,siag*};;
smbclient) echo rm -rf usr/bin/smb* usr/local/bin/smbclient.lua;;
sqlite) echo rm -rf usr/bin/sqlite usr/lib/libsqlite*;;
sylpheed) echo rm -rf usr/bin/sylpheed;;
ted) echo rm -rf usr/local{,/bin}/Ted usr/local/bin/ted;;
telnet) echo rm -rf usr/bin/telnet;;
torsmo) echo rm -rf usr/local/bin/torsmo;;
vnc) echo rm -rf usr/bin/vnc*;;
xmms) echo rm -rf usr/{bin,lib}/xmms usr/lib/libxmms.* usr/share/xmms;;
xpaint) echo rm -rf usr/X11R6/bin/xpaint;;
xpdf) echo rm -rf etc/xpdf usr/bin/xpdf usr/share/xpdf;;
xtdesk) echo rm -rf usr/bin/xtdesk usr/local/bin/xtdesk.sh;;
xzgv) echo rm -rf usr/bin/xzgv;;
esac
done

It will not do any actual removal in its current state, since all commands are just echo commands. Using this command will remove the echos:
Code Sample
sed 's/echo\ rm/rm/' /path/to/script > /path/to/new/script


I have a notion that Mowitz is used in DSL only for Siag, which is why they are removed together. However, I'm not sure about this, so that fact along with the fact that this is a test may result in unwanted behavior.

The script runs on the current directory unless a directory is specified as a command parameter.  If you want to remove programs from an existing harddrive install (not frugal or embedded), it should be run from /, as root.

Basically I'm looking for feedback on how useful this is, whether it should have added features, ways to make it smaller and more efficient, etc.

Posted by ^thehatsrule^ on Nov. 10 2006,19:34
I'm sure this will come in handy for quite a number of users out there ;p

Not sure how serious you're taking this on... but here are some ideas:

- might want to consider an additional script to remove icons and/or menu items.

- size of files/directories [to be] removed (using du?).  You'll probably want to just use that case block to echo the file/paths so functions can reuse em.

Posted by mikshaw on Nov. 10 2006,20:48
I had planned to ignore everything in /home/dsl and /etc/skel, just because i don't like the idea of removing personal configs automatically.  I hadn't considered making it an option....good idea.

Honestly I don't understand what your second idea is.  It sounds like it might be a handy way to reduce the size of the script while making it easier to expand its functionality, but I'm not sure exactly what you're saying.  As far as I can tell, It'd be building the file list and getting file sizes *before* displaying the checklist so the data can be reused and cut down on redundancy?  I've never tried automating the creation of a whiptail/dialog list, but it sounds like a worthwhile experiment.

I'm not big on dynamically grabbing the file sizes, though. It sounds like it would be a lot of cpu cycles for little benefit.  At most I think i'd include a static display of the approximate size of each.  But...it just occured to me while typing that last sentence that you may have meant getting a single du of all selected applications.  That might not be so bad.

As for how serious I'm taking this....I already had a workable filelist for automatically stripping out a static collection of files, so this checklist method is not terribly important to me. However, it was just something that crossed my mind last night while i was trying to sleep, so I thought i'd test it out. I have no idea where it will lead.

Posted by mikshaw on Nov. 11 2006,03:31
This is a rewrite using an array to store all of the files' information, and building the checklist dynamically.  I couldn't figure out how to do this and include whiptail labels that contain spaces, so i replaced them with dots.

At this point I think adding/editing applications should be a simple matter of changing just the applist array.

I'm not sure how accurate the du command is when using a list of files, possibly some duplicates and symlinks.

Code Sample
#!/bin/bash

applist=(
aterm terminal.emulator.and.xterm/rxvt.symlinks "usr/bin/aterm usr/bin/rxvt usr/bin/xterm usr/include/rxvtlib.h usr/lib/librxvt*"
beaver gui.text.editor "usr/bin/beaver"
dillo dillo.web.browser "etc/dillorc usr/local/bin/dillo usr/local/lib/dillo* usr/local/bin/dpid* usr/local/etc/dillorc usr/local/etc/dpidrc"
emelfm gui.file.manager "usr/X11R6/bin/emelfm* usr/lib/emelfm"
firefox firefox.web.browser "usr/local/bin/firefox usr/local/firefox"
fluxbox window.manager "usr/bin/flux* usr/share/fluxbox"
games card.games.and.tetris "usr/games"
gphone internet.phone "usr/bin/gphone"
grun application.launcher "usr/bin/grun"
gtkfind find.files.gui "usr/bin/gtkfind"
jwm window.manager "usr/bin/jwm"
mc midnight.commander.text-based.file.manager "usr/local/bin/mc usr/local/bin/mc.bin"
nano text-based.text.editor "bin/nano*"
netrik text-based.web.browser "usr/local/bin/netrik"
perl perl.script.interpreter "usr/bin/perl* usr/lib/perl* usr/lib/libperl* usr/share/perl*"
rdesktop remote.NT.desktop "usr/bin/rdesktop usr/share/rdesktop usr/local/bin/rdesktop.lua"
siag spreadsheet.application "usr/lib/libMowitz* usr/local/share/siag usr/local/lib/siag usr/local/lib/libMowitz* usr/local/share/Mowitz usr/local/bin/mowitz-config usr/local/bin/siag*"
smbclient connect.to.SMB.shares "usr/bin/smb* usr/local/bin/smbclient.lua"
sqlite database "usr/bin/sqlite usr/lib/libsqlite*"
sylpheed email.client "usr/bin/sylpheed"
ted word.processor "usr/local/Ted usr/local/bin/Ted usr/local/bin/ted"
telnet Telnet "usr/bin/telnet"
torsmo desktop.system.monitor "usr/local/bin/torsmo"
vnc VNC.client "usr/bin/vnc*"
xmms X.multimedia.system "usr/lib/xmms usr/bin/xmms usr/lib/libxmms.* usr/share/xmms"
xpaint image.editor "usr/X11R6/bin/xpaint"
xpdf pdf.viewer "etc/xpdf usr/bin/xpdf usr/share/xpdf"
xtdesk desktop.icons "usr/bin/xtdesk usr/local/bin/xtdesk.sh"
xzgv image.viewer "usr/bin/xzgv"
)

# build checklist, omitting filenames
wtstring=""
cnt=${#applist[*]}
for (( i = 0; i < cnt; i=i+3 )); do wtstring="$wtstring ${applist[$i]} ${applist[$i+1]} 0"; done
chooser=`whiptail --separate-output --checklist "select applications you want to remove" 20 72 12 $wtstring 3>&1 1>&2 2>&3`
[ $? -ne 0 ] && exit

# list of files to be deleted
filelist=""
for (( i = 0; i < cnt; i=i+3 )); do
echo $chooser | grep ${applist[$i]} &>/dev/null && filelist="$filelist ${applist[$i+2]}"
done

size=`du -h -c $filelist | tail -1 | awk '{print $1}'`
cat << EOF
You are about to remove the selected applications and their related files,
with an approximate total uncompressed size of $size
The script may leave a few stray files behind, since I ain't perfect.
No guarantee is made about the condition of your system after you complete
the following process. The removal of some applications may cause failure
in other applications. Proceed at your own risk.
Type YES (all caps) to continue.
EOF
read anykey
[ "$anykey" != "YES" ] && exit

echo rm -rfv $filelist

Posted by ^thehatsrule^ on Nov. 11 2006,05:56
I haven't been able to test it yet... but looks good so far ;p

If you're worried about du taking too many cycles, it could be made as an option (via variable, etc) and it's pretty accurate.  The main reason for the sizes is so that the user can see how much space taking things out will be... like if it's worth the effort - it's a nice-to-have anyways :)

Posted by mikshaw on Nov. 11 2006,14:48
It seems to have very little negative effect on my 1.8ghz machine, but i haven't tested yet with the 333mhz.  On the subject of how accurate it is, I was mainly concerned about what happens if you accidentally get duplicate directories listed in $filelist, but after some du testing it seems as though the program knows how to properly handle it.

Next step will be to implement the optional removal of /home/dsl and /etc/skel files.  That will be later, though...still have a pile of other unfinished projects that I have to get back to =o)

Posted by mikshaw on Nov. 11 2006,17:28
Ok, so i stuck with it for a little while longer...

Changes:
Check for the existence of a $chooser variable rather than the exit status of whiptail. It now quits if you select nothing and choose "ok".
File lists are created via function to reduce redundancy.
Removed the description field from whiptail to cut down on size and maintenance time.
Add option to remove icons with application.

Code Sample
#!/bin/bash

# 0 = program name, 1 = program files, 2 = icon files
applist=(
aterm
"usr/bin/aterm usr/bin/rxvt usr/bin/xterm usr/include/rxvtlib.h usr/lib/librxvt*"
"home/dsl/.xtdesktop/Aterm.* etc/skel/.xtdesktop/Aterm.*"
axyftp
"usr/X11R6/bin/axyftp*"
"home/dsl/.xtdesktop/Ftp.* etc/skel/.xtdesktop/Ftp.*"
beaver
"usr/bin/beaver"
"home/dsl/.xtdesktop/Beaver.* etc/skel/.xtdesktop/Beaver.*"
dillo
"etc/dillorc usr/local/bin/dillo usr/local/lib/dillo* usr/local/bin/dpid* usr/local/etc/dillorc usr/local/etc/dpidrc"
"home/dsl/.xtdesktop/Dillo.* etc/skel/.xtdesktop/Dillo.*"
emelfm
"usr/X11R6/bin/emelfm* usr/lib/emelfm"
"home/dsl/.xtdesktop/Emelfm.* etc/skel/.xtdesktop/Emelfm.*"
firefox
"usr/local/bin/firefox usr/local/firefox"
"home/dsl/.xtdesktop/Firefox.* etc/skel/.xtdesktop/Firefox.*"
fluxbox
"usr/bin/flux* usr/share/fluxbox" " "
games
"usr/games" " "
gphone
"usr/bin/gphone" " "
grun
"usr/bin/grun" " "
gtkfind
"usr/bin/gtkfind" " "
jwm
"usr/bin/jwm" " "
mc
"usr/local/bin/mc usr/local/bin/mc.bin" " "
nano
"bin/nano*" " "
netrik
"usr/local/bin/netrik" " "
perl
"usr/bin/perl* usr/lib/perl* usr/lib/libperl* usr/share/perl*" " "
rdesktop
"usr/bin/rdesktop usr/share/rdesktop usr/local/bin/rdesktop.lua"
"home/dsl/.xtdesktop/Rdesktop.* etc/skel/.xtdesktop/Rdesktop.*"
siag
"usr/lib/libMowitz* usr/local/share/siag usr/local/lib/siag usr/local/lib/libMowitz* usr/local/share/Mowitz usr/local/bin/mowitz-config usr/local/bin/siag*"
"home/dsl/.xtdesktop/Siag.* etc/skel/.xtdesktop/Siag.*"
smbclient
"usr/bin/smb* usr/local/bin/smbclient.lua" " "
sqlite
"usr/bin/sqlite usr/lib/libsqlite*" " "
sylpheed
"usr/bin/sylpheed"
"home/dsl/.xtdesktop/Sylpheed.* etc/skel/.xtdesktop/Sylpheed.*"
ted
"usr/local/Ted usr/local/bin/Ted usr/local/bin/ted"
"home/dsl/.xtdesktop/Ted.* etc/skel/.xtdesktop/Ted.*"
telnet
"usr/bin/telnet" " "
torsmo
"usr/local/bin/torsmo" " "
vnc
"usr/bin/vnc*"
"home/dsl/.xtdesktop/Vnc.* etc/skel/.xtdesktop/Vnc.*"
xmms
"usr/lib/xmms usr/bin/xmms usr/lib/libxmms.* usr/share/xmms"
"home/dsl/.xtdesktop/Xmms.* etc/skel/.xtdesktop/Xmms.*"
xpaint
"usr/X11R6/bin/xpaint"
"home/dsl/.xtdesktop/Xpaint.* etc/skel/.xtdesktop/Xpaint.*"
xpdf
"etc/xpdf usr/bin/xpdf usr/share/xpdf"
"home/dsl/.xtdesktop/Xpdf.* etc/skel/.xtdesktop/Xpdf.*"
xtdesk
"usr/bin/xtdesk usr/local/bin/xtdesk.sh"
"home/dsl/.xtdesktop etc/skel/.xtdesktop"
xzgv
"usr/bin/xzgv"
"home/dsl/.xtdesktop/Xzgv.* etc/skel/.xtdesktop/Xzgv.*"
)

cnt=${#applist[*]}

# list of filenames
build_list() {
for (( i = 0; i < cnt; i=i+3 )); do
 echo $chooser | grep ${applist[$i]} &>/dev/null && filelist="$filelist ${applist[$i+$1]}"
done
}

# intro
echo "This script will attempt to remove unwanted applications
from the current directory tree. If you're running this script
from the root directory (/), files will be removed from your
running system. If you wish to use this script while remasting
DSL, it should be run from the top of the directory containing
your temporary filesystem, and not from the system root.
Press Enter to continue."
read anykey

echo "Do you want to remove desktop icons? [y|N]"
read rmicons

# build checklist, omitting filenames
wtstring=""
cnt=${#applist[*]}
for (( i = 0; i < cnt; i=i+3 )); do wtstring="$wtstring ${applist[$i]} 0"; done
chooser=`whiptail --separate-output --noitem --checklist \
"Use the spacebar to select the applications you want to remove." \
20 40 12 $wtstring 3>&1 1>&2 2>&3`

[ -z "$chooser" ] && exit

# list of files to be deleted
filelist=""
build_list 1
size=`du -h -c $filelist | tail -1 | awk '{print $1}'`

cat << EOF
You are about to remove the selected applications and their related files,
with a total uncompressed size of approximately $size
The script may leave a few stray files behind, since I ain't perfect.
No guarantee is made about the condition of your system after you complete
the following process. The removal of some applications may cause failure
in other applications. Proceed at your own risk.
Type YES (all caps) to continue.
EOF
read anykey
[ "$anykey" != "YES" ] && exit

case $rmicons in
[Yy][Ee][Ss]|[Yy]) build_list 2;;
esac

# remove everything in $filelist
echo rm -rfv $filelist

Posted by sathyan on Feb. 06 2007,07:03
Hi mikshaw,
good work...
i tryed this code...
and when i restarted my system it didn't start the display...:(
it said xtdesk.sh is missing....
then i installed DSL again and i tryed by not removing xtdesk.sh file and it worked fine...
so i think its better to remove this line from ur code
rm -rf usr/bin/xtdesk usr/local/bin/xtdesk.sh;;
still now i didn't get any error...:D
hope it won't give any error too...
thank u...
and do u know how to remove auto configure devices during the booting??? it takes lot of time for me... how to make DSL boot faster ???now from HD installation it takes 4min....
anyway... thank u once agian for ur help...
regards,
Sathyan

Posted by WDef on Feb. 06 2007,12:55
I'm assuming none of these applications can be removed with apt-get or dpkg? They were all not installed via deb packages?
Posted by mikshaw on Feb. 06 2007,17:43
PLEASE NOTE that I am aware this script is buggy and is not suitable for serious use at this time! As I said in the first post, this is only an experiment for now, and it is definitely not intended to be used by anyone who knows less about Linux than I do =o)
If/when it becomes safe and stable, I will post it as such.

Quote
it said xtdesk.sh is missing....
then i installed DSL again and i tryed by not removing xtdesk.sh file and it worked fine...
so i think its better to remove this line from ur code
rm -rf usr/bin/xtdesk usr/local/bin/xtdesk.sh;;
This is an issue that is related personal configuration files, which I refuse to touch without explicit permission.  If you choose to remove the xtdesk application, it will remove files that are expected by your personal configs. As a result, you must modify those configs to no longer want to use the removed files. You either have everything done for you and expect to lose some choice, or you keep the choice as well as the need to do some work yourself.  In most cases I opt for the latter.

Auto-configuration of hardware is found in /etc/init.d/knoppix-autoconfig
This file is necessary, but can be modified if you know what hardware you don't need to check for.
An alternative is passing boot options to the bootloader to disable checking of certain things:
< http://damnsmalllinux.org/wiki/index.php/Cheat_Codes >

Quote
I'm assuming none of these applications can be removed with apt-get or dpkg?
I couldn't tell you, as I have no interest in debian packages. All I know is these files are the ones that are related to the listed applications and they are removed manually. I don't use Debian packages myself, so I have no intention of caring whether or not the deb system breaks until i fix the obvious things like the firefox/mkunion bug.

Posted by roberts on Feb. 06 2007,23:15
John's bailiwick is the base applications in DSL, so he would know.
I am with mikshaw, in that, I too have little to no interest in Debian. My contributions to DSL are mainly providing infrastructure to support additional capabilites of the base system.

Posted by WDef on Feb. 09 2007,18:20
I wasn't advocating some attempt to preserve the integrity of the Debian base if that is what you mean by "with" and it's got nothing to do with being interested or not in Debian.

If an app was installed with dpkg, as they often are in  knoppix proper, I'd run (eg) dpkg -L and dpkg --contents to see what (if any) files are owned by that app so they might be deleted manually if needed.

I imagine that won't work for many things so keep working on the script Mik.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.