|
From: <abe...@us...> - 2017-01-15 16:17:01
|
Revision: 8097
http://sourceforge.net/p/astlinux/code/8097
Author: abelbeck
Date: 2017-01-15 16:16:59 +0000 (Sun, 15 Jan 2017)
Log Message:
-----------
acme, acme-client, add native support for --installcronjob and --uninstallcronjob
Modified Paths:
--------------
branches/1.0/package/acme/acme-client.sh
Modified: branches/1.0/package/acme/acme-client.sh
===================================================================
--- branches/1.0/package/acme/acme-client.sh 2017-01-15 01:34:33 UTC (rev 8096)
+++ branches/1.0/package/acme/acme-client.sh 2017-01-15 16:16:59 UTC (rev 8097)
@@ -25,14 +25,52 @@
exit 1
fi
+CRON_FILE="/var/spool/cron/crontabs/root"
+
+CRON_UPDATE="/var/spool/cron/crontabs/cron.update"
+
+is_cron_entry()
+{
+ grep -q '/usr/sbin/acme-client ' "$CRON_FILE"
+}
+
add_cron_entry()
{
- echo "acme-client: TODO installcronjob."
+ local min
+
+ if is_cron_entry; then
+ echo "acme-client: cron entry previously exists, no changes."
+ return
+ fi
+
+ # randomize minutes in the range of 4-56, 53 is a prime number
+ min=$(( RANDOM % 53 + 4 ))
+
+ echo "$min 1 * * * /usr/sbin/acme-client --cron >/dev/null 2>&1" >> "$CRON_FILE"
+ echo 'root' >> "$CRON_UPDATE"
+
+ if is_cron_entry; then
+ echo "acme-client: Successfully added cron entry."
+ else
+ echo "acme-client: Failed adding cron entry."
+ fi
}
del_cron_entry()
{
- echo "acme-client: TODO uninstallcronjob."
+ if ! is_cron_entry; then
+ echo "acme-client: cron entry does not exist, no changes."
+ return
+ fi
+
+ sed -i -e '/\/usr\/sbin\/acme-client /d' "$CRON_FILE"
+ echo 'root' >> "$CRON_UPDATE"
+
+ if ! is_cron_entry; then
+ echo "acme-client: Successfully removed cron entry."
+ else
+ echo "acme-client: Failed removing cron entry."
+ fi
}
no_op_arg()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|