about summary refs log tree commit diff
path: root/bin/redo
blob: 0c76a18adcacdbc29523b4a53f56ffb3c5b7bc12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh -eu
# redo – bourne shell implementation of DJB redo
# Copyright © 2014-2021  Nils Dagsson Moskopp (erlehmann)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# Dieses Programm hat das Ziel, die Medienkompetenz der Leser zu
# steigern. Gelegentlich packe ich sogar einen handfesten Buffer
# Overflow oder eine Format String Vulnerability zwischen die anderen
# Codezeilen und schreibe das auch nicht dran.

: \
 "${REDO_JOBS_MAX:=1}" \
 "${REDO_MKDIR:=$(command -v mkdir)}" \
 "${REDO_RM:=$(command -v rm) -f}" \
 "${REDO_RMDIR:=$(command -v rmdir)}" \
 "${REDO_TMP_DIR:=$(mktemp -d /tmp/redo.XXXXXXX)}" \

export \
 REDO_JOBS_MAX \
 REDO_MKDIR \
 REDO_RM \
 REDO_RMDIR \
 REDO_TMP_DIR \

while [ $# != 0 ]; do
 case "${1}" in
  '-d'|'--debug')
   export REDO_DEBUG='1'
  ;;
  '--debug-jobs')
   export REDO_DEBUG_JOBS='1'
  ;;
  '--debug-locks')
   export REDO_DEBUG_LOCKS='1'
  ;;
  '-h'|'--help')
   printf >&2 \
"Usage: redo [OPTIONS] [TARGETS...]

  -d, --debug          print dependency checks as they happen
      --debug-jobs     print messages about job management
      --debug-locks    print messages about file locking
  -h, --help           print usage instructions and exit
  -j [n], --jobs [n]   execute at most [n] dofiles in parallel
      --version        print version information and exit
  -x, --xtrace         print commands as they are executed (variables expanded)

Report bugs to <nils+redo@dieweltistgarnichtso.net>.
"
   exit 0
  ;;
  '-j'|'--jobs')
   shift; REDO_JOBS_MAX=${1}
  ;;
  '--version')
   printf >&2 \
"redo 4.0.4
Copyright © 2014-2021 Nils Dagsson Moskopp (erlehmann)

License AGPLv3+: GNU Affero GPL version 3 or later <http://www.gnu.org/licenses/agpl-3.0.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
"
   exit 0
  ;;
  '-x'|'--xtrace')
   export REDO_XTRACE='1'
  ;;
  *)
   REDO_HAS_TARGETS='1'
   export REDO_TARGET=''
   # If this is build directory, create .redo database directory.
   case "${REDO_BASE:-}" in
    '')
     export REDO_DEPTH=""
     export REDO_PID="${PPID}"
     export REDO_BASE="${PWD}"
     export REDO_DIR="$REDO_BASE/.redo"
     [ -d "$REDO_DIR" ] || LANG=C "${REDO_MKDIR}" -p "$REDO_DIR"
   esac
   break
  ;;
 esac
 shift
done

[ "${REDO_HAS_TARGETS:-}" = "1" ] || exec redo all

case "${REDO_JOBS_PIPE:-}" in
 '')
  export REDO_JOBS_PIPE="${REDO_TMP_DIR}"/jobs_pipe
  mkfifo "${REDO_JOBS_PIPE}"
  exec 9<> "${REDO_JOBS_PIPE}"
  >&9 seq $(( REDO_JOBS_MAX - 1 )) &
 ;;
esac

set +e
redo-ifchange "$@"
EXITCODE=${?}
set -e

wait

case ${#REDO_DEPTH} in
 0)
  LANG=C ${REDO_RM} "${REDO_JOBS_PIPE}"
  LANG=C ${REDO_RMDIR} "${REDO_TMP_DIR}"
 ;;
esac

exit "${EXITCODE}"