⚠ Warning: Cascading Style Sheets↗ support is disabled in your browser. Please enable CSS for a better experience on this website.


Browscap #6000030

🗣 Translations

Website: browscap.org↗

Downloading the INI files here implies you agree to our fair usage policy. Any repeat attempts to download the files will be banned. We highly recommend that you request the version URL and compare your current version against the latest version before requesting the download URL.

We have implemented rate limiting and banning with the following rules:

Let' script this!

Download script

First, create the directory /var/local/lib/browscap/. It will hold all the browscap data. If you don't have it already, create the directory /var/local/log/ too.

Next, save this shell script in /usr/local/sbin/update-browscap-source:

#!/bin/bash

# select a RAMDISK or a temporary directory (i.e. /tmp or /var/tmp)
TMP="/var/tmp/"

# 1A) remote files
REMOTE_BASE="http://browscap.org/"
REMOTE_VERSION="${REMOTE_BASE}version-number"
REMOTE_INI="${REMOTE_BASE}stream?q=Full_PHP_BrowsCapINI"

# 1B) tmp files
FILE_VERSION="version"
FILE_NAME="full-php-browscap"
FILE_EXT=".ini"
FILE_INI="${FILE_NAME}${FILE_EXT}"

# 1C) local files
LOCAL_BASE="/var/local/lib/browscap/"
LOCAL_VERSION="${LOCAL_BASE}${FILE_VERSION}"

# 1Z) runtime
VERSION_LOCAL=
VERSION_REMOTE=

#  2) must be root or staff
if [ "root" != "`id -un`" ] && [ -z "`id -Gn | grep staff`" ];
then
	echo "ERROR: privilege denied!" >&2
	echo "GO AWAY!" >&2
	exit 255
fi

if ! umask 0002;
then
	echo "WARNING: unable to set umask" >&2
fi
echo "UMASK = $(umask)" >&2

#  3) check directory
if ! [ -d "${TMP}" ];
then
	echo "ERROR: ${TMP} does not exist!" >&2
	exit 255
fi
if ! [ -w "${TMP}" ];
then
	echo "ERROR: ${TMP} is not writable!" >&2
	exit 255
fi
echo "${TMP} is ok" >&2

if ! [ -d "${LOCAL_BASE}" ];
then
	echo "ERROR: ${LOCAL_BASE} does not exist!" >&2
	exit 255
fi
if ! [ -w "${LOCAL_BASE}" ];
then
	echo "ERROR: ${LOCAL_BASE} is not writable!" >&2
	exit 255
fi
echo "${LOCAL_BASE} is ok" >&2

if ! cd "${TMP}";
then
	echo "ERROR: unable to read ${TMP}" >&2
	exit 255
fi
echo "PWD = ${PWD}" >&2

#  4) get local version
if ! [ -f "${LOCAL_VERSION}" ];
then
	echo "WARNING: ${LOCAL_VERSION} does not exist!" >&2
else
	VERSION_LOCAL=$(cat "${LOCAL_VERSION}")
	echo "VERSION_LOCAL = ${VERSION_LOCAL}" >&2
fi

#  5) get remote version
VERSION_REMOTE=$(wget "${REMOTE_VERSION}" -q -O -)
if [ $? != 0 ];
then
	echo "ERROR: unable to download ${REMOTE_VERSION}" >&2
	exit 255
fi
echo "VERSION_REMOTE = ${VERSION_REMOTE}" >&2

#  6) terminate if equal
if [ "${VERSION_LOCAL}" == "${VERSION_REMOTE}" ]
then
	echo "Browscap is up to date (version=${VERSION_LOCAL})" >&2
	echo ${VERSION_LOCAL}
	exit 1
fi

echo "UPDATING BROWSCAP TO ${VERSION_REMOTE}" >&2

#  7) download new version
if ! wget "${REMOTE_INI}" -q -O "${FILE_INI}";
then
	echo "ERROR: unable to download ${REMOTE_INI}" >&2
	exit 255
fi

if ! cd "${LOCAL_BASE}";
then
	echo "ERROR: unable to read ${LOCAL_BASE}" >&2
	exit 255
fi
echo "PWD = ${PWD}" >&2

#  8) create the new version folder
if ! mkdir -p "${VERSION_REMOTE}";
then
	echo "ERROR: unable to create ${VERSION_REMOTE}/" >&2
fi
ls -dl "${VERSION_REMOTE}/" >&2

#  9) save the new ini file
echo cp "${TMP}${FILE_INI}" "${VERSION_REMOTE}/${FILE_INI}"
if ! cp "${TMP}${FILE_INI}" "${VERSION_REMOTE}/${FILE_INI}";
then
	echo "ERROR: unable to copy to ${VERSION_REMOTE}/${FILE_INI}" >&2
fi
# ls -l "${VERSION_REMOTE}/" >&2

# 10) link the new version to its final destination
echo ln -sf "${VERSION_REMOTE}/${FILE_INI}" "${FILE_INI}"
if ! ln -sf "${VERSION_REMOTE}/${FILE_INI}" "${FILE_INI}";
then
	echo "ERROR: unable to apply the new browscap" >&2
	exit 255
fi

# 11) update the version file
VERSION_LOCAL="${VERSION_REMOTE}"
echo -n "${VERSION_LOCAL}" > "${LOCAL_VERSION}"

# 12) end
echo ${VERSION_LOCAL}
exit 0

Make it executable, obviously, and … execute it!

$ chmod ug+x /usr/local/sbin/update-browscap-source
$ cd /var/local/lib/browscap/
$ ls -1
$ update-browscap-source 2>/dev/null
6000030
$ echo $?
0
$ ls -1
6000030
full-php-browscap.ini -> 6000030/full-php-browscap.ini
version
$ echo $(cat version)
6000030

The file full-php-browscap.ini will always be an up-to-date symbolic link to the latest version.

The script will only returns 0 if a successful update took place.

If there isn't any error (i.e. successful update or already up to date) the script will output the new/current browscap version (6000030) to STDOUT.

Finally, in case of error, a message is output to STDERR.

As long as you don't delete the files in /var/local/lib/browscap/, you can now call this script as many times as you want.

$ update-browscap-source 2>/dev/null
6000030
$ echo $?
1
$ ls -1
6000030
full-php-browscap.ini -> 6000030/full-php-browscap.ini
version
$ echo $(cat version)
6000030

CRON

Create the file /etc/cron.d/browscap:

#
# /etc/cron.d/browscap -- updates the browscap database
#

# runs at 12:35PM every Wednesday
35 12 * * 3 root /usr/local/sbin/update-browscap-source > /dev/null 2>> /var/local/log/browscap.log

You can pick your own update time and user (hopefully, one with limited privileges). Don't forget to reload cron!

$ /etc/init.d/cron reload

PHP

Edit the files /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini appropriately:

browscap = /var/local/lib/browscap/full-php-browscap.ini

Restart apache:

$ /etc/init.d/apache2 restart

Mapping files

The values returned by the browscap library can be mapped for more information. See Maps - Browscap

End

Enjoy!