From e4e1273e5a5c0a3987047ddb7486122a39520950 Mon Sep 17 00:00:00 2001 From: deajan Date: Sun, 23 Oct 2016 18:04:39 +0200 Subject: [PATCH] Implemented SSH_PASSWORD_FILE option --- dev/n_obackup.sh | 26 +++++++++++++++++++------- upgrade-v1.x-2.1x.sh | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dev/n_obackup.sh b/dev/n_obackup.sh index 22a1246..6aab525 100755 --- a/dev/n_obackup.sh +++ b/dev/n_obackup.sh @@ -9,7 +9,7 @@ PROGRAM="obackup" AUTHOR="(C) 2013-2016 by Orsiris de Jong" CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr" PROGRAM_VERSION=2.1-dev -PROGRAM_BUILD=2016102301 +PROGRAM_BUILD=2016102303 IS_STABLE=no source "./ofunctions.sh" @@ -94,6 +94,11 @@ function CheckEnvironment { CAN_BACKUP_SQL=false fi fi + + if [ "$SSH_PASSWORD_FILE" != "" ] && ! type sshpass > /dev/null 2>&1 ; then + Logger "sshpass not present. Cannot use password authentication." "CRITICAL" + exit 1 + fi fi if [ "$FILE_BACKUP" != "no" ]; then @@ -189,7 +194,10 @@ function CheckCurrentConfig { fi fi - + if [ "$REMOTE_OPERATION" == "yes" ] && ([ ! -f "$SSH_RSA_PRIVATE_KEY" ] && [ ! -f "$SSH_PASSWORD_FILE" ]); then + Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY] nor password file [$SSH_PASSWORD_FILE]. No authentication method provided." "CRITICAL" + exit 1 + fi } function CheckRunningInstances { @@ -482,7 +490,7 @@ function _GetDirectoriesSizeLocal { if [ -s "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then TOTAL_FILES_SIZE="$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" - if [ $(IsNumeric $TOTAL_FILES_SIZE) -eq 0 ]; then + if [ $(IsInteger $TOTAL_FILES_SIZE) -eq 0 ]; then TOTAL_FILES_SIZE="$(HumanToNumeric $TOTAL_FILES_SIZE)" fi else @@ -515,7 +523,7 @@ function _GetDirectoriesSizeRemote { fi if [ -s "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" ]; then TOTAL_FILES_SIZE="$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID)" - if [ $(IsNumeric $TOTAL_FILES_SIZE) -eq 0 ]; then + if [ $(IsInteger $TOTAL_FILES_SIZE) -eq 0 ]; then TOTAL_FILES_SIZE="$(HumanToNumeric $TOTAL_FILES_SIZE)" fi else @@ -636,7 +644,7 @@ function GetDiskSpaceLocal { else DISK_SPACE=$(tail -1 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" | awk '{print $4}') DRIVE=$(tail -1 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" | awk '{print $1}') - if [ $(IsNumeric $DISK_SPACE) -eq 0 ]; then + if [ $(IsInteger $DISK_SPACE) -eq 0 ]; then DISK_SPACE="$(HumanToNumeric $DISK_SPACE)" fi fi @@ -665,7 +673,7 @@ function GetDiskSpaceRemote { else DISK_SPACE=$(tail -1 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" | awk '{print $4}') DRIVE=$(tail -1 "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID" | awk '{print $1}') - if [ $(IsNumeric $DISK_SPACE) -eq 0 ]; then + if [ $(IsInteger $DISK_SPACE) -eq 0 ]; then DISK_SPACE="$(HumanToNumeric $DISK_SPACE)" fi fi @@ -1469,7 +1477,10 @@ function Init { fi if [ "$SSH_RSA_PRIVATE_KEY" == "" ]; then - SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa + if [ ! -f "$SSH_PASSWORD_FILE" ]; then + # Assume that there might exist a standard rsa key + SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa + fi fi # remove everything before '@' @@ -1522,6 +1533,7 @@ function Main { FILE_STORAGE="${FILE_STORAGE/#\~/$HOME}" SQL_STORAGE="${SQL_STORAGE/#\~/$HOME}" SSH_RSA_PRIVATE_KEY="${SSH_RSA_PRIVATE_KEY/#\~/$HOME}" + SSH_PASSWORD_FILE="${SSH_PASSWORD_FILE/#\~/$HOME}" ENCRYPT_PUBKEY="${ENCRYPT_PUBKEY/#\~/$HOME}" if [ "$CREATE_DIRS" != "no" ]; then diff --git a/upgrade-v1.x-2.1x.sh b/upgrade-v1.x-2.1x.sh index 4424aa5..dfd6795 100755 --- a/upgrade-v1.x-2.1x.sh +++ b/upgrade-v1.x-2.1x.sh @@ -37,7 +37,7 @@ SQL_WARN_MIN_SPACE FILE_WARN_MIN_SPACE REMOTE_SYSTEM_URI SSH_RSA_PRIVATE_KEY -SSH_PASSWORD +SSH_PASSWORD_FILE SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS RSYNC_REMOTE_PATH