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 |
Code Sample |
sed 's/echo\ rm/rm/' /path/to/script > /path/to/new/script |
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 |