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

[ "$SYNOPKG_PKG_STATUS" = UPGRADE ] && exit 0

. "$(dirname $0)"/common

if [ -z "$pkgwizard_dataroot" ]; then
	log "$failed_illegal_dir_name" "$pkgwizard_dataroot"
	exit 1
fi

# check mariadb password
MARIADB_PASS="${pkgwizard_mysql_password:+-p$pkgwizard_mysql_password}"
if [ "$(mysqladmin ping "$MARIADB_PASS")" != "mysqld is alive" ]; then
	log "$failed_db_connect"
	exit 1
fi

# check share create
dataPath="$SHARE_PATH/$pkgwizard_dataroot"
if ! mkdir -p "$dataPath"; then
	log "$failed_illegal_dir_name" "$pkgwizard_dataroot"
	exit 1
fi
chmod 755 "$dataPath"

exit 0
