]> arthur.barton.de Git - bup.git/commitdiff
Handle external commands directly rather than via renamed symlinks
authorRob Browning <rlb@defaultvalue.org>
Sun, 13 Dec 2020 19:25:10 +0000 (13:25 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:51 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Makefile
lib/cmd/bup-import-rdiff-backup [new file with mode: 0755]
lib/cmd/bup-import-rsnapshot [new file with mode: 0755]
lib/cmd/import-rdiff-backup-cmd.sh [deleted file]
lib/cmd/import-rsnapshot-cmd.sh [deleted file]

index 29383a55fda62f5deab8e1daeec52bd898c79823..a9c7fb9ebc278ac072c6372db88a7dbd3448117d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -71,13 +71,11 @@ ifeq ($(bup_have_libacl),1)
   LDFLAGS += $(bup_libacl_ldflags)
 endif
 
-config/bin/python: config/config.vars
+bup_ext_cmds := lib/cmd/bup-import-rdiff-backup lib/cmd/bup-import-rsnapshot
 
-bup_cmds := \
-  $(patsubst cmd/%-cmd.py,cmd/bup-%,$(wildcard cmd/*-cmd.py)) \
-  $(patsubst cmd/%-cmd.sh,cmd/bup-%,$(wildcard cmd/*-cmd.sh))
+config/bin/python: config/config.vars
 
-bup_deps := lib/bup/_helpers$(SOEXT) $(bup_cmds)
+bup_deps := lib/bup/_helpers$(SOEXT)
 
 all: $(bup_deps) Documentation/all $(current_sampledata)
 
@@ -109,24 +107,19 @@ dest_bindir := $(DESTDIR)$(BINDIR)
 dest_libdir := $(DESTDIR)$(LIBDIR)
 
 install: all
-       $(INSTALL) -d $(dest_bindir) \
-               $(dest_libdir)/bup $(dest_libdir)/cmd \
-               $(dest_libdir)/web $(dest_libdir)/web/static
+       $(INSTALL) -d $(dest_bindir) $(dest_libdir)/bup/cmd $(dest_libdir)/cmd \
+         $(dest_libdir)/web/static
        test -z "$(man_roff)" || install -d $(dest_mandir)/man1
        test -z "$(man_roff)" || $(INSTALL) -m 0644 $(man_roff) $(dest_mandir)/man1
        test -z "$(man_html)" || install -d $(dest_docdir)
        test -z "$(man_html)" || $(INSTALL) -m 0644 $(man_html) $(dest_docdir)
        dev/install-python-script lib/cmd/bup "$(dest_libdir)/cmd/bup"
-       set -e; \
-       for cmd in $$(ls cmd/bup-*); do \
-         dev/install-python-script "$$cmd" "$(dest_libdir)/$$cmd"; \
-       done
+       $(INSTALL) -pm 0755 $(bup_ext_cmds) "$(dest_libdir)/cmd/"
        cd "$(dest_bindir)" && \
          ln -sf "$$($(bup_python) -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')"
        set -e; \
-       $(INSTALL) -pm 0644 \
-               lib/bup/*.py \
-               $(dest_libdir)/bup
+       $(INSTALL) -pm 0644 lib/bup/*.py $(dest_libdir)/bup/
+       $(INSTALL) -pm 0644 lib/bup/cmd/*.py $(dest_libdir)/bup/cmd/
        $(INSTALL) -pm 0755 \
                lib/bup/*$(SOEXT) \
                $(dest_libdir)/bup
@@ -191,14 +184,6 @@ check-both:
        $(MAKE) clean && PYTHON=python3 $(MAKE) check
        $(MAKE) clean && PYTHON=python2 $(MAKE) check
 
-cmd/bup-%: cmd/%-cmd.py
-       rm -f $@
-       ln -s $*-cmd.py $@
-
-cmd/bup-%: cmd/%-cmd.sh
-       rm -f $@
-       ln -s $*-cmd.sh $@
-
 .PHONY: Documentation/all
 Documentation/all: $(man_roff) $(man_html)
 
@@ -248,9 +233,6 @@ clean: Documentation/clean config/bin/python
                lib/bup/checkout_info.py \
                randomgen memtest \
                testfs.img test/int/testfs.img
-       for x in $$(ls cmd/*-cmd.py cmd/*-cmd.sh | grep -vF python-cmd.sh | cut -b 5-); do \
-           echo "cmd/bup-$${x%-cmd.*}"; \
-       done | xargs -t rm -f
        if test -e test/mnt; then dev/cleanup-mounts-under test/mnt; fi
        if test -e test/mnt; then rm -r test/mnt; fi
        if test -e test/tmp; then dev/cleanup-mounts-under test/tmp; fi
diff --git a/lib/cmd/bup-import-rdiff-backup b/lib/cmd/bup-import-rdiff-backup
new file mode 100755 (executable)
index 0000000..0bbf327
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+
+cmd_dir="$(cd "$(dirname "$0")" && pwd)" || exit $?
+
+set -o pipefail
+
+must() {
+    local file=${BASH_SOURCE[0]}
+    local line=${BASH_LINENO[0]}
+    "$@"
+    local rc=$?
+    if test $rc -ne 0; then
+        echo "Failed at line $line in $file" 1>&2
+        exit $rc
+    fi
+}
+
+usage() {
+    echo "Usage: bup import-rdiff-backup [-n]" \
+        "<path to rdiff-backup root> <backup name>"
+    echo "-n,--dry-run: just print what would be done"
+    exit 1
+}
+
+control_c() {
+    echo "bup import-rdiff-backup: signal 2 received" 1>&2
+    exit 128
+}
+
+must trap control_c INT
+
+dry_run=
+while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
+    dry_run=echo
+    shift
+done
+
+bup()
+{
+    $dry_run "$cmd_dir/bup" "$@"
+}
+
+snapshot_root="$1"
+branch="$2"
+
+[ -n "$snapshot_root" -a "$#" = 2 ] || usage
+
+if [ ! -e "$snapshot_root/." ]; then
+    echo "'$snapshot_root' isn't a directory!"
+    exit 1
+fi
+
+
+backups=$(must rdiff-backup --list-increments --parsable-output "$snapshot_root") \
+    || exit $?
+backups_count=$(echo "$backups" | must wc -l) || exit $?
+counter=1
+echo "$backups" |
+while read timestamp type; do
+    tmpdir=$(must mktemp -d import-rdiff-backup-XXXXXXX) || exit $?
+
+    echo "Importing backup from $(date -d @$timestamp +%c) " \
+        "($counter / $backups_count)" 1>&2
+    echo 1>&2
+
+    echo "Restoring from rdiff-backup..." 1>&2
+    must rdiff-backup -r $timestamp "$snapshot_root" "$tmpdir"
+    echo 1>&2
+
+    echo "Importing into bup..." 1>&2
+    tmpidx=$(must mktemp -u import-rdiff-backup-idx-XXXXXXX) || exit $?
+    must bup index -ux -f "$tmpidx" "$tmpdir"
+    must bup save --strip --date="$timestamp" -f "$tmpidx" -n "$branch" "$tmpdir"
+    must rm -f "$tmpidx"
+
+    must rm -rf "$tmpdir"
+    counter=$((counter+1))
+    echo 1>&2
+    echo 1>&2
+done
diff --git a/lib/cmd/bup-import-rsnapshot b/lib/cmd/bup-import-rsnapshot
new file mode 100755 (executable)
index 0000000..91f711e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Does an import of a rsnapshot archive.
+
+cmd_dir="$(cd "$(dirname "$0")" && pwd)" || exit $?
+
+usage() {
+    echo "Usage: bup import-rsnapshot [-n]" \
+        "<path to snapshot_root> [<backuptarget>]"
+    echo "-n,--dry-run: just print what would be done"
+    exit 1
+}
+
+DRY_RUN=
+while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
+    DRY_RUN=echo
+    shift
+done
+
+bup()
+{
+    $DRY_RUN "$cmd_dir/bup" "$@"
+}
+
+SNAPSHOT_ROOT=$1
+TARGET=$2
+
+[ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage
+
+if [ ! -e "$SNAPSHOT_ROOT/." ]; then
+    echo "'$SNAPSHOT_ROOT' isn't a directory!"
+    exit 1
+fi
+
+
+cd "$SNAPSHOT_ROOT" || exit 2
+
+for SNAPSHOT in *; do
+    [ -e "$SNAPSHOT/." ] || continue
+    echo "snapshot='$SNAPSHOT'" >&2
+    for BRANCH_PATH in "$SNAPSHOT/"*; do
+        BRANCH=$(basename "$BRANCH_PATH") || exit $?
+        [ -e "$BRANCH_PATH/." ] || continue
+        [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ] || continue
+        
+        echo "snapshot='$SNAPSHOT' branch='$BRANCH'" >&2
+
+        # Get the snapshot's ctime
+        DATE=$(perl -e '@a=stat($ARGV[0]) or die "$ARGV[0]: $!";
+                        print $a[10];' "$BRANCH_PATH")
+       [ -n "$DATE" ] || exit 3
+
+        TMPIDX=bupindex.$BRANCH.tmp
+        bup index -ux -f "$TMPIDX" "$BRANCH_PATH/" || exit $?
+        bup save --strip --date="$DATE" \
+            -f "$TMPIDX" -n "$BRANCH" \
+            "$BRANCH_PATH/" || exit $?
+        rm "$TMPIDX" || exit $?
+    done
+done
diff --git a/lib/cmd/import-rdiff-backup-cmd.sh b/lib/cmd/import-rdiff-backup-cmd.sh
deleted file mode 100755 (executable)
index 0bbf327..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/usr/bin/env bash
-
-cmd_dir="$(cd "$(dirname "$0")" && pwd)" || exit $?
-
-set -o pipefail
-
-must() {
-    local file=${BASH_SOURCE[0]}
-    local line=${BASH_LINENO[0]}
-    "$@"
-    local rc=$?
-    if test $rc -ne 0; then
-        echo "Failed at line $line in $file" 1>&2
-        exit $rc
-    fi
-}
-
-usage() {
-    echo "Usage: bup import-rdiff-backup [-n]" \
-        "<path to rdiff-backup root> <backup name>"
-    echo "-n,--dry-run: just print what would be done"
-    exit 1
-}
-
-control_c() {
-    echo "bup import-rdiff-backup: signal 2 received" 1>&2
-    exit 128
-}
-
-must trap control_c INT
-
-dry_run=
-while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
-    dry_run=echo
-    shift
-done
-
-bup()
-{
-    $dry_run "$cmd_dir/bup" "$@"
-}
-
-snapshot_root="$1"
-branch="$2"
-
-[ -n "$snapshot_root" -a "$#" = 2 ] || usage
-
-if [ ! -e "$snapshot_root/." ]; then
-    echo "'$snapshot_root' isn't a directory!"
-    exit 1
-fi
-
-
-backups=$(must rdiff-backup --list-increments --parsable-output "$snapshot_root") \
-    || exit $?
-backups_count=$(echo "$backups" | must wc -l) || exit $?
-counter=1
-echo "$backups" |
-while read timestamp type; do
-    tmpdir=$(must mktemp -d import-rdiff-backup-XXXXXXX) || exit $?
-
-    echo "Importing backup from $(date -d @$timestamp +%c) " \
-        "($counter / $backups_count)" 1>&2
-    echo 1>&2
-
-    echo "Restoring from rdiff-backup..." 1>&2
-    must rdiff-backup -r $timestamp "$snapshot_root" "$tmpdir"
-    echo 1>&2
-
-    echo "Importing into bup..." 1>&2
-    tmpidx=$(must mktemp -u import-rdiff-backup-idx-XXXXXXX) || exit $?
-    must bup index -ux -f "$tmpidx" "$tmpdir"
-    must bup save --strip --date="$timestamp" -f "$tmpidx" -n "$branch" "$tmpdir"
-    must rm -f "$tmpidx"
-
-    must rm -rf "$tmpdir"
-    counter=$((counter+1))
-    echo 1>&2
-    echo 1>&2
-done
diff --git a/lib/cmd/import-rsnapshot-cmd.sh b/lib/cmd/import-rsnapshot-cmd.sh
deleted file mode 100755 (executable)
index 91f711e..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/sh
-# Does an import of a rsnapshot archive.
-
-cmd_dir="$(cd "$(dirname "$0")" && pwd)" || exit $?
-
-usage() {
-    echo "Usage: bup import-rsnapshot [-n]" \
-        "<path to snapshot_root> [<backuptarget>]"
-    echo "-n,--dry-run: just print what would be done"
-    exit 1
-}
-
-DRY_RUN=
-while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
-    DRY_RUN=echo
-    shift
-done
-
-bup()
-{
-    $DRY_RUN "$cmd_dir/bup" "$@"
-}
-
-SNAPSHOT_ROOT=$1
-TARGET=$2
-
-[ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage
-
-if [ ! -e "$SNAPSHOT_ROOT/." ]; then
-    echo "'$SNAPSHOT_ROOT' isn't a directory!"
-    exit 1
-fi
-
-
-cd "$SNAPSHOT_ROOT" || exit 2
-
-for SNAPSHOT in *; do
-    [ -e "$SNAPSHOT/." ] || continue
-    echo "snapshot='$SNAPSHOT'" >&2
-    for BRANCH_PATH in "$SNAPSHOT/"*; do
-        BRANCH=$(basename "$BRANCH_PATH") || exit $?
-        [ -e "$BRANCH_PATH/." ] || continue
-        [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ] || continue
-        
-        echo "snapshot='$SNAPSHOT' branch='$BRANCH'" >&2
-
-        # Get the snapshot's ctime
-        DATE=$(perl -e '@a=stat($ARGV[0]) or die "$ARGV[0]: $!";
-                        print $a[10];' "$BRANCH_PATH")
-       [ -n "$DATE" ] || exit 3
-
-        TMPIDX=bupindex.$BRANCH.tmp
-        bup index -ux -f "$TMPIDX" "$BRANCH_PATH/" || exit $?
-        bup save --strip --date="$DATE" \
-            -f "$TMPIDX" -n "$BRANCH" \
-            "$BRANCH_PATH/" || exit $?
-        rm "$TMPIDX" || exit $?
-    done
-done