#!/bin/bash

set -eu
set -o pipefail

source_filename="$1"
destination_filename="$2"

if [ "${3:-}" != "" ]
then
    echo "Usage: $0 source_filename destination_filename" 1>&2
    exit 1
fi

if [ -f "$source_filename" ]
then
    # Good, it exists
    if [ -f "$destination_filename" ]
    then
        echo "$0: $destination_filename already exists" 1>&2
        exit 1
    else
        mv "$source_filename" "$destination_filename"
        # These are some ancillary files to move too.
        for extension in .views .rip-output.xz .rip-output
        do
            if [ -f "$source_filename""$extension" ]
            then
                mv \
                    "$source_filename""$extension" \
                    "$destination_filename""$extension"
            fi
        done
    fi
else
    # Bad, it does not exist
    echo "$0: $source_filename does not exist" 1>&2
    exit 1
fi