#!/bin/sh
PROTOCOL=$1
DOMAIN=$2

modify_htaccess()
{
		URI=$1
		cat > abvw/.htaccess << EOF
SetEnvIf Referer "^$URI" RefererCheck
Order deny,allow
Deny from all
Allow from env=RefererCheck
<Files ~ "\.(js|json)$">
Header add Pragma "no-cache"
Header set Cache-Control no-cache
</Files>
EOF
}

modify_api()
{
	URI_PREFIX=$1
	cat > abvw/common/json/sys/conf.json << EOF
{
        "apiUrl"              : "$URI_PREFIX/{0}/abvapi",
        "apiLoginUrl"         : "$URI_PREFIX/nuabvapi",
        "apiResourceDlUrl"    : "$URI_PREFIX/{0}/dl",
        "bookShelfCount"      : 15,
        "bookListCount"       : 15,
        "screenlockTimeDefault" : 30,
        "pushPageCount"       : 5,
        "pushTimePeriod"      : 60,
        "debug"               : true,
        "loginPage"           : "index.html",
        "anonymousLoginFlg"   : true,
        "anonymousLoginPath"  : "",
        "anonymousLoginId"    : "",
        "appName"             : "ABookWebCL",
        "appVersion"          : "0.0.1"
}
EOF
}

modify_htaccess "$PROTOCOL://$DOMAIN/webad/"
modify_api "$PROTOCOL://$DOMAIN/acms"

# case "$1" in
#		localhost)
#				modify_htaccess "http://localhost/nmoto/Sites/webviewer/"
#				modify_api "https://web3.agentec.jp/acms"
#				;;
#		web2)
#				modify_htaccess "https://web2.mediaservice.agentec.jp/mc/webviewer/"
#				modify_api "https://web2.mediaservice.agentec.jp/mc"
#				;;
#		web3)
#				modify_htaccess "https://web3.agentec.jp/web/"
#				modify_api "https://web3.agentec.jp/acms"
#				;;
#		*)
#				echo $"Usage: $0 {localhost|web2|web3}"
#				;;
# esac
