#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
    DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $DIR/../

. ./meta/env
. ./meta/cdn

cat <<EOF > /tmp/qiniu.json
{
    "src":"$DIR/../dist/webapp",
    "dest":"$CDN_DEST",
    "debug_level":  1,
    "bucket":"$CDN_BUCKET"
}
EOF

echo "CDN config:"
cat /tmp/qiniu.json

rm -rf ~/.qrsync 2>/dev/null
./util/resource/qrsync -check-exist=false /tmp/qiniu.json

