]> git.donarmstrong.com Git - bin.git/blob - loadcron
add reset usb bus command
[bin.git] / loadcron
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
8
9 WARNING="# Automatically generated by loadcron; edit ~/.cron/ files instead."
10
11 if [ ! -z "`crontab -l`" ] && ! crontab -l | grep -q "$WARNING"; then
12         if [ "$1" != "-f" ]; then
13                 echo "loadcron: Current crontab was not generated by loadcron; not changing." >&2
14                 echo "loadcron: Use loadcron -f to override"
15                 exit
16         else
17                 crontab -l > $HOME/tmp/oldcrontab
18                 echo "loadcron: Old crontab is backed up to $HOME/tmp/oldcrontab"
19         fi
20 fi
21
22 dir=$HOME/.cron/`whoami`
23 if [ -d "$dir" ]; then
24         (
25                 echo "$WARNING"
26                 echo
27                 if [ -e "$dir/common" ]; then
28                         echo "# From $dir/common:"
29                         sed "s!\$HOME!$HOME!" < "$dir/common"
30                         echo
31                 fi
32                 hostfile="$dir/`hostname -f`"
33                 if [ -e "$hostfile" ]; then
34                         echo "# From $hostfile:"
35                         cat "$hostfile"
36                         echo
37                 fi
38                 # debian-edu crontab
39                 debianedufile=/org/alioth.debian.org/chroot/home/groups/debian-edu/cronjobs/crontab.alioth
40                 if [ "$(hostname)" = "haydn" ] && [ -e "$debianedufile" ]; then
41                         echo "# From $debianedufile:"
42                         cat "$debianedufile"
43                         echo
44                 fi
45         ) | crontab -
46 fi