dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

commit 7686274ded18265fae60f24a30fdba930a45838a
parent 4724f36ee77fc04e6fd8e75dd4c32e508bfe07a5
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Tue, 12 Jun 2018 20:39:51 -0400

Add systemd timers support

Diffstat:
M.local/bin/my | 11++++++++++-
M.local/bin/my-init | 32+++++++++++++++++++++++++++++++-
2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/.local/bin/my b/.local/bin/my @@ -346,6 +346,7 @@ case $command in esac ;; cron) + [ $1 = systemd ] && mycron_systemd=1 case ":$PATH:" in *:"$HOME/.local/bin":*) ;; *) PATH="$HOME/.local/bin:$PATH" ;; @@ -354,7 +355,15 @@ case $command in logpath="$HOME/.local/var/log" for job in $cronpath/* do - [ -f $job -a -x $job ] && $job > $logpath/`basename $job` 2>&1 + if [ -x $job ] + then + if [ -n "$mycron_systemd" ] + then + $job + else + $job > $logpath/`basename $job` 2>&1 + fi + fi done ;; login_async) diff --git a/.local/bin/my-init b/.local/bin/my-init @@ -12,6 +12,7 @@ do done vim_bundle_path="$HOME/.vim/pack/bundle" +configdir=${XDG_CONFIG_HOME:-$HOME/.config} __has() { @@ -75,6 +76,11 @@ then rm -rf "$vim_bundle_path" rm "$HOME/.less" rm "$HOME/.gnupg/gpg-agent.conf" + if ps -U $LOGNAME | grep systemd > /dev/null 2>&1 + then + rm $configdir/systemd/user/my-cron.service + rm $configdir/systemd/user/my-cron.timer + fi fi if [ -f "$HOME/._.djmoch" ] @@ -102,7 +108,31 @@ then lesskey fi -if __has "crontab" && [ -n "$crontab_init" ] +if ps -U $LOGNAME | grep systemd > /dev/null 2>&1 \ + && [ -n "$crontab_init" ] +then + echo " Installing systemd timers" + cat >> $configdir/systemd/user/my-cron.service <<-EOF +[Unit] +Description=djmoch "my cron" service + +[Service] +Type=simple +ExecStart=$HOME/.local/bin/my cron systemd +EOF + cat >> $configdir/systemd/user/my-cron.timer <<-EOF +[Unit] +Description=djmoch "my cron" timer + +[Timer] +OnBootSec=1min +OnUnitActiveSec=15min + +[Install] +WantedBy=timers.target +EOF + systemctl --user enable my-cron.timer +elif __has "crontab" && [ -n "$crontab_init" ] then echo " Installing crontab" crontab -l > /tmp/crontab.$$.orig