#!/bin/bash
##############################################################################
#
# Copyright (C) 2014 - 2016 x-odos GmbH
#
##############################################################################

ACTION=$1
function echolog {
echo "`date +'%m/%d/%Y %H:%M:%S'` - $1"
}

case $ACTION in
  mirror-flac-mp3.again )
	while [ -f /etc/x-stream/mirror-flac-mp3.running ]; do 
		sleep 30
	done
	
	echolog "Mirroring FLAC to mp3 one last time to make sure we got them all." >> /var/log/mirror.log
	rm /etc/x-stream/mirror-flac-mp3.again
	/usr/local/sbin/mirror-flac-mp3  >> /var/log/mirror.log &
	;;
	
  mirror-flac-aac.again )
	while [ -f /etc/x-stream/mirror-flac-aac.running ]; do 
		sleep 30
	done
	
	echolog "Mirroring FLAC to AAC one last time to make sure we got them all." >> /var/log/mirror.log
	rm /etc/x-stream/mirror-flac-aac.again
	
	flacdir=/storage/music/Local/flac/
	m4adir=/storage/music/m4a/
	/usr/local/sbin/flac2m4a.sh "$flacdir" "$m4adir" >> /var/log/mirror.log &
	;;

esac

