rename .cron to .cron-stage as mcron uses .cron
[james-home.git] / bin / loadcron
blob433040a178341be6289fd79422f055607195ddbd
1 #!/bin/sh
2 # Construct a crontab based on files in ~/.cron and load it into cron.
3 # The file ~/.cron/username/fqdn is appended to the common file in the same
4 # directory. Note that the common file may have "$HOME" in it, as in
5 # "PATH=$HOME/bin". cron is too dumb to deal with that, so the expansion is
6 # handled by this script.
7 set -e
9 which crontab >/dev/null 2>&1 || exit 0
11 WARNING="# Automatically generated by loadcron; edit ~/.cron/ files instead."
13 if [ ! -z "`crontab -l`" ] && ! crontab -l | grep -q "$WARNING"; then
14 if [ "$1" != "-f" ]; then
15 echo "loadcron: Current crontab was not generated by loadcron; not changing." >&2
16 echo "loadcron: Use loadcron -f to override"
17 exit 1
18 else
19 crontab -l > $HOME/tmp/oldcrontab
20 echo "loadcron: Old crontab is backed up to $HOME/tmp/oldcrontab"
24 dir=$HOME/.cron-stage/`whoami`
25 if [ -d "$dir" ]; then
26 hostfile="$dir/`hostname -f`"
27 # if [ ! -e "$hostfile" ]; then
28 # echo "loadcron: $hostfile does not exist, not loading" >&2
29 # fi
32 echo "$WARNING"
33 echo
34 if [ -e "$dir/common" ]; then
35 echo "# From $dir/common:"
36 sed "s!\$HOME!$HOME!" < "$dir/common"
37 echo
39 hostfile="$dir/`hostname -f`"
40 if [ -e "$hostfile" ]; then
41 echo "# From $hostfile:"
42 cat "$hostfile"
43 echo
45 # debian-edu crontab
46 debianedufile=/org/alioth.debian.org/chroot/home/groups/debian-edu/cronjobs/crontab.alioth
47 if [ "$(hostname)" = "haydn" ] && [ -e "$debianedufile" ]; then
48 echo "# From $debianedufile:"
49 cat "$debianedufile"
50 echo
52 ) | crontab -