Skip to content

Commit

Permalink
Dev 1.0 BSDCan update (#46)
Browse files Browse the repository at this point in the history
Fixed mixup between "usage" (quick command overview) and "help" (man pages), fixed man page installer for Debian variants.
  • Loading branch information
bellhyve authored May 31, 2024
1 parent 0c6446b commit 04b08f5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 45 deletions.
32 changes: 18 additions & 14 deletions bin/zelta
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#
# Initialize the environment for Zelta subcommands

ZELTA_VERSION="Zelta Replication Suite v1.0"

: ${ZELTA_ETC:="/usr/local/etc/zelta"}
: ${ZELTA_ENV:="$ZELTA_ETC/zelta.env"}
: ${ZELTA_SNAP_NAME:="date -u +%Y-%m-%d_%H.%M.%S"}
Expand Down Expand Up @@ -34,26 +36,28 @@ fi

case $zelta_command in
# Command synonyms
zmatch) $AWKPRE/zelta-match.awk -- "$@" ;;
zp) $AWKPRE/zelta-policy.awk -- "$@" ;;
zpull) $AWKPRE/zelta-replicate.awk -- "$@" ;;
zpush) $AWKPRE/zelta-replicate.awk -- "$@" ;;
zeport) $AWKPRE/zelta-report.awk -- "$@" ;;
zmatch) $AWKPRE/zelta-match.awk -- "$@" ;;
zp) $AWKPRE/zelta-policy.awk -- "$@" ;;
zpull) $AWKPRE/zelta-replicate.awk -- "$@" ;;
zpush) $AWKPRE/zelta-replicate.awk -- "$@" ;;
zeport) $AWKPRE/zelta-report.awk -- "$@" ;;
# "zelta replicate" variants
backup) $AWKPRE/zelta-replicate.awk -- -sI "$@" ;;
clone) $AWKPRE/zelta-replicate.awk -- --clone "$@" ;;
sync) $AWKPRE/zelta-replicate.awk -- -i "$@" ;;
backup) $AWKPRE/zelta-replicate.awk -- -sI "$@" ;;
clone) $AWKPRE/zelta-replicate.awk -- --clone "$@" ;;
sync) $AWKPRE/zelta-replicate.awk -- -i "$@" ;;
# Utilities
snapshot) echo "$@" | $AWKPRE/zelta-snapshot.awk ;;
endpoint) echo "$@" | $AWKPRE/zelta-endpoint.awk ;;
time) "$@" | bash -c "time -p cat" ;;
snapshot) echo "$@" | $AWKPRE/zelta-snapshot.awk ;;
endpoint) echo "$@" | $AWKPRE/zelta-endpoint.awk ;;
time) "$@" | bash -c "time -p cat" ;;
# Info
-V|--version|version) echo zelta-pre-release; exit ;;
-?|usage|help) . $ZELTA_SHARE/zelta-usage.sh "$@" ;;
-V|--version) echo $ZELTA_VERSION; exit ;;
version) echo $ZELTA_VERSION; exit ;;
help) . $ZELTA_SHARE/zelta-usage.sh "$@" ;;
-?|usage) "$ZELTA_SHARE/zelta-usage.sh" "$zelta_command" "$@" ;;
# Matching script name action
*) if [ -r "$ZELTA_SHARE/zelta-$zelta_command.awk" ]; then
$AWKPRE/zelta-$zelta_command.awk -- "$@"
else
. $ZELTA_SHARE/zelta-usage.sh "$@"
"$ZELTA_SHARE/zelta-usage.sh" usage "$zelta_command" "$@"
fi ;;
esac
51 changes: 36 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,36 @@ if [ root = "$USER" ]; then
: ${ZELTA_BIN:="/usr/local/bin"}
: ${ZELTA_SHARE:="/usr/local/share/zelta"}
: ${ZELTA_ETC:="/usr/local/etc/zelta"}
: ${ZELTA_MAN:="/usr/local/share/man/man8"}
if [ ! -d "$ZELTA_MAN" ] ; then
ZELTA_MAN="/usr/share/man/man8"
: ${ZELTA_MAN8:="/usr/local/share/man/man8"}
if [ ! -d "$ZELTA_MAN8" ] ; then
ZELTA_MAN8="/usr/share/man/man8"
fi
elif [ -z "$ZELTA_BIN$ZELTA_SHARE$ZELTA_ETC" ]; then
elif [ -z "$ZELTA_BIN$ZELTA_SHARE$ZELTA_ETC$ZELTA_DOC" ]; then
: ${ZELTA_BIN:="$HOME/bin"}
: ${ZELTA_SHARE:="$HOME/.local/share/zelta"}
: ${ZELTA_ETC:="$HOME/.config/zelta"}
: ${ZELTA_MAN:="$ZELTA_SHARE/doc"}
echo Installing Zelta as an unprivilaged user. To ensure the per-user setup of
echo Zelta is being used, please export the following environment variables in
echo your shell\'s startup scripts:
: ${ZELTA_DOC:="$ZELTA_SHARE/doc"}
echo Installing Zelta as an Unprivileged User
echo
echo To install Zelta as an unprivileged user, follow these steps:
echo
echo 1. Set the following environment variables in your startup script
echo or export them with your desired values:
echo
echo export ZELTA_BIN=\"$ZELTA_BIN\"
echo export ZELTA_SHARE=\"$ZELTA_SHARE\"
echo export ZELTA_ETC=\"$ZELTA_ETC\"
echo export ZELTA_MAN=\"$ZELTA_MAN\"
echo export ZELTA_DOC=\"$ZELTA_DOC\"
echo
echo 2. Ensure that \"$ZELTA_BIN\" is in PATH environment variable.
echo
echo You may also set these variables as desired and rerun this command.
echo Press Control-C to break or Return to install; read whatever
echo Note: If you prefer a global installation, cancel this installation
echo and rerun this command as root, e.g. \`sudo install.sh\`.
echo
echo Proceed with installation?
echo
echo Press Control-C to stop or Return to install using the above paths.
read whatever
fi

: ${ZELTA_CONF:="$ZELTA_ETC/zelta.conf"}
Expand Down Expand Up @@ -57,14 +67,17 @@ link_to_zelta() {
}


mkdir -p "$ZELTA_BIN" "$ZELTA_SHARE" "$ZELTA_ETC" "$ZELTA_MAN"
mkdir -p "$ZELTA_BIN" "$ZELTA_SHARE" "$ZELTA_ETC" "$ZELTA_DOC"
copy_file bin/zelta "$ZELTA"
find share/zelta -name '*.awk' -o -name '*.sh' | while read -r file; do
copy_file "$file" "${ZELTA_SHARE}/$(basename "$file")"
done
find doc -name '*.8' | while read -r file; do
copy_file "$file" "${ZELTA_MAN}/$(basename "$file")"
done

if [ -x "$ZELTA_MAN8" ] ; then
find doc -name '*.8' | while read -r file; do
copy_file "$file" "${ZELTA_MAN8}/$(basename "$file")"
done
fi

## Old Aliases:
# link_to_zelta zmatch
Expand All @@ -83,3 +96,11 @@ copy_file zelta.conf "${ZELTA_CONF}.example" "644"
if [ ! -s "$ZELTA_CONF" ]; then
copy_file zelta.conf "$ZELTA_CONF" "644"
fi

# Add doc if requested
if [ "$ZELTA_DOC" ]; then
mkdir -p "$ZELTA_DOC"
find doc/ -type f | while read -r file; do
copy_file "$file" "${ZELTA_DOC}/$(basename "$file")"
done
fi
12 changes: 6 additions & 6 deletions share/zelta/zelta-policy.awk
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function long_option() {
}

function get_options() {
# Possible Options
# Policy Options
OPTIONS["archive_root"]++
OPTIONS["backup_root"]++
OPTIONS["depth"]++
Expand Down Expand Up @@ -292,7 +292,7 @@ function h_num(num) {
return int(num) suffix
}

function zelta_sync() {
function zelta_replicate() {
sync_cmd = backup_command[site,host,source]
sync_status = 1
if (MODE == "LIST") {
Expand All @@ -310,7 +310,7 @@ function zelta_sync() {
if (/[0-9]+ [0-9]+ [0-9]+\.*[0-9]* -?[0-9]+/) {
if ($2) report(LOG_DEFAULT, h_num($2) ": ")
if ($4) {
report(LOG_DEFAULT, "failed: ")
#report(LOG_DEFAULT, "failed: ")
sync_status = 0
if ($4 == 1) report(LOG_DEFAULT, "error matching snapshots")
else if ($4 == 2) report(LOG_DEFAULT, "replication error")
Expand Down Expand Up @@ -356,7 +356,7 @@ BEGIN {
target = datasets[host,source]
if (!AUTO && !should_replicate()) continue
if (MODE == "ACTIVE") report(LOG_DEFAULT," ")
if (! zelta_sync()) {
if (! zelta_replicate()) {
failed_num++
failed_list[site"\t"host"\t"source"\t"target]++
}
Expand All @@ -367,8 +367,8 @@ BEGIN {
for (failed_sync in failed_list) {
$0 = failed_sync
site = $1; host = $2; source = $3; target = $4
if (MODE != "JSON") report(LOG_DEFAULT, "retrying: " $host ":" $source ": ")
if (zelta_sync()) {
if (MODE != "JSON") report(LOG_DEFAULT, "retry: " )
if (zelta_replicate()) {
delete failed_list[failed_sync]
}
}
Expand Down
7 changes: 5 additions & 2 deletions share/zelta/zelta-replicate.awk
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ function name_match_row() {
target_match = targetds match_snap
source_match = sourceds match_snap

single_snap = (sfirst && (sfirst == slast))
sorigin = srcprop[dataset,"origin"]
match_origin = ""
rotate_name = ""
Expand Down Expand Up @@ -576,8 +577,10 @@ BEGIN {

time_start = sys_time()
load_properties(source, srcprop)
if (NO_DS[source]) stop(1, "source does not exist: "source)
load_properties(target, tgtprop)
if (CLONE_MODE && !NO_DS[target]) stop(1, "cannot clone; target exists: "target)

run_snapshot()
while (match_command |getline) {
if (!name_match_row()) {
Expand All @@ -594,7 +597,7 @@ BEGIN {
continue
}
if (src_only) {
if (INTR) {
if (INTR && !single_snap) {
command_queue(sfirst_full, targetds)
command_queue(slast_full, targetds, sfirst)
} else command_queue(slast_full, targetds)
Expand All @@ -614,7 +617,7 @@ BEGIN {
rename_command = zfs[target] " rename " q(ds[target]) " " q(torigin_name)
if (! dry_run(rename_command)) {
system(rename_command)
report(LOG_BASIC, "source renamed to " q(torigin_name))
report(LOG_BASIC, "target renamed to " q(torigin_name))
}
}

Expand Down
29 changes: 21 additions & 8 deletions share/zelta/zelta-usage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

usage_zelta() {
cat << EOF
cat >&2 << EOF
usage: zelta command args ...
where 'command' is one of the following:
Expand All @@ -27,12 +27,25 @@ For further help on a command or topic, run: zelta help [<topic>]
EOF
}

# Add "man" if available.
runman() {
SECTION=8
if [ -s "$ZELTA_DOC" ] ; then
man "$ZELTA_DOC/$1.$SECTION"
else
man $SECTION $1
fi
}

case $1 in
usage|help) usage_zelta ;;
backup|sync|clone|replicate) man zelta-backup ;;
match) man zelta-match ;;
policy) man zelta-policy ;;
*) [ -n "$1" ] && echo unrecognized command \'$1\' >>/dev/null ;
usage_zelta ;;
usage|-?) usage_zelta ;;
help) runman zelta ;;
backup|sync|clone|replicate) runman zelta-backup ;;
match) runman zelta-match ;;
policy) runman zelta-policy ;;
*) if [ -n "$1" ] ; then
echo unrecognized command \'$1\' >&2
usage_zelta
else
runman zelta
fi ;;
esac

0 comments on commit 04b08f5

Please sign in to comment.