#!/bin/bash
[ "$2" == "" ] && exec echo "Usage: $0 <SOURCE_PATH> <ROTATE_PATH> <FILENAME_FILTER>"

SOURCE_PATH=$1
ROTATE_PATH=$2
FILENAME_FILTER=$3

for file in $(ls $SOURCE_PATH); do
	if [ ! -z $FILENAME_FILTER ]; then
		filter=$(echo $file | grep $FILENAME_FILTER)
		if [ ! -z $filter ]; then
			echo "1..."
			echo $file
		else
			echo "2..."
			continue
		fi
	else
		echo "3..."
		echo $file
	fi
	echo "4..."
	if [ ! -d "$ROTATE_PATH" ]; then
		#echo "mkdir -p $ROTATE_PATH"
		mkdir -p $ROTATE_PATH
	fi
	#echo "cp -arf $SOURCE_PATH/$file $ROTATE_PATH/."
	#echo "$HOME/bin/xz -3 $ROTATE_PATH/$file"
	mv $SOURCE_PATH/$file $ROTATE_PATH/.
	$HOME/bin/xz -3 $ROTATE_PATH/$file
done
