Last active
August 1, 2017 19:33
-
-
Save szepeviktor/7374696bce6fbb2ed285 to your computer and use it in GitHub Desktop.
Check Speedtest Mini script's expiration and update it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Check Speedtest Mini script's expiration and update it. | |
# | |
# DEPENDS :apt-get install swfmill html2text | |
# CRON-MONTHLY :/usr/local/bin/update-speedtest-mini.sh | |
################## | |
################## MOVED TO: https://github.com/szepeviktor/debian-server-tools/blob/master/monitoring/update-speedtest-mini.sh | |
################## | |
exit 0 | |
MINI_PATH="/home/viktor/public_dev/server/speed" | |
MINI_URL="http://c.speedtest.net/mini/mini.zip" | |
Die() { | |
echo "[$(basename "$0")] ERROR: ($*)" >&2 | |
exit 1 | |
} | |
Check_expiration() { | |
local MODIFY_DATE | |
local -i MODIFY_SEC | |
local -i MONTH_AGO | |
if ! [ -f "${MINI_PATH}/speedtest.swf" ]; then | |
Die "Flash file is missing." | |
fi | |
MODIFY_DATE="$(swfmill swf2xml "${MINI_PATH}/speedtest.swf" 2> /dev/null \ | |
| grep -o '<xmp:ModifyDate>.*</xmp:ModifyDate>' \ | |
| html2text -nobs)" | |
MODIFY_SEC="$(date --date "$MODIFY_DATE" --utc +%s)" | |
# older than a month | |
MONTH_AGO="$(date --utc --date="1 month ago" +%s)" | |
if [ "$MODIFY_SEC" -lt "$MONTH_AGO" ]; then | |
Update_mini | |
fi | |
} | |
Update_mini() { | |
local NAME="$(basename "$MINI_URL")" | |
wget -q --limit-rate=10m -O "${MINI_PATH}/${NAME}" "$MINI_URL" || Die "ZIP download" | |
if [ -d "${MINI_PATH}/mini" ]; then | |
rm -r "${MINI_PATH}/mini" || Die "Failed to remove old files: ./mini" | |
fi | |
if [ -d "${MINI_PATH}/speedtest" ]; then | |
rm -r "${MINI_PATH}/speedtest" || Die "Failed to remove old files: ./speedtest" | |
fi | |
unzip "${MINI_PATH}/${NAME}" -d "${MINI_PATH}/" || Die "Extraction failed." | |
rm "${MINI_PATH}/${NAME}" || Die "ZIP cannot be removed." | |
mv "${MINI_PATH}/mini/speedtest.swf" "${MINI_PATH}/" || Die "Flash file cannot be moved in place." | |
mv "${MINI_PATH}/mini/speedtest" "${MINI_PATH}/" || Die "Payload files cannot be moved in place." | |
mv "${MINI_PATH}/mini/crossdomain.xml" "${MINI_PATH}/" || Die "crossdomain.xml cannot be moved in place." | |
mv "${MINI_PATH}/mini/index-php.html" "${MINI_PATH}/index.php" || Die "Index file cannot be moved in place." | |
rm -r "${MINI_PATH}/mini" || Die "Failed to remove unnecassary files." | |
find "${MINI_PATH}" -type f -exec chmod -x \{\} \; || Die "Failed to turn off execution bit." | |
} | |
Check_expiration |
Yes. Thank you.
Fixed.
Script lives on in my Debian-server-tools repo:
https://github.com/szepeviktor/debian-server-tools/blob/master/monitoring/update-speedtest-mini.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 28 need to change $EXPIRE to $MODIFY_DATE ???