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

SHARE=docker
dataPath="$(servicetool --get-first-alive-volume)/$SHARE"

add_acl() {
	local path="$1"
	local acl="$2"
	if ! synoacltool -get "$path" | grep -q "$acl"; then
		synoacltool -add "$path" "$acl"
	fi
}

if ! synoshare --get "$SHARE"; then
	# check share create
	if ! synoshare --add "$SHARE" "" "$dataPath" "" "" "" 0 0; then
		logger -p 0 "Docker: failed to create docker share"
		exit 1
	fi
fi
add_acl "$dataPath" "owner:*:allow:rwxpdDaARWcCo:fd--"
add_acl "$dataPath" "everyone:*:allow:r-x---a-R-c--:fd--"

exit 0
