Rebuilt targets for v2.1beta1

This commit is contained in:
deajan 2017-01-04 09:00:47 +01:00
parent 4e0bbbcd88
commit 2d2530c55d
4 changed files with 3228 additions and 1402 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
_OFUNCTIONS_BOOTSTRAP=true
PROGRAM=obackup PROGRAM=obackup
PROGRAM_VERSION=2.1-dev PROGRAM_VERSION=2.1-beta1
PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh" PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016112401 SCRIPT_BUILD=2016122701
## 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 ## 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
#TODO: silent mode and no stats mode
# 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 )"
@ -42,7 +42,7 @@ else
LOG_FILE="./$PROGRAM-install.log" LOG_FILE="./$PROGRAM-install.log"
fi fi
# Generic quick logging function # QuickLogger subfunction, can be called directly
function _QuickLogger { function _QuickLogger {
local value="${1}" local value="${1}"
local destination="${2}" # Destination: stdout, log, both local destination="${2}" # Destination: stdout, log, both
@ -54,35 +54,36 @@ function _QuickLogger {
fi fi
} }
# Generic quick logging function
function QuickLogger { function QuickLogger {
local value="${1}" local value="${1}"
if [ "$_SILENT" -eq 1 ]; then if [ "$_LOGGER_SILENT" == true ]; then
_QuickLogger "$value" "log" _QuickLogger "$value" "log"
else else
_QuickLogger "$value" "stdout" _QuickLogger "$value" "stdout"
fi fi
} }
## from https://gist.github.com/cdown/1163649
function urlencode() { function UrlEncode {
# urlencode <string> local length="${#1}"
local LANG=C local LANG=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do for (( i = 0; i < length; i++ )); do
local c="${1:i:1}" local c="${1:i:1}"
case $c in case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;; [a-zA-Z0-9.~_-])
*) printf '%%%02X' "'$c" ;; printf "$c"
;;
*)
printf '%%%02X' "'$c"
;;
esac esac
done done
} }
function GetLocalOS {
function SetOSSettings {
local localOsVar local localOsVar
USER=root
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way. # There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then
localOsVar="BusyBox" localOsVar="BusyBox"
@ -91,7 +92,7 @@ function SetOSSettings {
if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then
localOsVar="Microsoft" localOsVar="Microsoft"
else else
localOsVar="$(uname -spio 2>&1)" localOsVar="$(uname -spior 2>&1)"
if [ $? != 0 ]; then if [ $? != 0 ]; then
localOsVar="$(uname -v 2>&1)" localOsVar="$(uname -v 2>&1)"
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -102,13 +103,62 @@ function SetOSSettings {
fi fi
case $localOsVar in case $localOsVar in
# Android uname contains both linux and android, keep it before linux entry
*"Android"*)
LOCAL_OS="Android"
;;
*"Linux"*)
LOCAL_OS="Linux"
;;
*"BSD"*)
LOCAL_OS="BSD"
;;
*"MINGW32"*|*"MSYS"*)
LOCAL_OS="msys"
;;
*"CYGWIN"*)
LOCAL_OS="Cygwin"
;;
*"Microsoft"*)
LOCAL_OS="WinNT10"
;;
*"Darwin"*)
LOCAL_OS="MacOSX"
;;
*"BusyBox"*)
LOCAL_OS="BusyBox"
;;
*)
if [ "$IGNORE_OS_TYPE" == "yes" ]; then
Logger "Running on unknown local OS [$localOsVar]." "WARN"
return
fi
if [ "$_OFUNCTIONS_VERSION" != "" ]; then
Logger "Running on >> $localOsVar << not supported. Please report to the author." "ERROR"
fi
exit 1
;;
esac
if [ "$_OFUNCTIONS_VERSION" != "" ]; then
Logger "Local OS: [$localOsVar]." "DEBUG"
fi
# Add a global variable for statistics in installer
LOCAL_OS_FULL="$localOsVar"
}
function SetLocalOSSettings {
USER=root
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
case $LOCAL_OS in
*"BSD"*) *"BSD"*)
GROUP=wheel GROUP=wheel
;; ;;
*"Darwin"*) *"MacOSX"*)
GROUP=admin GROUP=admin
;; ;;
*"MINGW"*|*"CYGWIN"*) *"msys"*|*"Cygwin"*)
USER="" USER=""
GROUP="" GROUP=""
;; ;;
@ -117,12 +167,17 @@ function SetOSSettings {
;; ;;
esac esac
if [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BusyBox" ]; then
QuickLogger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly."
exit 1
fi
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
QuickLogger "Must be run as $USER." QuickLogger "Must be run as $USER."
exit 1 exit 1
fi fi
OS=$(urlencode "$localOsVar") OS=$(UrlEncode "$LOCAL_OS_FULL")
} }
function GetInit { function GetInit {
@ -288,13 +343,13 @@ function Usage {
exit 127 exit 127
} }
_SILENT=0 _LOGGER_SILENT=false
_STATS=1 _STATS=1
for i in "$@" for i in "$@"
do do
case $i in case $i in
--silent) --silent)
_SILENT=1 _LOGGER_SILENT=true
;; ;;
--no-stats) --no-stats)
_STATS=0 _STATS=0
@ -308,7 +363,8 @@ if [ "$FAKEROOT" != "" ]; then
mkdir -p "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_USER" "$BIN_DIR" mkdir -p "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_USER" "$BIN_DIR"
fi fi
SetOSSettings GetLocalOS
SetLocalOSSettings
CreateConfDir CreateConfDir
CopyExampleFiles CopyExampleFiles
CopyProgram CopyProgram
@ -319,7 +375,7 @@ STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSI
QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM" QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
if [ $_STATS -eq 1 ]; then if [ $_STATS -eq 1 ]; then
if [ $_SILENT -eq 1 ]; then if [ $_LOGGER_SILENT == true ]; then
Statistics Statistics
else else
QuickLogger "In order to make install statistics, the script would like to connect to $STATS_LINK" QuickLogger "In order to make install statistics, the script would like to connect to $STATS_LINK"

