#!/bin/bash

phpCfgDir=/etc/php
browscapFile="$phpCfgDir/lite_php_browscap.ini"
versionFile="$phpCfgDir/browscap.version"
currentVersion=0

if [ -f "$versionFile" ]; then
    currentVersion=$(cat "$phpCfgDir/browscap.version")
fi

lastVersion=$(curl -s http://browscap.org/version-number)

if [ "$lastVersion" -gt "$currentVersion" ] || [ ! -f "$browscapFile" ]; then
    echo -n "$lastVersion" > "$versionFile"
    curl -s -o "$browscapFile" https://browscap.org/stream?q=Lite_PHP_BrowsCapINI
    echo "Browscap updated."
else
    echo "Browscap up to date."
fi
