commit - af1994595f5f9d7e81b9ad0052dbab382c9e5b56
commit + f6bdfddcff9b72edb6803ffd61ad98a256c43787
blob - 2b05f5c2d23d4b38a13e5fd4fc6dc513720ccb11
blob + d4af1cf9a03eebca09eff59415b38e7246dc7f7d
--- Makefile
+++ Makefile
SHELLS=ksh93 ksh yash sh
UTILITY_VERSION=0.0.1
UTILITY=$(PWD)/r7
+SSH_ID=$(HOME)/.ssh/managed/inda.re/id_ed25519_cobalt
+SSH_TEST_NODES=tools0
.DEFAULT: all
all: tests
$R -s group ;} | wc -c | grep -q 0
@echo _________________________________________________________
-SSH_ID=$(HOME)/.ssh/managed/inda.re/id_ed25519_cobalt
-SSH_TEST_NODES=tools0
workdir2-init:
@echo _________________________________________________________
rm -fr testdir/workdir2
cd testdir/workdir2 && . $(UTILITY) && \
echo 'prefix grouplib' > site-config && \
echo "group grouplib '.*'" >> site-config && \
- run_config && output_dump && output_status && \
- R7_DEBUG=yes summary && \
+ $R run-config && $R output-dump && $R info && \
for node in $(SSH_TEST_NODES); do \
ssh "$$node" ls -la /tmp/item\* | grep item; \
ssh "$$node" ls -la /tmp/r7/my-empty-file | grep empty | grep -e '-rw-r-----' ; \
ssh "$$node" ls -la /tmp/newdir/newdir2/null | grep -e '-rw-r-----' ; \
- done && output tools0 grouplib
+ done && $R output tools0 grouplib
@echo _________________________________________________________
workdir2-goodby: workdir2-grouplib
blob - 25ae5442e8dc86140e1ba2156d58544c58769c96
blob + 50c3ace4e16ec23dfeb68ae2e91d7e9e9e53cd1a
--- README.md
+++ README.md
_Supported shells are ksh93, oksh and yash. Supported platforms are OpenBSD, FreeBSD, NetBSD and GNU/Linux. Busybox support is planned._
+_Optional dependencies are openrsync, rsync, column, graphviz and pandoc_
## Tutorial
crontab -u _myscript - <<-/
MAILTO=$mail_admins
*/5 * * * * myscript
- /
+/
}
```
### Options
-Below is a description of the command line options available:
-
- **-h**
Show usage and exit
### Commands
-Below is a description of the available commands:
+| Name | Description |
+| ---- | ----------- |
+| **run-config** | Run the site configuration |
+| **group** | Deploy specified group to hosts |
+| **output-dump** | Dump the run directory to the output directory |
+| **output** | Consult the output |
+| **summary** | Produce a summary of errors and changes |
+| **digraph-host** | Produce a dot digraph for hosts |
+| **digraph-ssh** | Produce a dot digraph of SSH ID's, users and nodes relations |
+| **import** | Import TARGET host in the current nodes directory |
+| **info** | Default command showing active nodes and summary |
+| **init** | Initialize a new work directory |
-- **run-config**
- Run the site configuration
+### Environment
-- **group**
- Deploy specified group to hosts
+| Name | Default value | Description |
+| ---- | ------------- | ------------|
+| R7_DEBUG | no | Enable debug mode |
+| R7_DRYRUN | no | Enable dry-run mode |
+| R7_GROUP_ALLPREFIX | no | Group selects all available prefix |
+| R7_GROUP_SUMMARY | no | Enable output-dump and summary after group execution |
+| R7_GROUP_EXITONERROR | no | Enable exit on error function |
+| R7_PARALLEL | no | Enable group nodes parallel execution |
+| R7_PREFIX | install state doc | Set the r7 group execution prefix |
+| R7_SHOWOUTPUT | no | Show interactive output |
+| R7_WORKDIR | PWD | Set the r7 repository path |
+| R7_SITE_CONFIG | R7_WORKDIR/site-config | Set the r7 `site-config` path |
+| R7_OUTPUTDIR | R7_WORKDIR/_output | Set the r7 output directory path |
+| SSH_CONFIG_DIR | R7_WORKDIR/.ssh | Set the SSH configuration directory path |
+| SSH_CONFIG_FILE | R7_WORKDIR/.ssh/config | Set the SSH configuration file path |
+| SSH_CONTROL_DIR | SSH_CONFIG_DIR/control | Set the SSH control dir path |
+| SSH_IDENTITY_FILE | R7_WORKDIR/.ssh/id_ed25519_r7 | Set the SSH identity file |
+| SSH_KNOWN_HOSTS | R7_WORKDIR/.ssh/known_hosts | Set the SSH known hosts file |
+| SSH_CONNECT_TIMEOUT | 3 | Set the SSH connect timeout |
-- **output-dump**
- Dump the run directory to the output directory
-
-- **output**
- Consult the output
-
-- **summary**
- Produce a summary of errors and changes
-
-- **digraph-host**
- Produce a dot digraph for hosts
-
-- **digraph-ssh**
- Produce a dot digraph of SSH ID's, users and nodes relations
-
-- **import**
- Import TARGET host in the current nodes directory
-
-- **info**
- Default command showing active nodes and summary
-
-- **init**
- Initialize a new work directory
-
## Group functions
+
Those functions are accessible during the execution of the group file's functions.
1. [trace](#trace)
### trace
***Description:***
-Append a trace containing the current node name and `trace_id`.
+Append a trace containing the current node name and `trace_id`
**Usage:**
```sh
### node
***Description:***
-Returns true if the argument is an existing file or directory inside `/tmp/r7/$(nodename)`. Else, returns 31
+Returns true if the argument is an existing file or directory inside `/tmp/r7/$(nodename)`, else, returns 31
***Usage:***
```sh
***Description:***
Change directory to `/tmp/r7` and install files if changed and sets mode and
-owner. Returns true if the file changed, otherwise returns 30.
+owner, returns true if the file changed, otherwise returns 30
***Usage:***
```sh
### run-config
***Description:***
-Sources R7_SITE_CONFIG
+Executes `R7_SITE_CONFIG` in the loaded environment
***Usage:***
```sh
### members
***Description:***
-Returns a list of active nodes matching a list of REGEXES
+Returns a list of active nodes matching a list of grep REGEXES
***Usage:***
```sh
### html
***Description:***
-Retunrs a report page with the content of `README.md` in HTML format.
+Retunrs a report page with the content of `README.md` in HTML format
***Usage:***
```sh
blob - 6365870c8c5a28a01dc8d1c9d96c2c816e7d78f4
blob + 0416c70f82e6f6858332b02be354c29caf543764
--- r7
+++ r7
info() {
if test "$R7_ENV_READY" = yes; then
cd "$R7_WORKDIR" || return 2
- if test -n "$(trace_id_last)"; then
- trace_id_last | sed 's/^/- /'
- nodes_active | sed 's/^/ - /'
+ _trace_id_last=$(trace_id_last)
+ if test -n "$_trace_id_last"; then
+ printf -- "- (%s) - in %s the %s\n" \
+ "$_trace_id_last" "$(basename "$R7_WORKDIR")" "$(_epoch "$_trace_id_last")"
+ nodes_active | sed 's/^/ - (active) /'
echo
fi
output_dump
trace_id=$(_trace_id_new)
# shellcheck disable=SC1091
_debug LOADING "$R7_SITE_CONFIG"
- test -f "$R7_SITE_CONFIG" && . "$R7_SITE_CONFIG"
+ sh -n "$R7_SITE_CONFIG" && . "$R7_SITE_CONFIG"
}
# Inherits $target from group()
case $arg in
o) owner=$OPTARG ;;
m) mode=$OPTARG ;;
- *) ;;
+ *) : ;;
esac
done
shift $((OPTIND - 1))
;;
esac
)
+ groupinstalldir() ( cd "$(groupdir)" && r7_installdir "$@" ; )
+ nodeinstalldir() ( cd "$(nodedir)" && r7_installdir "$@" ; )
r7_installdir() (
- while getopts "o:m:O:M:"; do
+ while getopts "o:m:O:M:" arg; do
case $arg in
o) fileowner=$OPTARG ;;
m) filenode=$OPTARG ;;
O) dirowner=$OPTARG ;;
M) dirmode=$OPTARG ;;
+ *) : ;;
esac
- source=$1
- target=$2
- source_basename=${source##*/}
- source_dirname=${source%%/*}
- target_basename=${target##*/}
- target_dirname=${target%%/*}
- test -d "$source" || {
- error "$source" directory not found
- return 2
- }
- test -d "$target" || {
- error "$target" directory not found
- return 2
- }
- cd "$source" || return 2
- for dir in $(find ./* -type d); do
- newdir=${dir#./}
- trace "$newdir"
- (
- cd "$target" || return 2
- before=$(_getperm "$newdir")
- mkdir -p "$newdir" || error unable to create "$newdir"
- test -n "$dirowner" && chown "$dirowner" "$newdir"
- test -n "$dirmode" && chmod "$dirmode" "$newdir"
- after=$(_getperm "$newdir")
- test "$before" != "$after" &&
- trace PERMISSIONS CHANGE "$before" TO "$after" ON "$newdir"
- )
- done
- for file in $(find ./* -type f); do
- newfile=${file#./}
- trace "$newfile"
- (
- r7_install -o "$fileowner" -m "$filemode" "$file" "$target"
- )
- done
done
+ shift $((OPTIND - 1))
+ source=$1
+ target=$2
+ source_basename=${source##*/}
+ source_dirname=$PWD/${source%%/*}
+ target_basename=${target##*/}
+ test -d "$source" || {
+ error "$source" directory not found
+ return 2
+ }
+ for dir in $(find "$source" -type d); do
+ newdir=${dir#./}
+ (
+ cd "$target" || return 2
+ mkdir -p "$newdir" || { error unable to create "$newdir"; return 2 ; }
+ owner=$dirowner mode=$dirmode _setperm "$1"
+ )
+ done
+ for file in $(find "$source" -type f); do
+ newfile=${file#./}
+ r7_install -o "$fileowner" -m "$filemode" "$file" "$target/$newfile"
+ done
)
set -e
cd /tmp/r7 && umask 027
}
)
+_epoch() (
+ case $(uname) in
+ OpenBSD | FreeBSD | NetBSD | Darwin)
+ date -r "$1"
+ ;;
+ Linux)
+ date -d "@$1"
+ ;;
+ *)
+ perl -e "print scalar localtime($1)"
+ ;;
+ esac
+
+)
+
alias output-latest=output_latest
alias outlatest=output_latest
output_latest() (
done
)
test -z "$latest" && return 0
- case $(uname) in
- OpenBSD | FreeBSD | NetBSD | Darwin)
- latest_date=$(date -r "$latest")
- ;;
- Linux)
- latest_date=$(date -d "@$latest")
- ;;
- *)
- latest_date=$(perl -e "print scalar localtime($latest)")
- ;;
- esac
+ latest_date=$(_epoch "$latest")
if test -n "$latest_date"; then
find "$R7_RUNDIR" -type f -name "$latest.*"
fi
find ./* -type f -name 'duration'
)
+_column() {
+ column -t 2>/dev/null ||
+ cat -
+}
+
alias output-status=output_status
alias outstat=output_status
output_status() (
cd "$R7_OUTPUTDIR" || return 2
+ echo HOST GROUP FUNCTION STATUS
_status_files | {
- echo HOST GROUP FUNCTION STATUS
while read -r status; do
echo "$status" | while IFS=/ read -r _ host groupname funcname _; do
echo "$host" "$groupname" "$funcname" "$(cat "$status")"
done
done
- } | column -t
+ } | _column
)
alias output-duration=output_duration
alias outdur=output_duration
output_duration() (
cd "$R7_OUTPUTDIR" || return 2
+ echo HOST GROUP DURATION
_duration_files | {
- echo HOST GROUP DURATION
while read -r duration; do
echo "$duration" | while IFS=/ read -r _ host groupname _; do
echo "$host" "$groupname" "$(cat "$duration")"
done
done
- } | column -t
+ } | _column
)
alias out=output
alias outerr=output_errors
output_errors() (
trace_id=$(trace_id_last)
- output_status | tail -n +2 | while read -r host groupname funcname status; do
+ output_status | while read -r host groupname funcname status; do
case $status in
- 0 | 30 | 31) continue ;;
+ STATUS | 0 | 30 | 31) continue ;;
esac
echo "- (error $status) -" "in" "$host" "$groupname" "$funcname" "($trace_id)"
if test -f "$R7_OUTPUTDIR/$host/$groupname/$funcname/output"; then
</nav>
<main>
<section id="Documentation">
- $(lowdown README.md)
+ $(md README.md)
</section>
</main>
<footer>
blob - 852c14c127a16cbb329c2e9853e36e0631565f30
blob + 7187196b34bc9be19838fbef4c01932109996c4c
--- testdir/grouplib
+++ testdir/grouplib
groupinstall testfile2 /tmp
}
-grouplib_isntall_8() {
+grouplib_install_8() {
groupinstall subdir/subitem /tmp
groupinstall subdir/subitem2 /tmp/subitem
}
touch testfile3
}
+grouplib_installdir1() {
+ cd "$(groupdir)" &&
+ mkdir -p dirconf/subdir1 &&
+ mkdir -p dirconf/subdir2 &&
+ echo xyz >dirconf/subdir1/file &&
+ echo abc >dirconf/subdir2/file &&
+ find "$PWD"
+ cd /tmp/r7 || return 1
+ groupinstalldir dirconf /tmp
+}
+
grouplib_goodby() {
error goodby
}
blob - /dev/null
blob + 0940329b83770db36b9481fe82744b7bfb2c76a6 (mode 644)
--- /dev/null
+++ r7doc.html
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
+$for(author-meta)$
+ <meta name="author" content="$author-meta$" />
+$endfor$
+$if(date-meta)$
+ <meta name="dcterms.date" content="$date-meta$" />
+$endif$
+$if(keywords)$
+ <meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
+$endif$
+$if(description-meta)$
+ <meta name="description" content="$description-meta$" />
+$endif$
+ <title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
+ <style>
+ html {
+ color: #1a1a1a;
+ background-color: #fdfdfd;
+ }
+ body {
+ margin: 0 auto;
+ max-width: 42em;
+ padding-left: 50px;
+ padding-right: 50px;
+ padding-top: 50px;
+ padding-bottom: 50px;
+ hyphens: auto;
+ overflow-wrap: break-word;
+ text-rendering: optimizeLegibility;
+ font-kerning: normal;
+ }
+ @media (max-width: 600px) {
+ body {
+ font-size: 0.9em;
+ padding: 12px;
+ }
+ h1 {
+ font-size: 1.8em;
+ }
+ }
+ @media print {
+ html {
+ background-color: white;
+ }
+ body {
+ background-color: transparent;
+ color: black;
+ font-size: 12pt;
+ }
+ p, h2, h3 {
+ orphans: 3;
+ widows: 3;
+ }
+ h2, h3, h4 {
+ page-break-after: avoid;
+ }
+ }
+ p {
+ margin: 1em 0;
+ }
+ a {
+ color: #1a1a1a;
+ }
+ a:visited {
+ color: #1a1a1a;
+ }
+ img {
+ max-width: 100%;
+ }
+ svg {
+ height: auto;
+ max-width: 100%;
+ }
+ h1, h2, h3, h4, h5, h6 {
+ margin-top: 1.4em;
+ }
+ h5, h6 {
+ font-size: 1em;
+ font-style: italic;
+ }
+ h6 {
+ font-weight: normal;
+ }
+ ol, ul {
+ padding-left: 1.7em;
+ margin-top: 1em;
+ }
+ li > ol, li > ul {
+ margin-top: 0;
+ }
+ blockquote {
+ margin: 1em 0 1em 1.7em;
+ padding-left: 1em;
+ border-left: 2px solid #e6e6e6;
+ color: #606060;
+ }
+ code {
+ font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
+ font-size: 85%;
+ margin: 0;
+ hyphens: manual;
+ }
+ pre {
+ margin: 1em 0;
+ overflow: auto;
+ }
+ pre code {
+ padding: 0;
+ overflow: visible;
+ overflow-wrap: normal;
+ }
+ .sourceCode {
+ background-color: transparent;
+ overflow: visible;
+ }
+ hr {
+ background-color: #1a1a1a;
+ border: none;
+ height: 1px;
+ margin: 1em 0;
+ }
+ table {
+ margin: 1em 0;
+ border-collapse: collapse;
+ width: 100%;
+ overflow-x: auto;
+ display: block;
+ font-variant-numeric: lining-nums tabular-nums;
+ }
+ table caption {
+ margin-bottom: 0.75em;
+ }
+ tbody {
+ margin-top: 0.5em;
+ border-top: 1px solid #1a1a1a;
+ border-bottom: 1px solid #1a1a1a;
+ }
+ th {
+ border-top: 1px solid #1a1a1a;
+ padding: 0.25em 0.5em 0.25em 0.5em;
+ }
+ td {
+ padding: 0.125em 0.5em 0.25em 0.5em;
+ }
+ header {
+ margin-bottom: 4em;
+ text-align: center;
+ }
+ #TOC li {
+ list-style: none;
+ }
+ #TOC ul {
+ padding-left: 1.3em;
+ }
+ #TOC > ul {
+ padding-left: 0;
+ }
+ #TOC a:not(:hover) {
+ text-decoration: none;
+ }
+ code{white-space: pre-wrap;}
+ span.smallcaps{font-variant: small-caps;}
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
+ div.column{flex: auto; overflow-x: auto;}
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
+ /* The extra [class] is a hack that increases specificity enough to
+ override a similar rule in reveal.js */
+ ul.task-list[class]{list-style: none;}
+ ul.task-list li input[type="checkbox"] {
+ font-size: inherit;
+ width: 0.8em;
+ margin: 0 0.8em 0.2em -1.6em;
+ vertical-align: middle;
+ }
+ .display.math{display: block; text-align: center; margin: 0.5rem auto;}
+ /* CSS for syntax highlighting */
+ html { -webkit-text-size-adjust: 100%; }
+ pre > code.sourceCode { white-space: pre; position: relative; }
+ pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
+ pre > code.sourceCode > span:empty { height: 1.2em; }
+ .sourceCode { overflow: visible; }
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
+ div.sourceCode { margin: 1em 0; }
+ pre.sourceCode { margin: 0; }
+ @media screen {
+ div.sourceCode { overflow: auto; }
+ }
+ @media print {
+ pre > code.sourceCode { white-space: pre-wrap; }
+ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
+ }
+ pre.numberSource code
+ { counter-reset: source-line 0; }
+ pre.numberSource code > span
+ { position: relative; left: -4em; counter-increment: source-line; }
+ pre.numberSource code > span > a:first-child::before
+ { content: counter(source-line);
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
+ border: none; display: inline-block;
+ -webkit-touch-callout: none; -webkit-user-select: none;
+ -khtml-user-select: none; -moz-user-select: none;
+ -ms-user-select: none; user-select: none;
+ padding: 0 4px; width: 4em;
+ color: #aaaaaa;
+ }
+ pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
+ div.sourceCode
+ { }
+ @media screen {
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
+ }
+ code span.al { color: #ff0000; font-weight: bold; } /* Alert */
+ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
+ code span.at { color: #7d9029; } /* Attribute */
+ code span.bn { color: #40a070; } /* BaseN */
+ code span.bu { color: #008000; } /* BuiltIn */
+ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
+ code span.ch { color: #4070a0; } /* Char */
+ code span.cn { color: #880000; } /* Constant */
+ code span.co { color: #60a0b0; font-style: italic; } /* Comment */
+ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
+ code span.do { color: #ba2121; font-style: italic; } /* Documentation */
+ code span.dt { color: #902000; } /* DataType */
+ code span.dv { color: #40a070; } /* DecVal */
+ code span.er { color: #ff0000; font-weight: bold; } /* Error */
+ code span.ex { } /* Extension */
+ code span.fl { color: #40a070; } /* Float */
+ code span.fu { color: #06287e; } /* Function */
+ code span.im { color: #008000; font-weight: bold; } /* Import */
+ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
+ code span.kw { color: #007020; font-weight: bold; } /* Keyword */
+ code span.op { color: #666666; } /* Operator */
+ code span.ot { color: #007020; } /* Other */
+ code span.pp { color: #bc7a00; } /* Preprocessor */
+ code span.sc { color: #4070a0; } /* SpecialChar */
+ code span.ss { color: #bb6688; } /* SpecialString */
+ code span.st { color: #4070a0; } /* String */
+ code span.va { color: #19177c; } /* Variable */
+ code span.vs { color: #4070a0; } /* VerbatimString */
+ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
+ </style>
+$for(css)$
+ <link rel="stylesheet" href="$css$" />
+$endfor$
+$for(header-includes)$
+ $header-includes$
+$endfor$
+$if(math)$
+ $math$
+$endif$
+</head>
+<body>
+$for(include-before)$
+$include-before$
+$endfor$
+$if(title)$
+<header id="title-block-header">
+<h1 class="title">$title$</h1>
+$if(subtitle)$
+<p class="subtitle">$subtitle$</p>
+$endif$
+$for(author)$
+<p class="author">$author$</p>
+$endfor$
+$if(date)$
+<p class="date">$date$</p>
+$endif$
+$if(abstract)$
+<div class="abstract">
+<div class="abstract-title">$abstract-title$</div>
+$abstract$
+</div>
+$endif$
+</header>
+$endif$
+$if(toc)$
+<nav id="$idprefix$TOC" role="doc-toc">
+$if(toc-title)$
+<h2 id="$idprefix$toc-title">$toc-title$</h2>
+$endif$
+$table-of-contents$
+</nav>
+$endif$
+$body$
+$for(include-after)$
+$include-after$
+$endfor$
+</body>
+</html>