blob: bd1c0ae0afc6266d4bcce4986a706331f47b83dd [file] [log] [blame]
#!/bin/bash
# Given a script and it's content SHA-1, determine if it should run based upon
# whether its content has changed.
#
# Returns 0 if the script should run, other values indicate it should not run.
#
function should-run-script {
local script="$1"; shift
local script_sha1="$1"; shift
if [[ -f /var/cache/runonce/$fname ]]; then
previous_sha1=$(cat /var/cache/runonce/$fname)
if [[ $script_sha1 == $previous_sha1 ]]; then
return 1
fi
fi
return 0
}
function main {
local script=""
for script in /etc/runonce.d/*; do
local script_sha1=$(sha1sum $script |awk '{ print $1 }')
if ! should-run-script $script $script_sha1; then
continue;
fi
$script
if [[ $? == 0 ]]; then
local fname=$(basename $script)
echo $script_sha1 > /var/cache/runonce/$fname
fi
done
}
main