Last active
March 11, 2016 15:43
-
-
Save PhrozenByte/a5e47838ba5397571148 to your computer and use it in GitHub Desktop.
/etc/cron.daily/update-flashplugin-nonfree
This file contains 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 | |
# cron.daily.update-flashplugin-nonfree | |
# Version 2.2 | |
# | |
# SHORT DESCRIPTION: | |
# Daily cronjob executing Debian's `update-flashplugin-nonfree' command | |
# | |
# COPYRIGHT AND LICENSING: | |
# Copyright (C) 2014-2016 Daniel Rudolf <http://www.daniel-rudolf.de/> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, version 3 of the License only. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# don't output anything (except errors) | |
QUIET="no" | |
# command to execute to check whether system is on AC power or not | |
# prevents flashplugin updates on non-AC power; clear to disable | |
ON_AC_POWER_CMD="$(which on_ac_power)" | |
# use this URL to check whether system is online or not; clear to disable | |
CONNECTION_TEST_URL="http://debian.org/" | |
# command to execute to update the flashplugin | |
UPDATE_FLASH_CMD="$(which update-flashplugin-nonfree)" | |
if [ "$QUIET" == "yes" ]; then | |
exec 1> /dev/null | |
fi | |
if [ -n "$ON_AC_POWER_CMD" ]; then | |
if [ ! -x "$ON_AC_POWER_CMD" ]; then | |
echo "Warning: \`on_ac_power\` not executable; assuming system is on main power..." >&2 | |
else | |
"$ON_AC_POWER_CMD" | |
POWER=$? | |
# system NOT on main power - exit | |
if [ $POWER -eq 1 ]; then | |
exit 0 | |
fi | |
fi | |
fi | |
function checkFlashUpdates() { | |
"$UPDATE_FLASH_CMD" --status 2> /dev/null | head -n 2 | grep -oE "([0-9]+\.)*[0-9]+$" | { | |
read "FLASH_INSTALLED" | |
read "FLASH_AVAILABLE" | |
[ -z "$FLASH_AVAILABLE" ] && exit 2 | |
[ "$FLASH_INSTALLED" != "$FLASH_AVAILABLE" ] && exit 1 | |
exit 0 | |
} | |
return $? | |
} | |
if [ -z "$UPDATE_FLASH_CMD" ]; then | |
echo "Unable to update flash plugin: \`update-flashplugin-nonfree\` not found" >&2 | |
exit 1 | |
elif [ ! -x "$UPDATE_FLASH_CMD" ]; then | |
echo "Unable to update flash plugin: \`update-flashplugin-nonfree\` not executable" >&2 | |
exit 1 | |
else | |
# check for updates | |
checkFlashUpdates | |
CHECK_FLASH_UPDATE_STATUS=$? | |
if [ $CHECK_FLASH_UPDATE_STATUS -eq 0 ]; then | |
exit 0 | |
elif [ $CHECK_FLASH_UPDATE_STATUS -eq 2 ]; then | |
if [ -n "$CONNECTION_TEST_URL" ]; then | |
wget -q --tries=10 --timeout=20 --spider "$CONNECTION_TEST_URL" | |
CONNECTION_STATUS=$? | |
if [ $CONNECTION_STATUS -eq 0 ]; then | |
echo "Unable to update flash plugin: unable to determine available version" >&2 | |
exit 1 | |
elif [ $CONNECTION_STATUS -ne 4 ]; then | |
echo "Unable to update flash plugin: unable to determine available version" >&2 | |
echo "Testing the systems internet connection using \`wget \"$CONNECTION_TEST_URL\"\` failed (exited $CONNECTION_STATUS)" >&2 | |
exit 1 | |
fi | |
fi | |
if [ "$QUIET" != "yes" ]; then | |
echo "Unable to update flash plugin: unable to determine available version; system is probably not connected to the internet" | |
fi | |
exit 0 | |
fi | |
# try to update flashplugin | |
"$UPDATE_FLASH_CMD" --install --verbose 2>&1 | |
UPDATE_FLASH_STATUS=$? | |
if [ $UPDATE_FLASH_STATUS -ne 0 ]; then | |
echo "Unable to update flash plugin: \`update-flashplugin-nonfree --install\` failed (exited $UPDATE_FLASH_STATUS)" >&2 | |
exit 1 | |
elif [ "$QUIET" != "yes" ]; then | |
# don't trust the installer... | |
checkFlashUpdates | |
CHECK_FLASH_UPDATE_STATUS=$? | |
if [ $CHECK_FLASH_UPDATE_STATUS -eq 2 ]; then | |
echo "Unable to update flash plugin: unable to determine available version after installation; internet connection suddenly lost?" >&2 | |
exit 1 | |
elif [ $CHECK_FLASH_UPDATE_STATUS -ne 0 ]; then | |
echo "Unable to update flash plugin: installed and available version differ after \`update-flashplugin-nonfree --install\`" >&2 | |
exit 1 | |
fi | |
exit 0 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment