1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 # Original Author: Aaron Walker <ka0ttic@gentoo.org>
10 # @BLURB: Some functions for cron
12 # Purpose: The main motivation for this eclass was to simplify
13 # the jungle known as src_install() in cron ebuilds. Using these
14 # functions also ensures that permissions are *always* reset,
15 # preventing the accidental installation of files with wrong perms.
17 # NOTE on defaults: the default settings in the below functions were
18 # chosen based on the most common setting among cron ebuilds.
20 # Please assign any bugs regarding this eclass to cron-bugs@gentoo.org.
22 inherit eutils flag-o-matic
24 EXPORT_FUNCTIONS pkg_postinst
28 DEPEND=">=sys-apps/sed-4.0.5"
30 RDEPEND=">=sys-process/cronbase-0.3.2"
31 for pn in vixie-cron bcron cronie dcron fcron; do
32 [[ ${pn} == "${PN}" ]] || RDEPEND="${RDEPEND} !sys-process/${pn}"
35 # @FUNCTION: docrondir
36 # @USAGE: [ dir ] [ perms ]
38 # Creates crontab directory
40 # Both arguments are optional. Everything after 'dir' is considered
41 # the permissions (same format as insopts).
43 # ex: docrondir /some/dir -m 0770 -o root -g cron
44 # docrondir /some/dir (uses default perms)
45 # docrondir -m0700 (uses default dir)
49 local perms="-m0750 -o root -g cron" dir="/var/spool/cron/crontabs"
56 [[ -n $1 ]] && perms="$@"
67 # reset perms to default
72 # @USAGE: [ exe ] [ perms ]
74 # Install cron executable
76 # Both arguments are optional.
78 # ex: docron -m 0700 -o root -g root ('exe' defaults to "cron")
79 # docron crond -m 0110
82 local cron="cron" perms="-m 0750 -o root -g wheel"
92 [[ -n $1 ]] && perms="$@"
99 doexe ${cron} || die "failed to install ${cron}"
101 # reset perms to default
105 # @FUNCTION: docrontab
106 # @USAGE: [ exe ] [ perms ]
108 # Install crontab executable
110 # Uses same semantics as docron.
113 local crontab="crontab" perms="-m 4750 -o root -g cron"
115 if [[ -n $1 ]] ; then
123 [[ -n $1 ]] && perms="$@"
130 doexe ${crontab} || die "failed to install ${crontab}"
132 # reset perms to default
135 # users expect /usr/bin/crontab to exist...
136 if [[ "${crontab##*/}" != "crontab" ]] ; then
137 dosym ${crontab##*/} /usr/bin/crontab || \
138 die "failed to create /usr/bin/crontab symlink"
142 # @FUNCTION: cron_pkg_postinst
144 # Outputs a message about system crontabs
145 # daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
146 cron_pkg_postinst() {
148 # daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
149 if [ "${CRON_SYSTEM_CRONTAB:-no}" != "yes" ] ; then
150 einfo "To activate /etc/cron.{hourly|daily|weekly|monthly} please run:"
151 einfo " crontab /etc/crontab"
153 einfo "!!! That will replace root's current crontab !!!"
157 einfo "You may wish to read the Gentoo Linux Cron Guide, which can be"
158 einfo "found online at:"
159 einfo " https://www.gentoo.org/doc/en/cron-guide.xml"