From 2a3f2ed19144f45d86892a25caa8fdb43cfb2ea8 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Sun, 29 Aug 2021 11:23:15 -0700 Subject: [PATCH] make sudo optional, set a prefix command common to all --- all/dev/backup/dbackup | 13 +++++++------ all/dev/backup/src/root_command.sh | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/all/dev/backup/dbackup b/all/dev/backup/dbackup index edd5141..5d850ca 100755 --- a/all/dev/backup/dbackup +++ b/all/dev/backup/dbackup @@ -98,19 +98,20 @@ root_command() { # local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\"" #cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target" + local sudo="" + local pcmd="${sudo} ${password} ${bin} -r ${target}" + local cmd="${pcmd} backup ${source} ${exclude}" - cmd="sudo $password $bin -r $target backup $source $exclude" - - if [[ ${args[--init]} ]]; then cmd="sudo $password $bin -r $target init"; fi - if [[ ${args[--snap]} ]]; then cmd="sudo $password $bin -r $target snapshots"; fi - if [[ ${args[--prune]} ]]; then cmd="sudo password $bin -r $target prune"; fi + if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi + if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi + if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi if [[ ${args[--view]} || ${args[--view-path]} ]]; then mount=${args[--view-path]:-$BACKUP_MOUNT} mount=${mount:-"/opt/backup/view/"} echo view mount point $mount if [[ -e ${mount} ]]; then - cmd="$password $bin -r $target mount $mount"; + cmd="${pcmd} mount $mount"; echo browse files at $mount/snapshots/latest${source} else echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again diff --git a/all/dev/backup/src/root_command.sh b/all/dev/backup/src/root_command.sh index 7590110..37ef0fb 100644 --- a/all/dev/backup/src/root_command.sh +++ b/all/dev/backup/src/root_command.sh @@ -91,19 +91,20 @@ echo exclude: $exclude # local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\"" #cmd="$sudo rdiff-backup $options $exclude $ssh ${suser}${shost}$source ${tuser}${thost}$target" +local sudo="" +local pcmd="${sudo} ${password} ${bin} -r ${target}" +local cmd="${pcmd} backup ${source} ${exclude}" -cmd="sudo $password $bin -r $target backup $source $exclude" - -if [[ ${args[--init]} ]]; then cmd="sudo $password $bin -r $target init"; fi -if [[ ${args[--snap]} ]]; then cmd="sudo $password $bin -r $target snapshots"; fi -if [[ ${args[--prune]} ]]; then cmd="sudo password $bin -r $target prune"; fi +if [[ ${args[--init]} ]]; then cmd="${pcmd} init"; fi +if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi +if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; fi if [[ ${args[--view]} || ${args[--view-path]} ]]; then mount=${args[--view-path]:-$BACKUP_MOUNT} mount=${mount:-"/opt/backup/view/"} echo view mount point $mount if [[ -e ${mount} ]]; then - cmd="$password $bin -r $target mount $mount"; + cmd="${pcmd} mount $mount"; echo browse files at $mount/snapshots/latest${source} else echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again