#!/bin/sh
# Copyright (C) 2000-2020 Synology Inc. All rights reserved.

### This script will be executed when package installed and upgraded.
### Actions after package installed.
### ex. create database, create symbolic link...
# Un radio est true s'il est coche, ex: if [ "$myradio1" = true ] ; then

# pour crer le dossier de configuration de l'agent
if [ ! -d "/var/packages/BeemoBackupAgent/etc/dsr" ]; then
	mkdir /var/packages/BeemoBackupAgent/etc/dsr
fi

echo "Activation code is ($activation_code)"

if [ ! -z "$activation_code" ] && [ "$activation_code" != "000000000000000000000000" ]; then
	/var/packages/BeemoBackupAgent/scripts/start-stop-status start
	ps aux | grep dsr
	STR_RES=$(/var/packages/BeemoBackupAgent/target/dsr/dsr --associate $activation_code | grep "Successful" | grep -v grep)
	if [ -z "$STR_RES" ]; then
		echo "Nomad association failed"
		/var/packages/BeemoBackupAgent/scripts/start-stop-status stop
		exit 2
	fi

	echo "Nomad association success"
fi

exit 0
