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