mirror of
https://github.com/deajan/obackup.git
synced 2024-11-15 04:03:41 +01:00
Rebuilt targets
This commit is contained in:
parent
0a10ea99d1
commit
e83474614f
@ -7,7 +7,7 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(C) 2013-2017 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2017 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.1-beta5
|
PROGRAM_VERSION=2.1-beta5
|
||||||
PROGRAM_BUILD=2018083005
|
PROGRAM_BUILD=2018091201
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
#### Execution order #__WITH_PARANOIA_DEBUG
|
#### Execution order #__WITH_PARANOIA_DEBUG
|
||||||
@ -4224,7 +4224,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
@ -4260,7 +4260,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" false true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" false true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
@ -4295,7 +4295,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
332
install.sh
332
install.sh
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
## Installer script suitable for osync / obackup / pmocr
|
## Installer script suitable for osync / obackup / pmocr
|
||||||
|
|
||||||
_OFUNCTIONS_BOOTSTRAP=true
|
|
||||||
|
|
||||||
PROGRAM=obackup
|
PROGRAM=obackup
|
||||||
|
|
||||||
PROGRAM_VERSION=$(grep "PROGRAM_VERSION=" $PROGRAM.sh)
|
PROGRAM_VERSION=$(grep "PROGRAM_VERSION=" $PROGRAM.sh)
|
||||||
@ -12,12 +10,15 @@ PROGRAM_BINARY=$PROGRAM".sh"
|
|||||||
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||||
SSH_FILTER="ssh_filter.sh"
|
SSH_FILTER="ssh_filter.sh"
|
||||||
|
|
||||||
SCRIPT_BUILD=2017072701
|
SCRIPT_BUILD=2018090301
|
||||||
|
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
||||||
|
|
||||||
## osync / obackup / pmocr / zsnap install script
|
## osync / obackup / pmocr / zsnap install script
|
||||||
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11
|
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11
|
||||||
## Please adapt this to fit your distro needs
|
## Please adapt this to fit your distro needs
|
||||||
|
|
||||||
|
_OFUNCTIONS_BOOTSTRAP=true
|
||||||
|
|
||||||
# Get current install.sh path from http://stackoverflow.com/a/246128/2635443
|
# Get current install.sh path from http://stackoverflow.com/a/246128/2635443
|
||||||
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
@ -45,8 +46,9 @@ function GetCommandlineArguments {
|
|||||||
Usage
|
Usage
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
Logger "Unknown option '$i'" "CRITICAL"
|
Logger "Unknown option '$i'" "SIMPLE"
|
||||||
Usage
|
Usage
|
||||||
|
exit
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -60,6 +62,7 @@ SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
|
|||||||
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
|
||||||
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
SERVICE_DIR_SYSTEMD_SYSTEM=$FAKEROOT/lib/systemd/system
|
||||||
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
SERVICE_DIR_SYSTEMD_USER=$FAKEROOT/etc/systemd/user
|
||||||
|
SERVICE_DIR_OPENRC=$FAKEROOT/etc/init.d
|
||||||
|
|
||||||
if [ "$PROGRAM" == "osync" ]; then
|
if [ "$PROGRAM" == "osync" ]; then
|
||||||
SERVICE_NAME="osync-srv"
|
SERVICE_NAME="osync-srv"
|
||||||
@ -70,6 +73,7 @@ fi
|
|||||||
SERVICE_FILE_INIT="$SERVICE_NAME"
|
SERVICE_FILE_INIT="$SERVICE_NAME"
|
||||||
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
|
||||||
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
|
||||||
|
SERVICE_FILE_OPENRC="$SERVICE_NAME-openrc"
|
||||||
|
|
||||||
## Generic code
|
## Generic code
|
||||||
|
|
||||||
@ -82,7 +86,186 @@ else
|
|||||||
LOG_FILE="./$PROGRAM-install.log"
|
LOG_FILE="./$PROGRAM-install.log"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
include #### QuickLogger SUBSET ####
|
#### RemoteLogger SUBSET ####
|
||||||
|
|
||||||
|
# Array to string converter, see http://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array
|
||||||
|
# usage: joinString separaratorChar Array
|
||||||
|
function joinString {
|
||||||
|
local IFS="$1"; shift; echo "$*";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sub function of Logger
|
||||||
|
function _Logger {
|
||||||
|
local logValue="${1}" # Log to file
|
||||||
|
local stdValue="${2}" # Log to screeen
|
||||||
|
local toStdErr="${3:-false}" # Log to stderr instead of stdout
|
||||||
|
|
||||||
|
if [ "$logValue" != "" ]; then
|
||||||
|
echo -e "$logValue" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Build current log file for alerts if we have a sufficient environment
|
||||||
|
if [ "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" != "" ]; then
|
||||||
|
echo -e "$logValue" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$stdValue" != "" ] && [ "$_LOGGER_SILENT" != true ]; then
|
||||||
|
if [ $toStdErr == true ]; then
|
||||||
|
# Force stderr color in subshell
|
||||||
|
(>&2 echo -e "$stdValue")
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -e "$stdValue"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remote logger similar to below Logger, without log to file and alert flags
|
||||||
|
function RemoteLogger {
|
||||||
|
local value="${1}" # Sentence to log (in double quotes)
|
||||||
|
local level="${2}" # Log level
|
||||||
|
local retval="${3:-undef}" # optional return value of command
|
||||||
|
|
||||||
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
||||||
|
prefix="TIME: $SECONDS - "
|
||||||
|
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
||||||
|
prefix="R $(date) - "
|
||||||
|
else
|
||||||
|
prefix=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
|
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
|
if [ $_DEBUG == "yes" ]; then
|
||||||
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "ERROR" ]; then
|
||||||
|
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||||
|
if [ $_DEBUG == "yes" ]; then
|
||||||
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "WARN" ]; then
|
||||||
|
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||||
|
if [ $_DEBUG == "yes" ]; then
|
||||||
|
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
|
if [ $_LOGGER_ERR_ONLY != true ]; then
|
||||||
|
_Logger "" "$prefix$value"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
|
if [ $_LOGGER_VERBOSE == true ]; then
|
||||||
|
_Logger "" "$prefix$value"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "ALWAYS" ]; then
|
||||||
|
_Logger "" "$prefix$value"
|
||||||
|
return
|
||||||
|
elif [ "$level" == "DEBUG" ]; then
|
||||||
|
if [ "$_DEBUG" == "yes" ]; then
|
||||||
|
_Logger "" "$prefix$value"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
elif [ "$level" == "PARANOIA_DEBUG" ]; then #__WITH_PARANOIA_DEBUG
|
||||||
|
if [ "$_PARANOIA_DEBUG" == "yes" ]; then #__WITH_PARANOIA_DEBUG
|
||||||
|
_Logger "" "$prefix\e[35m$value\e[0m" #__WITH_PARANOIA_DEBUG
|
||||||
|
return #__WITH_PARANOIA_DEBUG
|
||||||
|
fi #__WITH_PARANOIA_DEBUG
|
||||||
|
else
|
||||||
|
_Logger "" "\e[41mLogger function called without proper loglevel [$level].\e[0m" true
|
||||||
|
_Logger "" "Value was: $prefix$value" true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#### RemoteLogger SUBSET END ####
|
||||||
|
|
||||||
|
# General log function with log levels:
|
||||||
|
|
||||||
|
# Environment variables
|
||||||
|
# _LOGGER_SILENT: Disables any output to stdout & stderr
|
||||||
|
# _LOGGER_ERR_ONLY: Disables any output to stdout except for ALWAYS loglevel
|
||||||
|
# _LOGGER_VERBOSE: Allows VERBOSE loglevel messages to be sent to stdout
|
||||||
|
|
||||||
|
# Loglevels
|
||||||
|
# Except for VERBOSE, all loglevels are ALWAYS sent to log file
|
||||||
|
|
||||||
|
# CRITICAL, ERROR, WARN sent to stderr, color depending on level, level also logged
|
||||||
|
# NOTICE sent to stdout
|
||||||
|
# VERBOSE sent to stdout if _LOGGER_VERBOSE = true
|
||||||
|
# ALWAYS is sent to stdout unless _LOGGER_SILENT = true
|
||||||
|
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=yes
|
||||||
|
# SIMPLE is a wrapper for QuickLogger that does not use advanced functionality
|
||||||
|
function Logger {
|
||||||
|
local value="${1}" # Sentence to log (in double quotes)
|
||||||
|
local level="${2}" # Log level
|
||||||
|
local retval="${3:-undef}" # optional return value of command
|
||||||
|
|
||||||
|
if [ "$_LOGGER_PREFIX" == "time" ]; then
|
||||||
|
prefix="TIME: $SECONDS - "
|
||||||
|
elif [ "$_LOGGER_PREFIX" == "date" ]; then
|
||||||
|
prefix="$(date) - "
|
||||||
|
else
|
||||||
|
prefix=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Obfuscate _REMOTE_TOKEN in logs (for ssh_filter usage only in osync and obackup)
|
||||||
|
value="${value/env _REMOTE_TOKEN=$_REMOTE_TOKEN/__(o_O)__}"
|
||||||
|
value="${value/env _REMOTE_TOKEN=\$_REMOTE_TOKEN/__(o_O)__}"
|
||||||
|
|
||||||
|
if [ "$level" == "CRITICAL" ]; then
|
||||||
|
_Logger "$prefix($level):$value" "$prefix\e[1;33;41m$value\e[0m" true
|
||||||
|
ERROR_ALERT=true
|
||||||
|
# ERROR_ALERT / WARN_ALERT is not set in main when Logger is called from a subprocess. Need to keep this flag.
|
||||||
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
||||||
|
return
|
||||||
|
elif [ "$level" == "ERROR" ]; then
|
||||||
|
_Logger "$prefix($level):$value" "$prefix\e[91m$value\e[0m" true
|
||||||
|
ERROR_ALERT=true
|
||||||
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
||||||
|
return
|
||||||
|
elif [ "$level" == "WARN" ]; then
|
||||||
|
_Logger "$prefix($level):$value" "$prefix\e[33m$value\e[0m" true
|
||||||
|
WARN_ALERT=true
|
||||||
|
echo -e "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$\n$prefix($level):$value" >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.warn.$SCRIPT_PID.$TSTAMP"
|
||||||
|
return
|
||||||
|
elif [ "$level" == "NOTICE" ]; then
|
||||||
|
if [ "$_LOGGER_ERR_ONLY" != true ]; then
|
||||||
|
_Logger "$prefix$value" "$prefix$value"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "VERBOSE" ]; then
|
||||||
|
if [ $_LOGGER_VERBOSE == true ]; then
|
||||||
|
_Logger "$prefix($level):$value" "$prefix$value"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
elif [ "$level" == "ALWAYS" ]; then
|
||||||
|
_Logger "$prefix$value" "$prefix$value"
|
||||||
|
return
|
||||||
|
elif [ "$level" == "DEBUG" ]; then
|
||||||
|
if [ "$_DEBUG" == "yes" ]; then
|
||||||
|
_Logger "$prefix$value" "$prefix$value"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
elif [ "$level" == "PARANOIA_DEBUG" ]; then #__WITH_PARANOIA_DEBUG
|
||||||
|
if [ "$_PARANOIA_DEBUG" == "yes" ]; then #__WITH_PARANOIA_DEBUG
|
||||||
|
_Logger "$prefix$value" "$prefix\e[35m$value\e[0m" #__WITH_PARANOIA_DEBUG
|
||||||
|
return #__WITH_PARANOIA_DEBUG
|
||||||
|
fi #__WITH_PARANOIA_DEBUG
|
||||||
|
elif [ "$level" == "SIMPLE" ]; then
|
||||||
|
if [ "$_LOGGER_SILENT" == true ]; then
|
||||||
|
_Logger "$preix$value"
|
||||||
|
else
|
||||||
|
_Logger "$preix$value" "$prefix$value"
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
else
|
||||||
|
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m" "\e[41mLogger function called without proper loglevel [$level].\e[0m" true
|
||||||
|
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
||||||
|
fi
|
||||||
|
}
|
||||||
## Modified version of https://gist.github.com/cdown/1163649
|
## Modified version of https://gist.github.com/cdown/1163649
|
||||||
function UrlEncode {
|
function UrlEncode {
|
||||||
local length="${#1}"
|
local length="${#1}"
|
||||||
@ -243,12 +426,12 @@ function SetLocalOSSettings {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "BusyBox" ]; then
|
if [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "BusyBox" ]; then
|
||||||
QuickLogger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly."
|
Logger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
|
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
|
||||||
QuickLogger "Must be run as $USER."
|
Logger "Must be run as $USER." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -256,14 +439,19 @@ function SetLocalOSSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GetInit {
|
function GetInit {
|
||||||
if [ -f /sbin/init ]; then
|
if [ -f /sbin/openrc-run ]; then
|
||||||
|
init="openrc"
|
||||||
|
Logger "Detected openrc." "SIMPLE"
|
||||||
|
elif [ -f /sbin/init ]; then
|
||||||
if file /sbin/init | grep systemd > /dev/null; then
|
if file /sbin/init | grep systemd > /dev/null; then
|
||||||
init="systemd"
|
init="systemd"
|
||||||
|
Logger "Detected systemd." "SIMPLE"
|
||||||
else
|
else
|
||||||
init="initV"
|
init="initV"
|
||||||
|
Logger "Detected initV." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
QuickLogger "Can't detect initV or systemd. Service files won't be installed. You can still run $PROGRAM manually or via cron."
|
Logger "Can't detect initV, systemd or openRC. Service files won't be installed. You can still run $PROGRAM manually or via cron." "SIMPLE"
|
||||||
init="none"
|
init="none"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -274,9 +462,9 @@ function CreateDir {
|
|||||||
if [ ! -d "$dir" ]; then
|
if [ ! -d "$dir" ]; then
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
QuickLogger "Created directory [$dir]."
|
Logger "Created directory [$dir]." "SIMPLE"
|
||||||
else
|
else
|
||||||
QuickLogger "Cannot create directory [$dir]."
|
Logger "Cannot create directory [$dir]." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -285,36 +473,39 @@ function CreateDir {
|
|||||||
function CopyFile {
|
function CopyFile {
|
||||||
local sourcePath="${1}"
|
local sourcePath="${1}"
|
||||||
local destPath="${2}"
|
local destPath="${2}"
|
||||||
local fileName="${3}"
|
local sourceFileName="${3}"
|
||||||
local fileMod="${4}"
|
local destFileName="${4}"
|
||||||
local fileUser="${5}"
|
local fileMod="${5}"
|
||||||
local fileGroup="${6}"
|
local fileUser="${6}"
|
||||||
local overwrite="${7:-false}"
|
local fileGroup="${7}"
|
||||||
|
local overwrite="${8:-false}"
|
||||||
|
|
||||||
local userGroup=""
|
local userGroup=""
|
||||||
local oldFileName
|
local oldFileName
|
||||||
|
|
||||||
if [ -f "$destPath/$fileName" ] && [ $overwrite == false ]; then
|
if [ "$destFileName" == "" ]; then
|
||||||
oldFileName="$fileName"
|
destFileName="$sourceFileName"
|
||||||
fileName="$oldFileName.new"
|
|
||||||
cp "$sourcePath/$oldFileName" "$destPath/$fileName"
|
|
||||||
else
|
|
||||||
cp "$sourcePath/$fileName" "$destPath"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
||||||
|
destfileName="$sourceFileName.new"
|
||||||
|
Logger "Copying [$sourceFileName] to [$destPath/$destFilename]." "SIMPLE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
QuickLogger "Cannot copy [$fileName] to [$destPath]. Make sure to run install script in the directory containing all other files."
|
Logger "Cannot copy [$sourcePath/$sourceFileName] to [$destPath/$destFileName]. Make sure to run install script in the directory containing all other files." "SIMPLE"
|
||||||
QuickLogger "Also make sure you have permissions to write to [$BIN_DIR]."
|
Logger "Also make sure you have permissions to write to [$BIN_DIR]." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
QuickLogger "Copied [$fileName] to [$destPath]."
|
Logger "Copied [$sourcePath/$sourceFileName] to [$destPath/$destFileName]." "SIMPLE"
|
||||||
if [ "$fileMod" != "" ]; then
|
if [ "$fileMod" != "" ]; then
|
||||||
chmod "$fileMod" "$destPath/$fileName"
|
chmod "$fileMod" "$destPath/$destFileName"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
QuickLogger "Cannot set file permissions of [$destPath/$fileName] to [$fileMod]."
|
Logger "Cannot set file permissions of [$destPath/$destFileName] to [$fileMod]." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
QuickLogger "Set file permissions to [$fileMod] on [$destPath/$fileName]."
|
Logger "Set file permissions to [$fileMod] on [$destPath/$destFileName]." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -325,12 +516,12 @@ function CopyFile {
|
|||||||
userGroup="$userGroup"":$fileGroup"
|
userGroup="$userGroup"":$fileGroup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chown "$userGroup" "$destPath/$fileName"
|
chown "$userGroup" "$destPath/$destFileName"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
QuickLogger "Could not set file ownership on [$destPath/$fileName] to [$userGroup]."
|
Logger "Could not set file ownership on [$destPath/$destFileName] to [$userGroup]." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
QuickLogger "Set file ownership on [$destPath/$fileName] to [$userGroup]."
|
Logger "Set file ownership on [$destPath/$destFileName] to [$userGroup]." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -346,7 +537,7 @@ function CopyExampleFiles {
|
|||||||
|
|
||||||
for file in "${exampleFiles[@]}"; do
|
for file in "${exampleFiles[@]}"; do
|
||||||
if [ -f "$SCRIPT_PATH/$file" ]; then
|
if [ -f "$SCRIPT_PATH/$file" ]; then
|
||||||
CopyFile "$SCRIPT_PATH" "$CONF_DIR" "$file" "" "" "" false
|
CopyFile "$SCRIPT_PATH" "$CONF_DIR" "$file" "$file" "" "" "" false
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -370,32 +561,37 @@ function CopyProgram {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for file in "${binFiles[@]}"; do
|
for file in "${binFiles[@]}"; do
|
||||||
CopyFile "$SCRIPT_PATH" "$BIN_DIR" "$file" 755 "$user" "$group" true
|
CopyFile "$SCRIPT_PATH" "$BIN_DIR" "$file" "$file" 755 "$user" "$group" true
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function CopyServiceFiles {
|
function CopyServiceFiles {
|
||||||
if ([ "$init" == "systemd" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
|
if ([ "$init" == "systemd" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
|
||||||
CreateDir "$SERVICE_DIR_SYSTEMD_SYSTEM"
|
CreateDir "$SERVICE_DIR_SYSTEMD_SYSTEM"
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM" "" "" "" true
|
||||||
if [ -f "$SCRIPT_PATH/$SERVICE_FILE_SYSTEMD_USER" ]; then
|
if [ -f "$SCRIPT_PATH/$SERVICE_FILE_SYSTEMD_USER" ]; then
|
||||||
CreateDir "$SERVICE_DIR_SYSTEMD_USER"
|
CreateDir "$SERVICE_DIR_SYSTEMD_USER"
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
||||||
fi
|
fi
|
||||||
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]." "SIMPLE"
|
||||||
QuickLogger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
|
Logger "Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR." "SIMPLE"
|
||||||
QuickLogger "Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR."
|
Logger "Can be enabled on boot with [systemctl enable $SERVICE_NAME@instance.conf]." "SIMPLE"
|
||||||
QuickLogger "Can be enabled on boot with [systemctl enable $SERVICE_NAME@instance.conf]."
|
Logger "In userland, active with [systemctl --user start $SERVICE_NAME@instance.conf]." "SIMPLE"
|
||||||
QuickLogger "In userland, active with [systemctl --user start $SERVICE_NAME@instance.conf]."
|
|
||||||
elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_INIT" ] && [ -d "$SERVICE_DIR_INIT" ]); then
|
elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_INIT" ] && [ -d "$SERVICE_DIR_INIT" ]); then
|
||||||
CreateDir "$SERVICE_DIR_INIT"
|
#CreateDir "$SERVICE_DIR_INIT"
|
||||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
|
|
||||||
QuickLogger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]."
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "SIMPLE"
|
||||||
QuickLogger "Can be activated with [service $SERVICE_FILE_INIT start]."
|
Logger "Can be activated with [service $SERVICE_FILE_INIT start]." "SIMPLE"
|
||||||
QuickLogger "Can be enabled on boot with [chkconfig $SERVICE_FILE_INIT on]."
|
Logger "Can be enabled on boot with [chkconfig $SERVICE_FILE_INIT on]." "SIMPLE"
|
||||||
|
elif ([ "$init" == "openrc" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_OPENRC" ] && [ -d "$SERVICE_DIR_OPENRC" ]); then
|
||||||
|
# Rename service to usual service file
|
||||||
|
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||||
|
|
||||||
|
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "SIMPLE"
|
||||||
|
Logger "Can be activated with [rc-update add $SERVICE_NAME.instance] where instance is a configuration file found in /etc/osync." "SIMPLE"
|
||||||
else
|
else
|
||||||
QuickLogger "Cannot define what init style is in use on this system. Skipping service file installation."
|
Logger "Cannot properly find how to deal with init on this system. Skipping service file installation." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +610,7 @@ function Statistics {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
QuickLogger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please."
|
Logger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." "SIMPLE"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,12 +620,12 @@ function RemoveFile {
|
|||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
rm -f "$file"
|
rm -f "$file"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
QuickLogger "Could not remove file [$file]."
|
Logger "Could not remove file [$file]." "SIMPLE"
|
||||||
else
|
else
|
||||||
QuickLogger "Removed file [$file]."
|
Logger "Removed file [$file]." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
QuickLogger "File [$file] not found. Skipping."
|
Logger "File [$file] not found. Skipping." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,13 +639,13 @@ function RemoveAll {
|
|||||||
if [ ! -f "$BIN_DIR/osync.sh" ] && [ ! -f "$BIN_DIR/obackup.sh" ]; then # Check if any other program requiring ssh filter is present before removal
|
if [ ! -f "$BIN_DIR/osync.sh" ] && [ ! -f "$BIN_DIR/obackup.sh" ]; then # Check if any other program requiring ssh filter is present before removal
|
||||||
RemoveFile "$BIN_DIR/$SSH_FILTER"
|
RemoveFile "$BIN_DIR/$SSH_FILTER"
|
||||||
else
|
else
|
||||||
QuickLogger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it."
|
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||||
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
||||||
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
||||||
|
|
||||||
QuickLogger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually."
|
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "SIMPLE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Usage {
|
function Usage {
|
||||||
@ -462,6 +658,26 @@ function Usage {
|
|||||||
exit 127
|
exit 127
|
||||||
}
|
}
|
||||||
|
|
||||||
|
############################## Script entry point
|
||||||
|
|
||||||
|
if [ "$LOGFILE" == "" ]; then
|
||||||
|
if [ -w /var/log ]; then
|
||||||
|
LOG_FILE="/var/log/$PROGRAM.$INSTANCE_ID.log"
|
||||||
|
elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then
|
||||||
|
LOG_FILE="$HOME/$PROGRAM.$INSTANCE_ID.log"
|
||||||
|
else
|
||||||
|
LOG_FILE="./$PROGRAM.$INSTANCE_ID.log"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
LOG_FILE="$LOGFILE"
|
||||||
|
fi
|
||||||
|
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
||||||
|
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
||||||
|
else
|
||||||
|
Logger "Script begin, logging to [$LOG_FILE]." "DEBUG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
GetLocalOS
|
GetLocalOS
|
||||||
SetLocalOSSettings
|
SetLocalOSSettings
|
||||||
GetInit
|
GetInit
|
||||||
@ -470,7 +686,7 @@ STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSI
|
|||||||
|
|
||||||
if [ "$ACTION" == "uninstall" ]; then
|
if [ "$ACTION" == "uninstall" ]; then
|
||||||
RemoveAll
|
RemoveAll
|
||||||
QuickLogger "$PROGRAM uninstalled."
|
Logger "$PROGRAM uninstalled." "SIMPLE"
|
||||||
else
|
else
|
||||||
CreateDir "$CONF_DIR"
|
CreateDir "$CONF_DIR"
|
||||||
CreateDir "$BIN_DIR"
|
CreateDir "$BIN_DIR"
|
||||||
@ -479,11 +695,11 @@ else
|
|||||||
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "pmocr" ]; then
|
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "pmocr" ]; then
|
||||||
CopyServiceFiles
|
CopyServiceFiles
|
||||||
fi
|
fi
|
||||||
QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
|
Logger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM" "SIMPLE"
|
||||||
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
|
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
|
||||||
QuickLogger ""
|
echo ""
|
||||||
QuickLogger "If connecting remotely, consider setup ssh filter to enhance security."
|
Logger "If connecting remotely, consider setup ssh filter to enhance security." "SIMPLE"
|
||||||
QuickLogger ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -491,7 +707,7 @@ if [ $_STATS -eq 1 ]; then
|
|||||||
if [ $_LOGGER_SILENT == true ]; then
|
if [ $_LOGGER_SILENT == true ]; then
|
||||||
Statistics
|
Statistics
|
||||||
else
|
else
|
||||||
QuickLogger "In order to make usage statistics, the script would like to connect to $STATS_LINK"
|
Logger "In order to make usage statistics, the script would like to connect to $STATS_LINK" "SIMPLE"
|
||||||
read -r -p "No data except those in the url will be send. Allow [Y/n] " response
|
read -r -p "No data except those in the url will be send. Allow [Y/n] " response
|
||||||
case $response in
|
case $response in
|
||||||
[nN])
|
[nN])
|
||||||
|
@ -7,7 +7,7 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(C) 2013-2017 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2017 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.1-beta5
|
PROGRAM_VERSION=2.1-beta5
|
||||||
PROGRAM_BUILD=2018083005
|
PROGRAM_BUILD=2018091201
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
|
|
||||||
@ -4016,7 +4016,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
@ -4052,7 +4052,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" false true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" false true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
@ -4087,7 +4087,7 @@ function FilesBackup {
|
|||||||
encryptDir="$FILE_STORAGE"
|
encryptDir="$FILE_STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
Logger "Beginning file backup of [$sourceDir] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user