*/*: Fix obsolete copyrights
[gentoo.git] / eclass / cron.eclass
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: cron.eclass
5 # @MAINTAINER:
6 # maintainer-needed@gentoo.org
7 # @AUTHOR:
8 # Original Author: Aaron Walker <ka0ttic@gentoo.org>
9 # @BLURB: Some functions for cron
10 # @DESCRIPTION:
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.
15 #
16 # NOTE on defaults: the default settings in the below functions were
17 # chosen based on the most common setting among cron ebuilds.
18 #
19 # Please assign any bugs regarding this eclass to cron-bugs@gentoo.org.
20
21 inherit eutils flag-o-matic
22
23 EXPORT_FUNCTIONS pkg_postinst
24
25 SLOT="0"
26
27 DEPEND=">=sys-apps/sed-4.0.5"
28
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}"
32 done
33
34 # @FUNCTION: docrondir
35 # @USAGE: [ dir ] [ perms ]
36 # @DESCRIPTION:
37 # Creates crontab directory
38 #
39 #       Both arguments are optional.  Everything after 'dir' is considered
40 #   the permissions (same format as insopts).
41 #
42 # ex: docrondir /some/dir -m 0770 -o root -g cron
43 #     docrondir /some/dir (uses default perms)
44 #     docrondir -m0700 (uses default dir)
45
46 docrondir() {
47         # defaults
48         local perms="-m0750 -o root -g cron" dir="/var/spool/cron/crontabs"
49
50         if [[ -n $1 ]] ; then
51                 case "$1" in
52                         */*)
53                                 dir=$1
54                                 shift
55                                 [[ -n $1 ]] && perms="$@"
56                                 ;;
57                         *)
58                                 perms="$@"
59                                 ;;
60                 esac
61         fi
62
63         diropts ${perms}
64         keepdir ${dir}
65
66         # reset perms to default
67         diropts -m0755
68 }
69
70 # @FUNCTION: docron
71 # @USAGE: [ exe ] [ perms ]
72 # @DESCRIPTION:
73 # Install cron executable
74 #
75 #    Both arguments are optional.
76 #
77 # ex: docron -m 0700 -o root -g root ('exe' defaults to "cron")
78 #     docron crond -m 0110
79
80 docron() {
81         local cron="cron" perms="-m 0750 -o root -g wheel"
82
83         if [[ -n $1 ]] ; then
84                 case "$1" in
85                         -*)
86                                 perms="$@"
87                                 ;;
88                          *)
89                                 cron=$1
90                                 shift
91                                 [[ -n $1 ]] && perms="$@"
92                                 ;;
93                 esac
94         fi
95
96         exeopts ${perms}
97         exeinto /usr/sbin
98         doexe ${cron} || die "failed to install ${cron}"
99
100         # reset perms to default
101         exeopts -m0755
102 }
103
104 # @FUNCTION: docrontab
105 # @USAGE: [ exe ] [ perms ]
106 # @DESCRIPTION:
107 # Install crontab executable
108 #
109 #   Uses same semantics as docron.
110
111 docrontab() {
112         local crontab="crontab" perms="-m 4750 -o root -g cron"
113
114         if [[ -n $1 ]] ; then
115                 case "$1" in
116                         -*)
117                                 perms="$@"
118                                 ;;
119                          *)
120                                 crontab=$1
121                                 shift
122                                 [[ -n $1 ]] && perms="$@"
123                                 ;;
124                 esac
125         fi
126
127         exeopts ${perms}
128         exeinto /usr/bin
129         doexe ${crontab} || die "failed to install ${crontab}"
130
131         # reset perms to default
132         exeopts -m0755
133
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"
138         fi
139 }
140
141 # @FUNCTION: cron_pkg_postinst
142 # @DESCRIPTION:
143 # Outputs a message about system crontabs
144 # daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
145 cron_pkg_postinst() {
146         echo
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"
151                 einfo
152                 einfo "!!! That will replace root's current crontab !!!"
153                 einfo
154         fi
155
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"
159         echo
160 }