Skip to content

Instantly share code, notes, and snippets.

@nitmir
Last active August 29, 2015 12:14
Show Gist options
  • Save nitmir/5650acbcf48220625be9 to your computer and use it in GitHub Desktop.
Save nitmir/5650acbcf48220625be9 to your computer and use it in GitHub Desktop.
auto update pepperflashplugin using update-pepperflashplugin-nonfree in debian/ubuntu based distributions
#!/bin/bash
# Parameters
# <maxinterval> <probability>
# Updates the pepperflashplugin randomly, guaranteeing there
# won't be more than <maxinterval> seconds between each
# update. Otherwise, there is a a 1 in <probability>
# chance that an update will occur.
maxinterval=$1
probability=$2
statefile=/var/lib/update-pepperflashplugin/state.info
if [ -z $maxinterval ] || [ -z $probability ]; then
echo "usage $0 <maxinterval> <probability>"
exit 1
fi
current_date=$(date +'%s')
mkdir -p $(dirname $statefile)
if [ -f $statefile ]; then
last_run=$(date +%s -r $statefile)
else
last_run=0;
fi
function random(){
if [ $(($probability % 32768)) = 0 ]; then
r=$(($RANDOM % $probability))
else
r=$(($RANDOM * $probability / 32768))
fi
return $([ $r = 1 ]);
}
since_last_run=$(($current_date - $last_run));
if [ $since_last_run -ge $maxinterval ] || random; then
/usr/sbin/update-pepperflashplugin-nonfree --install --quiet &&
touch $statefile
fi
#!/bin/bash
# approxymatively update once a day (12 invokations a day, 1 in 12 chance
# that the update will occur), but ensure that there will never be more
# than two days (172800 seconds) interval between updates.
/path/to/autoupdate-pepperflashplugin 172800 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment