make sudo optional, set a prefix command common to all

master
Kebler Network System Administrator 2021-08-29 11:23:15 -07:00
parent b6e3f1bb2b
commit 2a3f2ed191
2 changed files with 14 additions and 12 deletions

View File

@ -98,19 +98,20 @@ root_command() {
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\"" # 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" #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="${pcmd} init"; fi
if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi
if [[ ${args[--init]} ]]; then cmd="sudo $password $bin -r $target init"; fi if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; 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[--view]} || ${args[--view-path]} ]]; then if [[ ${args[--view]} || ${args[--view-path]} ]]; then
mount=${args[--view-path]:-$BACKUP_MOUNT} mount=${args[--view-path]:-$BACKUP_MOUNT}
mount=${mount:-"/opt/backup/view/"} mount=${mount:-"/opt/backup/view/"}
echo view mount point $mount echo view mount point $mount
if [[ -e ${mount} ]]; then if [[ -e ${mount} ]]; then
cmd="$password $bin -r $target mount $mount"; cmd="${pcmd} mount $mount";
echo browse files at $mount/snapshots/latest${source} echo browse files at $mount/snapshots/latest${source}
else else
echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again

View File

@ -91,19 +91,20 @@ echo exclude: $exclude
# local ssh="--remote-schema \"ssh -C %s /home/sysadmin/.local/bin/rdiff-backup --server\"" # 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" #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="${pcmd} init"; fi
if [[ ${args[--snap]} ]]; then cmd="${pcmd} snapshots"; fi
if [[ ${args[--init]} ]]; then cmd="sudo $password $bin -r $target init"; fi if [[ ${args[--prune]} ]]; then cmd="${pcmd} prune"; 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[--view]} || ${args[--view-path]} ]]; then if [[ ${args[--view]} || ${args[--view-path]} ]]; then
mount=${args[--view-path]:-$BACKUP_MOUNT} mount=${args[--view-path]:-$BACKUP_MOUNT}
mount=${mount:-"/opt/backup/view/"} mount=${mount:-"/opt/backup/view/"}
echo view mount point $mount echo view mount point $mount
if [[ -e ${mount} ]]; then if [[ -e ${mount} ]]; then
cmd="$password $bin -r $target mount $mount"; cmd="${pcmd} mount $mount";
echo browse files at $mount/snapshots/latest${source} echo browse files at $mount/snapshots/latest${source}
else else
echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again echo $mount: directory for mounting snapshot for viewing does not exist. Create and try again