blob: ebf8ea1e824a29f7191814fc00ab2b545d486e36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: cron.eclass
# @MAINTAINER:
# maintainer-needed@gentoo.org
# @AUTHOR:
# Original Author: Aaron Walker <ka0ttic@gentoo.org>
# @SUPPORTED_EAPIS: 6 7 8
# @BLURB: Some functions for cron
# @DESCRIPTION:
# Purpose: The main motivation for this eclass was to simplify
# the jungle known as src_install() in cron ebuilds. Using these
# functions also ensures that permissions are *always* reset,
# preventing the accidental installation of files with wrong perms.
#
# NOTE on defaults: the default settings in the below functions were
# chosen based on the most common setting among cron ebuilds.
case ${EAPI} in
6|7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
if [[ -z ${_CRON_ECLASS} ]]; then
_CRON_ECLASS=1
inherit flag-o-matic
RDEPEND=">=sys-process/cronbase-0.3.2"
for pn in bcron cronie dcron fcron; do
[[ ${pn} == "${PN}" ]] || RDEPEND+=" !sys-process/${pn}"
done
unset pn
# @FUNCTION: docrondir
# @USAGE: [dir] [perms]
# @DESCRIPTION:
# Creates crontab directory
#
# Both arguments are optional. Everything after 'dir' is considered
# the permissions (same format as insopts).
#
# ex: docrondir /some/dir -m 0770 -o 0 -g cron
# docrondir /some/dir (uses default perms)
# docrondir -m0700 (uses default dir)
docrondir() {
# defaults
local perms="-m0750 -o 0 -g cron"
local dir="/var/spool/cron/crontabs"
if [[ -n $1 ]] ; then
case $1 in
*/*)
dir="$1"
shift
[[ -n $1 ]] && perms="$@"
;;
*)
perms="$@"
;;
esac
fi
(
diropts ${perms}
keepdir ${dir}
)
}
# @FUNCTION: docron
# @USAGE: [exe] [perms]
# @DESCRIPTION:
# Install cron executable
#
# Both arguments are optional.
#
# ex: docron -m 0700 -o 0 -g root ('exe' defaults to "cron")
# docron crond -m 0110
docron() {
local cron="cron"
local perms="-m 0750 -o 0 -g wheel"
if [[ -n $1 ]] ; then
case $1 in
-*)
perms="$@"
;;
*)
cron="$1"
shift
[[ -n $1 ]] && perms="$@"
;;
esac
fi
(
exeopts ${perms}
exeinto /usr/sbin
doexe ${cron}
)
}
# @FUNCTION: docrontab
# @USAGE: [exe] [perms]
# @DESCRIPTION:
# Install crontab executable
#
# Uses same semantics as docron.
docrontab() {
local crontab="crontab"
local perms="-m 4750 -o 0 -g cron"
if [[ -n $1 ]] ; then
case $1 in
-*)
perms="$@"
;;
*)
crontab=$1
shift
[[ -n $1 ]] && perms="$@"
;;
esac
fi
(
exeopts ${perms}
exeinto /usr/bin
doexe ${crontab}
)
# users expect /usr/bin/crontab to exist...
if [[ ${crontab##*/} != crontab ]] ; then
dosym ${crontab##*/} /usr/bin/crontab || \
die "failed to create /usr/bin/crontab symlink"
fi
}
# @FUNCTION: cron_pkg_postinst
# @DESCRIPTION:
# Outputs a message about system crontabs
# daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
cron_pkg_postinst() {
# daemons that have a true system crontab set CRON_SYSTEM_CRONTAB="yes"
if [[ ${CRON_SYSTEM_CRONTAB:-no} != yes ]] ; then
einfo "To activate /etc/cron.{hourly|daily|weekly|monthly} please run:"
einfo " crontab /etc/crontab"
einfo
einfo "!!! That will replace root's current crontab !!!"
einfo
fi
einfo "You may wish to read the Gentoo Linux Cron Guide, which can be"
einfo "found online at:"
einfo " https://wiki.gentoo.org/wiki/Cron"
}
fi
EXPORT_FUNCTIONS pkg_postinst
|