3 # Copyright (C) 2008 Jonathan Moore Liles #
5 # This program is free software; you can redistribute it and/or modify it #
6 # under the terms of the GNU General Public License as published by the #
7 # Free Software Foundation; either version 2 of the License, or (at your #
8 # option) any later version. #
10 # This program is distributed in the hope that it will be useful, but WITHOUT #
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
15 # You should have received a copy of the GNU General Public License along #
16 # with This program; see the file COPYING. If not,write to the Free Software #
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
19 ## remove-unused-sources
21 # April 2008, Jonathan Moore Liles
23 # Simple script to scan a compacted Non-DAW project and remove all
24 # unused sources from disk.
28 # $ remove-unused-sources ~/audio/'The Best Song Ever'
32 # This script will not ask for comfirmation! It will ruthlessly
33 # delete all unused sources! You have been warned.
50 rm -f "${TEMP}/all-sources" "${TEMP}/used-sources"
55 diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2"
67 PSIZE
=`stat -c '%s' "${FILE}.peak" 2>/dev/null`
68 SIZE
=`stat -c '%s' "${FILE}" 2>/dev/null`
74 echo "Would remove \"${FILE}\", if it existed."
78 echo "Would remove: ${FILE}"
82 echo "Moving unused source \"${FILE}\"..."
83 mv -f .
/"${FILE}" .
/"${FILE}".peak ..
/unused-sources
85 echo "Removing unused source \"${FILE}\"..."
86 rm -f .
/"${FILE}" .
/"${FILE}".peak
90 TOTAL
=$
(( $TOTAL + $SIZE + $PSIZE ))
95 echo "...Freeing a total of $(($TOTAL / ( 1024 * 1024 ) ))MB"
100 fatal
"Usage: $0 [-n] [-c] [-m|-d] path/to/project"
104 while getopts "dmnc" o
110 c
) ONLY_COMPACTED
=1 ;;
112 *) echo "$o" && usage
;;
116 shift $
(( $OPTIND - 1 ))
119 [ $# -eq 1 ] || usage
121 cd "$PROJECT" || fatal
"No such project"
123 [ -f history ] && [ -f info
] || fatal
"Not a Non-DAW project?"
125 [ -f .lock
] && fatal
"Project appears to be in use"
127 if [ "$ONLY_COMPACTED" = 1 ]
129 grep -v '\(^\{\|\}$\)\|create' history && fatal
"Not a compacted project"
132 echo "Scanning \"${PROJECT}\"..."
134 sed -n 's/^\s*Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history |
sort |
uniq > "${TEMP}/used-sources"
136 cd sources || fatal
"Can't change to source directory"
138 [ "$MOVE" = 1 ] && mkdir ..
/unused-sources
2>/dev
/null
140 ls -1 |
grep -v '\.peak$' |
sort > "${TEMP}/all-sources"
142 set_diff
"${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources