#!/bin/ash

ver_new="$1"
ver_old="$2"

if [ "$(apk version -t "$ver_old" '1.12.0-r1')" = '<' ]; then
	tmp_new=/var/tmp/nginx
	tmp_old=/var/lib/nginx/tmp

	# Create a new temp directory, move data from the old one to the new
	# one and delete the old one.
	if [ -d "$tmp_old" ]; then
		echo "* Moving data from $tmp_old to $tmp_new..." >&2

		[ -d "$tmp_new" ] \
			|| install -d -m 700 -o nginx -g nginx "$tmp_new"
		rmdir "$tmp_old" 2>/dev/null \
			&& exit 0 \
			|| mv "$tmp_old"/* "$tmp_new"/
		rmdir "$tmp_old" 2>/dev/null \
			&& exit 0 \
			|| mv "$tmp_old"/.[!.]* "$tmp_new"/  # move dot files
		rmdir "$tmp_old"
	fi
fi

exit 0
