#!/bin/sh # vivc Vorbis comment editor front-end v0.2 # [cc] 2001 Greg Wooledge # This program is in the public domain, and may be used without restrictions. prog=`basename $0` usage() { echo "usage: $prog oggfile [...]" 1>&2 exit 1 } [ $# -lt 1 ] && usage ed=vi [ -n "$EDITOR" ] && ed="$EDITOR" [ -n "$VISUAL" ] && ed="$VISUAL" if [ -w $PWD ]; then tmp=.vivc.$$ tmpogg=.vivc.$$.ogg else tmp=/tmp/vivc.$$ tmpogg=/tmp/vivc.$$.ogg fi dosigs() { trap 'echo "$prog: killed by signal" 1>&2; rm -f $tmp $tmpogg; exit 1' \ 1 2 3 15 } dosigs dovc() { vorbiscomment -l "$1" >$tmp if [ $? -ne 0 ]; then echo "$prog: could not read vorbis comments from '$1'" 1>&2 rm -f $tmp return 0 fi "$ed" $tmp # Can't assume anything about the editor's return code. vorbiscomment -w "$1" $tmpogg <$tmp if [ $? -ne 0 ]; then echo "$prog: could not write temporary file '$tmpogg'" 1>&2 rm -f $tmp $tmpogg return 0 fi rm $tmp # ignore signals during this part trap '' 1 2 3 15 mv "$1" "$1".bak mv $tmpogg "$1" if [ $? -ne 0 ]; then echo "$prog: could not replace file '$1' with new version" 1>&2 echo "$prog: your original file is in '$1.bak'" 1>&2 echo "$prog: your modified Ogg Vorbis file is in $tmpogg" 1>&2 # do NOT rm $tmpogg! return 1 # fatal, do not continue fi rm "$1".bak # allow signals again dosigs } for file; do if [ ! -w "$file" ]; then echo "$prog: file '$file' is not writable, skipping" continue fi dovc "$file" rc=$? [ $rc -gt 0 ] && exit $rc done exit 0