1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
8 # Original Author: Aaron Walker <ka0ttic@gentoo.org>
9 # @BLURB: Some functions for cron
11 # Purpose: The main motivation for this eclass was to simplify
12 # the jungle known as src_install() in cron ebuilds. Using these
13 # functions also ensures that permissions are *always* reset,
14 # preventing the accidental installation of files with wrong perms.
16 # NOTE on defaults: the default settings in the below functions were
17 # chosen based on the most common setting among cron ebuilds.
19 # Please assign any bugs regarding this eclass to cron-bugs@gentoo.org.
21 inherit eutils flag-o-matic
23 EXPORT_FUNCTIONS pkg_postinst
27 DEPEND=">=sys-apps/sed-4.0.5"
29 RDEPEND=">=sys-process/cronbase-0.3.2"
30 for pn in vixie-cron bcron cronie dcron fcron; do
31 [[ ${pn} == "${PN}" ]] || RDEPEND="${RDEPEND} !sys-process/${pn}"
34 # @FUNCTION: docrondir
35 # @USAGE: [ dir ] [ perms ]
37 # Creates crontab directory
39 # Both arguments are optional. Everything after 'dir' is considered
40 # the permissions (same format as insopts).
42 # ex: docrondir /some/dir -m 0770 -o root -g cron
43 # docrondir /some/dir (uses default perms)
44 # docrondir -m0700 (uses default dir)
48 local perms="-m0750 -o root -g cron" dir="/var/spool/cron/crontabs"
55 [[ -n $1 ]] && perms="$@"
66 # reset perms to default
71 # @USAGE: [ exe ] [ perms ]
73 # Install cron executable
75 # Both arguments are optional.
77 # ex: docron -m 0700 -o root -g root ('exe' defaults to "cron")
78 # docron crond -m 0110
81 local cron="cron" perms="-m 0750 -o root -g wheel"
91 [[ -n $1 ]] && perms="$@"
98 doexe ${cron} || die "failed to install ${cron}"
100 # reset perms to default
104 # @FUNCTION: docrontab
105 # @USAGE: [ exe ] [ perms ]
107 # Install crontab executable
109 # Uses same semantics as docron.
112 local crontab="crontab" perms="-m 4750 -o root -g cron"
114 if [[ -n $1 ]] ; then
122 [[ -n $1 ]] && perms="$@"
129 doexe ${crontab} || die "failed to install ${crontab}"
131 # reset perms to default
134 # users expect /usr/bin/crontab to exist...
135 if [[ "${crontab##*/}" != "crontab" ]] ; then
136 dosym ${crontab##*/} /usr/bin/crontab || \
137 die "failed to create /usr/bin/crontab symlink"
141 # @FUNCTION: cron_pkg_postinst
143 # Outputs a message about system crontabs
144 # daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
145 cron_pkg_postinst() {
147 # daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
148 if [ "${CRON_SYSTEM_CRONTAB:-no}" != "yes" ] ; then
149 einfo "To activate /etc/cron.{hourly|daily|weekly|monthly} please run:"
150 einfo " crontab /etc/crontab"
152 einfo "!!! That will replace root's current crontab !!!"
156 einfo "You may wish to read the Gentoo Linux Cron Guide, which can be"
157 einfo "found online at:"
158 einfo " https://wiki.gentoo.org/wiki/Cron"