#!/bin/bash
#	    http://www.kahealani.net/posix/bin/riparchive
# 2012-04-27 18:43:00+00:00	/usr/local/bin/riparchive
# by  celeste:crystalfaery

# Presuming there have been one or more streamrippers running,
# dumping into `hostname`:/home/downloads/streams/
# then by invoking riparchive, we
# then tidy the names of the files and directories generated, and
# fill-in holes in the archive from any incomplete downloads.
# then clones the files to my_twin.
# Miro will find and catalogue them for listening.
# //sysin dd "Rube Goldberg"

pkill streamripper	# which generates non POSIX filenames
sleep 60		# we could test for running processes instead
cd /home/audio/streams||exit 1	# default output of streamripper jobs.
name_tidy		# first tidy the top level of directories names.
for directory in *	# then for each stream/directory
do			# migrate it to faery: else complain of failure.
	if [ -d					 $directory/incomplete ]
	then	# we have an incomplete directory to handle
		name_tidy -r			 $directory/incomplete	# tidy the incompletes
		# partials get backdated to make them obsolete compared to any whole copies we might successfully download
		touch -t 197001012359		 $directory/incomplete/*
		yes n | mv -i 2>/dev/null	 $directory/incomplete/* \
						 $directory/		# save the fragments that don't overwrite possible whole files
		rm -rf				 $directory/incomplete	# in(tegration)complete
		name_tidy -r			 $directory		# tidy the integrated directory
	fi
	rsync -auvzH	 	 /home/audio/streams/$directory	~/documents/audio/streams	# backup
	completion=$?
	if [ $completion ]
	then
		rm -rf				 $directory	# WE HAVE MOVED THE STREAMRIPS, NOT COPIED THEM
	else
		echo -n	 "/home/downloads/streams/$directory migration: $completion" | \
		mail -s	 "$0"	`whoami`
	fi
done
exit $completion	# exit status code has not yet been written, so never return 0.


syntax highlighted by Code2HTML, v. 0.9.1