diff options
-rwxr-xr-x | bin/with-email | 14 | ||||
-rw-r--r-- | etc/guix/home.scm | 50 | ||||
-rwxr-xr-x | etc/sh/check.sh | 9 | ||||
-rwxr-xr-x | etc/sh/cronjob.sh | 70 | ||||
-rw-r--r-- | etc/sh/rc | 14 |
5 files changed, 126 insertions, 31 deletions
diff --git a/bin/with-email b/bin/with-email index dc2a022..7df101a 100755 --- a/bin/with-email +++ b/bin/with-email @@ -69,15 +69,7 @@ while getopts 's:h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - -assert_arg "${1:-}" 'COMMAND...' +eval "$(assert-arg "${1:-}" 'COMMAND...')" now() { date '+%Y-%m-%dT%H:%M:%S%Z' @@ -90,10 +82,10 @@ OUT="$(mkstemp)" printf '\n' STATUS=0 - "$@" 2>&1 || STATUS=$? + "$@" || STATUS=$? printf '\n' printf '\nFinished at: %s\n' "$(now)" -} 2>&1 1>"$OUT" +} 1>"$OUT" 2>&1 email -s "(exit status: $STATUS) - $SUBJECT" eu@euandre.org < "$OUT" diff --git a/etc/guix/home.scm b/etc/guix/home.scm index 94521d4..b43e8ec 100644 --- a/etc/guix/home.scm +++ b/etc/guix/home.scm @@ -1,4 +1,5 @@ (use-modules + ((ice-9 textual-ports) #:prefix textual-ports:) ((xyz euandreh heredoc) #:prefix heredoc:) (gnu home) (gnu home services) @@ -16,6 +17,7 @@ (gnu packages version-control) (gnu packages video) (gnu services) + (guix build-system trivial) (guix gexp) (guix modules) (guix packages) @@ -154,18 +156,41 @@ config-files))) +(define (slurp name) + (string-trim-both + (call-with-input-file + name + textual-ports:get-string-all))) + +(define (script name content) + (package + (name name) + (version "latest") + (source #f) + (build-system trivial-build-system) + (arguments + `(#:modules ((guix build utils)) + #:builder + (begin + (use-modules (guix build utils)) + (let* ((bin (string-append %output "/bin")) + (prog (string-append bin "/" ,name))) + (mkdir-p bin) + (call-with-output-file prog + (lambda (port) + (format port "~a" ,content))) + (chmod prog #o755))))) + (home-page "") + (synopsis "") + (description "") + (license #f))) + (define cronjobs - '() - #; (list - ;; FIXME - #~(job "* * * * *" "echo foi > ~/foi") - #~(job "* * * * *" "backup -h 2>&1 > ~/bk") - #~(job "* * * * *" "which backup -h 2>&1 > ~/which-bk") - #~(job "* * * * *" "echo $PATH 2>&1 > ~/path") - #~(job "* * * * *" "echo 123") - #~(job "* * * * *" "echo 123 > k") - #~(job "* * * * *" "date > ~/job"))) + #~(job "0 * * * *" "cronjob msmtp-queue -r") + #~(job "5 * * * *" "cronjob m") + #~(job "30 1 * * *" "cronjob backup cron"))) + (home-environment (packages @@ -362,7 +387,6 @@ ;; remembering ;; guile-heredoc ;; td - ;; walk guile-heredoc-latest gzip xz @@ -415,7 +439,9 @@ myrepos-with-options texinfo-with-options mpv-with-options - openssh-with-options))) + openssh-with-options + (script "cronjob" (slurp (string-append (getenv "XDG_CONFIG_HOME") + "/sh/cronjob.sh")))))) (services (list (simple-service 'my-shell-profile home-shell-profile-service-type diff --git a/etc/sh/check.sh b/etc/sh/check.sh index 102fcd0..07e9e66 100755 --- a/etc/sh/check.sh +++ b/etc/sh/check.sh @@ -51,10 +51,11 @@ cd -- "$(dirname -- "$0")" cd -- "$(git rev-parse --show-toplevel)" shellcheck -xe 1090,1091 \ - "$XDG_CONFIG_HOME"/sh/rc \ - "$XDG_CONFIG_HOME"/sh/vcs-ps1.sh \ - "$XDG_CONFIG_HOME"/sh/check.sh \ - "$XDG_CONFIG_HOME"/sh/privrc.sh \ + "$XDG_CONFIG_HOME"/sh/rc \ + "$XDG_CONFIG_HOME"/sh/vcs-ps1.sh \ + "$XDG_CONFIG_HOME"/sh/check.sh \ + "$XDG_CONFIG_HOME"/sh/privrc.sh \ + "$XDG_CONFIG_HOME"/sh/cronjob.sh \ "$XDG_CONFIG_HOME"/notmuch/default/hooks/post-new if git grep FIXME -- ":(exclude)$XDG_CONFIG_HOME/bash/check.sh"; then diff --git a/etc/sh/cronjob.sh b/etc/sh/cronjob.sh new file mode 100755 index 0000000..950430f --- /dev/null +++ b/etc/sh/cronjob.sh @@ -0,0 +1,70 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + cronjob COMMAND... + cronjob -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + COMMAND the command to be executed + + + Execute the given command, and send the output to email, with + special treatment to the status code. + + It loads the appropriate files, so that the actual cron + declaration is smaller. + + + Examples: + + Run a backup: + + $ cronjob backup cron + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + + +. ~/.usr/etc/sh/rc +CMD="$@" +with-email -s "$CMD" -- "$@" 1>>"$XDG_LOG_HOME"/euandreh/mcron.log 2>&1 @@ -38,7 +38,7 @@ idempotent_path_add() { esac } export A="$HOME${A:+:}${A:-}" -idempotent_path_add B "$HOME" +# idempotent_path_add B "$HOME" export XDG_DATA_DIRS="$XDG_DATA_HOME/flatpak/exports/share:/var/lib/flatpak/exports/share${XDG_DATA_DIRS:+:}${XDG_DATA_DIRS:-}" # idempotent_path_add XDG_DATA_DIRS "$XDG_DATA_HOME/flatpak/exports/share" @@ -241,7 +241,7 @@ fi # SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) -GPG_TTY=$(tty) +GPG_TTY=$(tty ||:) export GPG_TTY SSH_AUTH_SOCK gpgconf --launch gpg-agent gpg --export-ssh-key eu@euandre.org > "$XDG_CONFIG_HOME"/ssh/id_rsa.pub @@ -253,11 +253,17 @@ $HOME/dev/libre/package-repository/EuAndreh.key $HOME/dev/published/euandre.org/public.asc " for f in $PUB_GPG_FILES; do - gpg --armour --export eu@euandre.org > $f + gpg --armour --export eu@euandre.org > "$f" done -stty -ixon # Disable C-s/C-q mode +case $- in + *i*) + stty -ixon # Disable C-s/C-q mode + ;; + *) + ;; +esac F="$XDG_CONFIG_HOME"/sh/privrc.sh if [ -e "$F" ]; then |