#!/bin/sh

ver_old="$2"

if [ "$(apk version -t "$ver_old" '2.16.0-r0')" = '<' ]; then
	cat >&2 <<-EOF
	*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
	*! Before upgrading AgensGraph, dump the cluster
	*! (/usr/libexec/agensgraph/pg_dumpall) and then restore the backup.
	*!
	EOF
	if [ -t 1 ]; then  # if &1 is terminal
		echo '*! If you want to abort the upgrade, press Ctr+C.'
		printf '*! Upgrade will continue in seconds '
		count=10
		while [ $count -gt 0 ]; do
			printf "$count..." >&2
			sleep 1
			count=$(( count - 1 ))
		done
		echo '*!'
	fi
	echo '*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*' >&2
fi
