logo

overlay

My (experimental) gentoo overlay

cron.eclass (3590B)


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