#!/bin/bash
#
# Parallels Tools for Linux installer entry point
#
# Copyright (c) 1999-2017 Parallels International GmbH.
# All rights reserved.
# http://www.parallels.com

BASE_DIR=$(dirname "$(readlink -f "$0")")
INSTALLER_DIR=$BASE_DIR/installer

if [[ $# > 0 ]]; then
	# we run this script only if run without any parameters
	exec "$INSTALLER_DIR/install-cli.sh" "$@"
fi

check_requirements() {
	if [[ "$(uname -s)" != "Linux" ]]; then
		echo "Error: these Parallels Guest Tools can be installed on" \
			"Linux guest OS only." >&2
		exit 101
	fi

	if [[ "$(id -u)" != "0" ]]; then
		echo "Error: you do not have permissions to" \
			"run this script." >&2
		exit 102
	fi
}

check_requirements
case "$(uname -m)" in
	x86_64)
		FLAG_CHECK_GUI="Yes"
		exec "$INSTALLER_DIR/installer.x86_64"
		;;
	i686)
		FLAG_CHECK_GUI="Yes"
		exec "$INSTALLER_DIR/installer.x86_32"
		;;
	aarch64)
		FLAG_CHECK_GUI="Yes"
		exec "$INSTALLER_DIR/installer.aarch64"
		;;
	*)
		echo "Arhitecture $(uname -m) is not supported" >&2
		exit 103
		;;
esac

exit $?

