Some extra safety checks when appending to crontab

This commit is contained in:
Bob Mottram 2018-04-07 18:39:54 +01:00
parent 6e65880756
commit d1535c71ea
1 changed files with 9 additions and 5 deletions

View File

@ -95,12 +95,16 @@ function refresh_gpg_keys {
fi fi
sudo cp /etc/crontab ~/temp_crontab sudo cp /etc/crontab ~/temp_crontab
sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab
if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then if [ -f ~/temp_crontab ]; then
echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab if grep -q 'test' ~/temp_crontab; then
sudo cp ~/temp_crontab /etc/crontab if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
sudo chown root:root /etc/crontab echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
sudo cp ~/temp_crontab /etc/crontab
sudo chown root:root /etc/crontab
fi
fi
rm ~/temp_crontab
fi fi
rm ~/temp_crontab
} }
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html # see https://stribika.github.io/2015/01/04/secure-secure-shell.html