Programming and Scripting :: Application removal script



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.

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.

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.

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

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 :)

Next Page...
original here.