#!/bin/bash
#
# Stub script for old updater that spoofs the version number
#
# The spoofed version doesn't need to match what's being migrated to, it
# only needs to match the spoofed updater-version.txt. I think.

version=3.0.000000                     # spoofed version number
real=cloudbackup-updater.real          # install actual updater with this name
pkg=/tmp/cloudbackup-updater-$version  # unpack directory

# The old updater will install this stub in place of itself, then run it to
# check the version number. Take advantage of the opportunity to grab the real
# updater from the unpack directory, so a migration error after this point
# doesn't brick the old updater.
#
# (an error in between copying this file and running it *will* brick the
# updater, but that can't be helped, and it's a short window)

mv -f $pkg/$real /usr/bin/$real 2>/dev/null

# Prepend the spoofed version string to --version.
if [ "$1" = "--version" ]; then
	echo "Version: $version (0000000000000000000000000000000000000000)"
	echo
	echo "Spoofed for v3 migration. Actual output from $real follows:"
	echo
fi

# Now forward all arguments to the real updater. Note that this includes
# --version, so the real version still gets printed (after the spoofed one)
# for troubleshooting purposes.
"$real" "$@"