View File

@ -3,7 +3,7 @@ SUBPROGRAM=obackup
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
AUTHOR="(L) 2013-2016 by Orsiris de Jong" AUTHOR="(L) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr - ozy@netpower.fr" CONTACT="http://www.netpower.fr - ozy@netpower.fr"
PROGRAM_BUILD=2016112402 PROGRAM_BUILD=2016120401
## Runs an osync /obackup instance for every conf file found ## Runs an osync /obackup instance for every conf file found
## If an instance fails, run it again if time permits ## If an instance fails, run it again if time permits
@ -66,6 +66,7 @@ function CheckEnvironment {
SUBPROGRAM_EXECUTABLE=/usr/local/bin/$SUBPROGRAM.sh SUBPROGRAM_EXECUTABLE=/usr/local/bin/$SUBPROGRAM.sh
else else
Logger "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" "CRITICAL" Logger "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" "CRITICAL"
( >&2 echo "Could not find [/usr/local/bin/$SUBPROGRAM.sh]" )
exit 1 exit 1
fi fi
else else
@ -78,62 +79,49 @@ function CheckEnvironment {
} }
function Batch { function Batch {
local runs=0 # Number of batch runs local runs=1 # Number of batch runs
local runList # Actual conf file list to run local runList # Actual conf file list to run
local runAgainList # List of failed conf files sto run again local runAgainList # List of failed conf files sto run again
local confFile local confFile
local result local result
## Check for CONF_FILE_PATH local i
if [ -d "$CONF_FILE_PATH" ]; then
## Get list of .conf files
for confFile in $CONF_FILE_PATH/*.conf
do
if [ -f "$confFile" ]; then
if [ "$runList" == "" ]; then
runList="$confFile"
else
runList=$runList" $confFile"
fi
fi
done
elif [ -f "$CONF_FILE_PATH" ] && [ "${CONF_FILE_PATH##*.}" == "conf" ]; then
runList="$CONF_FILE_PATH"
fi
if [ "$runList" == "" ]; then # Using -e because find will accept directories or files
if [ ! -e "$CONF_FILE_PATH" ]; then
Logger "Cannot find conf file path [$CONF_FILE_PATH]." "CRITICAL" Logger "Cannot find conf file path [$CONF_FILE_PATH]." "CRITICAL"
Usage Usage
fi else
# Ugly hack to read files into an array while preserving special characters
runList=()
while IFS= read -d $'\0' -r file; do runList+=("$file"); done < <(find "$CONF_FILE_PATH" -maxdepth 1 -iname "*.conf" -print0)
while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "$runList" != "" ] && [ $MAX_RUNS -gt $runs ] while ([ $MAX_EXECUTION_TIME -gt $SECONDS ] || [ $MAX_EXECUTION_TIME -eq 0 ]) && [ "${#runList[@]}" -gt 0 ] && [ $runs -le $MAX_RUNS ]; do
do runAgainList=()
Logger "$SUBPROGRAM instances will be run for: $runList" "NOTICE" Logger "Sequential run n°$runs of $SUBPROGRAM instances for:" "NOTICE"
for confFile in $runList for confFile in "${runList[@]}"; do
do Logger "$(basename $confFile)" "NOTICE"
done
for confFile in "${runList[@]}"; do
$SUBPROGRAM_EXECUTABLE "$confFile" --silent $opts & $SUBPROGRAM_EXECUTABLE "$confFile" --silent $opts &
wait $! wait $!
result=$? result=$?
if [ $result != 0 ]; then if [ $result != 0 ]; then
if [ $result == 1 ] || [ $result == 128 ]; then # Do not handle exit code 127 because it is already handled here if [ $result == 1 ] || [ $result == 128 ]; then # Do not handle exit code 128 because it is already handled here
Logger "Run instance $(basename $confFile) failed with exit code [$result]." "ERROR" Logger "Instance $(basename $confFile) failed with exit code [$result]." "ERROR"
if [ "$runAgainList" == "" ]; then runAgainList+=("$confFile")
runAgainList="$confFile"
else
runAgainList=$runAgainList" $confFile"
fi
elif [ $result == 2 ]; then elif [ $result == 2 ]; then
Logger "Run instance $(basename $confFile) finished with warnings." "WARN" Logger "Instance $(basename $confFile) finished with warnings." "WARN"
fi fi
else else
Logger "Run instance $(basename $confFile) succeed." "NOTICE" Logger "Instance $(basename $confFile) succeed." "NOTICE"
fi fi
done done
runList="$runAgainList" runList=("${runAgainList[@]}")
runAgainList=""
runs=$(($runs + 1)) runs=$(($runs + 1))
done done
fi
} }
function Usage { function Usage {
@ -174,7 +162,7 @@ do
Usage Usage
;; ;;
*) *)
opts="$i " opts="$opts$i "
;; ;;
esac esac
done done

1879
obackup.sh

File diff suppressed because it is too large Load Diff