Commit 8b587af5 authored by Andrew's avatar Andrew

first

parent 5d0a49f7
config
\ No newline at end of file
#token for your site
TOKEN=""
#Path to file. Should be accessible through the web and included to <head> of site pages
CODE_PATH="${HOME}/code.js"
#Generate gzipped version for nginx_gzip module (strongly recommended if module is enabled)
GZIP_CODE=true
\ No newline at end of file
#!/usr/bin/env bash
function error_exit {
echo "$1" >&2
exit "${2:-1}"
}
[[ -e "config" ]] || error_exit "Config not found: please copy config.default to config (no extension)"
. config
ARGON_ENDPOINT="http://emd.instraroam.net/token/${TOKEN}"
SCRIPT_HEADER='// HEADER'
CODE_DIR=$(dirname "${CODE_PATH}")
VERSION_REGEXP="(?<=/\*)[0-9a-f_-]+(?=\*/)"
[[ ! -z "$TOKEN" ]] || error_exit "Config error: TOKEN is empty"
[[ ! -z "$CODE_PATH" ]] || error_exit "Config error: CODE_PATH is empty"
[[ -d "$CODE_DIR" ]] || error_exit "Path ${CODE_DIR} is not a directory"
[[ -e "$CODE_PATH" ]] || > ${CODE_PATH}
[[ -w "$CODE_PATH" ]] || error_exit "File ${CODE_PATH} is not writable"
CODE=$(curl -s -L "${ARGON_ENDPOINT}")
R_VERSION=$(grep -oP ${VERSION_REGEXP} <<< ${CODE})
[[ ! -z "$R_VERSION" ]] || error_exit "Version extracting error. Incorrect TOKEN"
L_VERSION=$(grep -oP ${VERSION_REGEXP} ${CODE_PATH})
if [[ ${R_VERSION} != ${L_VERSION} ]]; then
[[ -z "$SCRIPT_HEADER" ]] || CODE="${SCRIPT_HEADER}\n${CODE}"
echo -e ${CODE} >${CODE_PATH}
[ "$GZIP_CODE" != true ] || gzip -q -f -9 -k ${CODE_PATH}
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment