Programming and Scripting :: Application removal script



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)

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

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

I'm assuming none of these applications can be removed with apt-get or dpkg? They were all not installed via deb packages?
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.

Next Page...
original here.