2008-04-26 04:56:03 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
# Copyright (C) 2008 Jonathan Moore Liles #
|
|
|
|
# #
|
|
|
|
# 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 2 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; see the file COPYING. If not,write to the Free Software #
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
|
|
|
|
|
2008-04-26 04:56:03 +02:00
|
|
|
## remove-unused-sources
|
|
|
|
#
|
|
|
|
# April 2008, Jonathan Moore Liles
|
|
|
|
#
|
2008-06-21 21:29:15 +02:00
|
|
|
# Simple script to scan a compacted Non-DAW project and remove all
|
2008-04-26 04:56:03 +02:00
|
|
|
# unused sources from disk.
|
|
|
|
#
|
|
|
|
# USAGE:
|
|
|
|
#
|
|
|
|
# $ remove-unused-sources ~/audio/'The Best Song Ever'
|
|
|
|
#
|
|
|
|
# NOTES:
|
|
|
|
#
|
|
|
|
# This script will not ask for comfirmation! It will ruthlessly
|
|
|
|
# delete all unused sources! You have been warned.
|
|
|
|
#
|
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
DRY_RUN=
|
|
|
|
ONLY_COMPACTED=
|
|
|
|
MOVE=1
|
2008-04-26 04:56:03 +02:00
|
|
|
|
|
|
|
fatal ()
|
|
|
|
{
|
|
|
|
echo Error: "$1"
|
|
|
|
echo 'Aborting!'
|
|
|
|
cleanup
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
cleanup ()
|
|
|
|
{
|
|
|
|
rm -f "${TEMP}/all-sources" "${TEMP}/used-sources"
|
|
|
|
}
|
|
|
|
|
2008-04-26 04:56:03 +02:00
|
|
|
set_diff ()
|
|
|
|
{
|
2008-06-21 21:29:15 +02:00
|
|
|
diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2"
|
2008-04-26 04:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
remove_sources ()
|
|
|
|
{
|
2008-12-06 07:29:07 +01:00
|
|
|
local TOTAL=0
|
2008-04-26 04:56:03 +02:00
|
|
|
local FILE
|
2008-12-06 07:29:07 +01:00
|
|
|
local SIZE
|
2008-12-06 07:56:55 +01:00
|
|
|
local PSIZE
|
2008-04-26 04:56:03 +02:00
|
|
|
while read FILE
|
|
|
|
do
|
2008-12-06 07:29:07 +01:00
|
|
|
|
2008-12-06 07:56:55 +01:00
|
|
|
PSIZE=`stat -c '%s' "${FILE}.peak" 2>/dev/null`
|
2008-12-17 08:18:20 +01:00
|
|
|
SIZE=`stat -c '%s' "${FILE}" 2>/dev/null`
|
|
|
|
|
|
|
|
PSIZE=${PSIZE:-0}
|
2008-12-06 07:29:07 +01:00
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
if ! [ -f "${FILE}" ]
|
2008-06-21 21:29:15 +02:00
|
|
|
then
|
2008-12-06 07:29:07 +01:00
|
|
|
echo "Would remove \"${FILE}\", if it existed."
|
2008-06-21 21:29:15 +02:00
|
|
|
else
|
2008-12-17 08:18:20 +01:00
|
|
|
if [ "$DRY_RUN" = 1 ]
|
2008-12-06 07:29:07 +01:00
|
|
|
then
|
|
|
|
echo "Would remove: ${FILE}"
|
|
|
|
else
|
2008-12-17 08:18:20 +01:00
|
|
|
if [ "$MOVE" = 1 ]
|
|
|
|
then
|
|
|
|
echo "Moving unused source \"${FILE}\"..."
|
|
|
|
mv -f ./"${FILE}" ./"${FILE}".peak ../unused-sources
|
|
|
|
else
|
|
|
|
echo "Removing unused source \"${FILE}\"..."
|
|
|
|
rm -f ./"${FILE}" ./"${FILE}".peak
|
|
|
|
fi
|
2008-12-06 07:29:07 +01:00
|
|
|
fi
|
|
|
|
|
2008-12-06 07:56:55 +01:00
|
|
|
TOTAL=$(( $TOTAL + $SIZE + $PSIZE ))
|
2008-06-21 21:29:15 +02:00
|
|
|
fi
|
2008-12-06 07:29:07 +01:00
|
|
|
|
2008-04-26 04:56:03 +02:00
|
|
|
done
|
2008-12-06 07:29:07 +01:00
|
|
|
|
|
|
|
echo "...Freeing a total of $(($TOTAL / ( 1024 * 1024 ) ))MB"
|
2008-04-26 04:56:03 +02:00
|
|
|
}
|
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
usage ()
|
|
|
|
{
|
|
|
|
fatal "Usage: $0 [-n] [-c] [-m|-d] path/to/project"
|
|
|
|
}
|
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
while getopts "dmnc" o
|
|
|
|
do
|
|
|
|
case "$o" in
|
|
|
|
d) MOVE= ;;
|
|
|
|
m) MOVE=1 ;;
|
|
|
|
n) DRY_RUN=1 ;;
|
|
|
|
c) ONLY_COMPACTED=1 ;;
|
|
|
|
\?) usage ;;
|
|
|
|
*) echo "$o" && usage ;;
|
|
|
|
esac
|
|
|
|
done
|
2008-06-21 21:29:15 +02:00
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
shift $(( $OPTIND - 1 ))
|
2008-06-21 21:29:15 +02:00
|
|
|
PROJECT="$1"
|
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
[ $# -eq 1 ] || usage
|
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
cd "$PROJECT" || fatal "No such project"
|
2008-04-26 04:56:03 +02:00
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
[ -f history ] && [ -f info ] || fatal "Not a Non-DAW project?"
|
2008-04-26 04:56:03 +02:00
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
[ -f .lock ] && fatal "Project appears to be in use"
|
2008-04-26 04:56:03 +02:00
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
if [ "$ONLY_COMPACTED" = 1 ]
|
2008-06-21 21:29:15 +02:00
|
|
|
then
|
|
|
|
grep -v '\(^\{\|\}$\)\|create' history && fatal "Not a compacted project"
|
|
|
|
fi
|
2008-04-26 04:56:03 +02:00
|
|
|
|
2008-06-21 21:29:15 +02:00
|
|
|
echo "Scanning \"${PROJECT}\"..."
|
2008-04-26 04:56:03 +02:00
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
sed -n 's/^\s*Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources"
|
2008-04-26 04:56:03 +02:00
|
|
|
|
|
|
|
cd sources || fatal "Can't change to source directory"
|
|
|
|
|
2008-12-17 08:18:20 +01:00
|
|
|
[ "$MOVE" = 1 ] && mkdir ../unused-sources 2>/dev/null
|
|
|
|
|
2008-04-26 04:56:03 +02:00
|
|
|
ls -1 | grep -v '\.peak$' | sort > "${TEMP}/all-sources"
|
|
|
|
|
|
|
|
set_diff "${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources
|
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
|
|
|
echo "Done."
|