#!/bin/bash . GoboPath script=$0 kbToMB() { echo -e "scale=1\n$1/1024\n" | bc } outText() { sed '/^#BEGIN '$1'$/,/#END/ !d; /^#BEGIN\|#END/ d; s/^# //' $script [[ 1 == $2 ]] && exit } # Help and version texts are in comments at the end of the file. [[ "--help" == "$1" ]] && outText help 1 [[ "--version" == "$1" ]] && outText version 1 mode=0 prompt=1 [[ "--path" == "$1" ]] && mode=1 || outText termnotice [[ "--exec" == "$1" ]] && { mode=2;cmd=$2; } [[ "--noprompt" == "$3" ]] && prompt=0 t=0 for x in $goboPrograms/* do p=`basename $x` pt=0 cd $x c=`readlink Current` for v in $(GuessLatest --list [^CRSV]*|sed '1 d') do # Skip current version even if it isn't the newest [[ "$c" != "$v" ]] && { # mode 0: print program name and version if [[ 0 == $mode ]] then # Get the filesize, and print it to one d.p with the name & version s=`du -s $v | cut -f1` echo $p $v $(kbToMB $s)MB # Update the program subtotal and overall total t=$(($t+$s)) pt=$(($pt+$s)) # mode 1: print path of version directory elif [[ 1 == $mode ]] then echo $x/$v # mode 2: execute the --exec command, prompting unless --noprompt given else r=y # --noprompt suppresses this prompting and will always execute the command [[ 1 == $prompt ]] && { s=`du -s $v | cut -f1` echo -n "$p $v (current $c): " echo $(kbToMB $s)MB echo "Execute command '$cmd $x/$v'? y/N" read r } [[ "y" == "$r" ]] && $cmd $x/$v fi } done # Print the total filesize for this program in standard mode only, when # there was more than one old version found [[ 0 == $mode ]] && [[ 0 != $pt ]] && [[ $pt != $s ]] && echo " $p total: $(kbToMB $pt)MB" done # Print the total filesize of all old versions in standard mode only [[ 0 == $mode ]] && echo Total: $(kbToMB $t)MB #BEGIN help # OldPrograms # Finds obsoleted versions of programs that may be able to be deleted. # # Run with no arguments, outputs a list of programs and versions under # /Programs with newer versions installed and the amount of space these # versions take up. Will not include a version symlinked as Current even # if a newer version is installed. # # --exec # Prompts for each version, and executes with the full path # as an argument if approved. # --noprompt # Used with --exec, skips prompting and automatically executes the # command. Equivalent to yes|OldPrograms --exec . # --path # Outputs the full paths to the obsolete versions with no additional # information, suitable for piping to other commands such as xargs. # --version # Outputs version and licensing information. # # Example usage: # OldPrograms # OldPrograms --exec "rm -rf" #END #BEGIN version # OldPrograms 1.0 # Copyright (C) 2007 Michael Homer <=mwh> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #END #BEGIN termnotice # OldPrograms Copyright (C) 2007 Michael Homer <=mwh> # This program comes with ABSOLUTELY NO WARRANTY. It is free software, # and you are welcome to redistribute it under certain conditions. Run # `OldPrograms --version` for details. # #END