Rebuilt target

pull/93/head
deajan 7 years ago
parent 1444d44b6b
commit bb6e9e895c

@ -6,7 +6,9 @@ PROGRAM=osync
PROGRAM_VERSION=1.2-RC1+dev PROGRAM_VERSION=1.2-RC1+dev
PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh" PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016122701 SSH_FILTER="ssh_filter.sh"
SCRIPT_BUILD=2017020701
## 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
@ -22,19 +24,20 @@ SERVICE_DIR_INIT=$FAKEROOT/etc/init.d
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
## osync specific code if [ "$PROGRAM" == "osync" ]; then
OSYNC_SERVICE_FILE_INIT="osync-srv" SERVICE_NAME="osync-srv"
OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM="osync-srv@.service" elif [ "$PROGRAM" == "pmocr" ]; then
OSYNC_SERVICE_FILE_SYSTEMD_USER="osync-srv@.service.user" SERVICE_NAME="pmocr-srv"
fi
## pmocr specfic code SERVICE_FILE_INIT="$SERVICE_NAME"
PMOCR_SERVICE_FILE_INIT="pmocr-srv" SERVICE_FILE_SYSTEMD_SYSTEM="$SERVICE_NAME@.service"
PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM="pmocr-srv@.service" SERVICE_FILE_SYSTEMD_USER="$SERVICE_NAME@.service.user"
## Generic code ## Generic code
## Default log file ## Default log file
if [ -w $FAKEROOT/var/log ]; then if [ -w "$FAKEROOT/var/log" ]; then
LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log" LOG_FILE="$FAKEROOT/var/log/$PROGRAM-install.log"
elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then elif ([ "$HOME" != "" ] && [ -w "$HOME" ]); then
LOG_FILE="$HOME/$PROGRAM-install.log" LOG_FILE="$HOME/$PROGRAM-install.log"
@ -207,112 +210,110 @@ function CreateConfDir {
fi fi
} }
function CopyExampleFiles { function CopyFile {
if [ -f "$SCRIPT_PATH/sync.conf.example" ]; then local sourcePath="${1}"
cp "$SCRIPT_PATH/sync.conf.example" "$CONF_DIR/sync.conf.example" local destPath="${2}"
fi local fileName="${3}"
local fileMod="${4}"
if [ -f "$SCRIPT_PATH/host_backup.conf.example" ]; then local fileUser="${5}"
cp "$SCRIPT_PATH/host_backup.conf.example" "$CONF_DIR/host_backup.conf.example" local fileGroup="${6}"
fi
local userGroup=""
if [ -f "$SCRIPT_PATH/exlude.list.example" ]; then local oldFileName
cp "$SCRIPT_PATH/exclude.list.example" "$CONF_DIR/exclude.list.example"
fi if [ -f "$destPath/$fileName" ]; then
oldFileName="$fileName"
if [ -f "$SCRIPT_PATH/snapshot.conf.example" ]; then fileName="$oldFileName.new"
cp "$SCRIPT_PATH/snapshot.conf.example" "$CONF_DIR/snapshot.conf.example" cp "$sourcePath/$oldFileName" "$destPath/$fileName"
else
cp "$sourcePath/$fileName" "$destPath"
fi fi
if [ -f "$SCRIPT_PATH/default.conf" ]; then
if [ -f "$CONF_DIR/default.conf" ]; then
cp "$SCRIPT_PATH/default.conf" "$CONF_DIR/default.conf.new"
QuickLogger "Copied default.conf to [$CONF_DIR/default.conf.new]."
else
cp "$SCRIPT_PATH/default.conf" "$CONF_DIR/default.conf"
fi
fi
}
function CopyProgram {
cp "$SCRIPT_PATH/$PROGRAM_BINARY" "$BIN_DIR"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]. Make sure to run install script in the directory containing all other files." QuickLogger "Cannot copy [$fileName] to [$destPath]. Make sure to run install script in the directory containing all other files."
QuickLogger "Also make sure you have permissions to write to [$BIN_DIR]." QuickLogger "Also make sure you have permissions to write to [$BIN_DIR]."
exit 1 exit 1
else else
chmod 755 "$BIN_DIR/$PROGRAM_BINARY" QuickLogger "Copied [$fileName] to [$destPath]."
QuickLogger "Copied $PROGRAM_BINARY to [$BIN_DIR]." if [ "$fileMod" != "" ]; then
fi chmod "$fileMod" "$destPath/$fileName"
if [ $? != 0 ]; then
if [ -f "$SCRIPT_PATH/$PROGRAM_BATCH" ]; then QuickLogger "Cannot set file permissions of [$destPath/$fileName] to [$fileMod]."
cp "$SCRIPT_PATH/$PROGRAM_BATCH" "$BIN_DIR" exit 1
if [ $? != 0 ]; then else
QuickLogger "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]." QuickLogger "Set file permissions to [$fileMod] on [$destPath/$fileName]."
else fi
chmod 755 "$BIN_DIR/$PROGRAM_BATCH"
QuickLogger "Copied $PROGRAM_BATCH to [$BIN_DIR]."
fi fi
fi
if [ -f "$SCRIPT_PATH/ssh_filter.sh" ]; then if [ "$fileUser" != "" ]; then
cp "$SCRIPT_PATH/ssh_filter.sh" "$BIN_DIR" userGroup="$fileUser"
if [ $? != 0 ]; then
QuickLogger "Cannot copy ssh_filter.sh to [$BIN_DIR]." if [ "$fileGroup" != "" ]; then
else userGroup="$userGroup"":$fileGroup"
chmod 755 "$BIN_DIR/ssh_filter.sh" fi
if ([ "$USER" != "" ] && [ "$GROUP" != "" ] && [ "$FAKEROOT" == "" ]); then
chown $USER:$GROUP "$BIN_DIR/ssh_filter.sh" chown "$userGroup" "$destPath/$fileName"
if [ $? != 0 ]; then
QuickLogger "Could not set file ownership on [$destPath/$fileName] to [$userGroup]."
exit 1
else
QuickLogger "Set file ownership on [$destPath/$fileName] to [$userGroup]."
fi fi
QuickLogger "Copied ssh_filter.sh to [$BIN_DIR]."
fi fi
fi fi
} }
function CopyServiceFiles { function CopyExampleFiles {
# OSYNC SPECIFIC exampleFiles=()
if ([ "$init" == "systemd" ] && [ -f "$SCRIPT_PATH/$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then exampleFiles[0]="sync.conf.example" # osync
cp "$SCRIPT_PATH/$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM" && cp "$SCRIPT_PATH/$OSYNC_SERVICE_FILE_SYSTEMD_USER" "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_SYSTEM" exampleFiles[1]="host_backup.conf.example" # obackup
if [ $? != 0 ]; then exampleFiles[2]="exclude.list.example" # osync & obackup
QuickLogger "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]." exampleFiles[3]="snapshot.conf.example" # zsnap
else exampleFiles[4]="default.conf" # pmocr
QuickLogger "Created osync-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
QuickLogger "Can be activated with [systemctl start osync-srv@instance.conf] where instance.conf is the name of the config file in $CONF_DIR." for file in "${exampleFiles[@]}"; do
QuickLogger "Can be enabled on boot with [systemctl enable osync-srv@instance.conf]." if [ -f "$SCRIPT_PATH/$file" ]; then
QuickLogger "In userland, active with [systemctl --user start osync-srv@instance.conf]." CopyFile "$SCRIPT_PATH" "$CONF_DIR" "$file"
fi
elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$OSYNC_SERVICE_FILE_INIT" ]); then
cp "$SCRIPT_PATH/$OSYNC_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT"
if [ $? != 0 ]; then
QuickLogger "Cannot copy osync-srv to [$SERVICE_DIR_INIT]."
else
chmod 755 "$SERVICE_DIR_INIT/$OSYNC_SERVICE_FILE_INIT"
QuickLogger "Created osync-srv service in [$SERVICE_DIR_INIT]."
QuickLogger "Can be activated with [service $OSYNC_SERVICE_FILE_INIT start]."
QuickLogger "Can be enabled on boot with [chkconfig $OSYNC_SERVICE_FILE_INIT on]."
fi fi
done
}
function CopyProgram {
binFiles=()
binFiles[0]="$PROGRAM_BINARY"
binFiles[1]="$PROGRAM_BATCH"
binFiles[2]="$SSH_FILTER"
local user=""
local group=""
if ([ "$USER" != "" ] && [ "$FAKEROOT" == "" ]); then
user="$USER"
fi
if ([ "$GROUP" != "" ] && [ "$FAKEROOT" == "" ]); then
group="$GROUP"
fi fi
# PMOCR SPECIFIC for file in "${binFiles[@]}"; do
if ([ "$init" == "systemd" ] && [ -f "$SCRIPT_PATH/$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then CopyFile "$SCRIPT_PATH" "$BIN_DIR" "$file" 755 "$user" "$group"
cp "$SCRIPT_PATH/$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM" done
if [ $? != 0 ]; then }
QuickLogger "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
else function CopyServiceFiles {
QuickLogger "Created pmocr-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]." if ([ "$init" == "systemd" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
QuickLogger "Can be activated with [systemctl start pmocr-srv@default.conf] where default.conf is the name of the config file in $CONF_DIR." CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_FILE_SYSTEMD_SYSTEM"
QuickLogger "Can be enabled on boot with [systemctl enable pmocr-srv@default.conf]." CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER"
fi
elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$PMOCR_SERVICE_FILE_INIT" ]); then QuickLogger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
cp "$SCRIPT_PATH/$PMOCR_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT" QuickLogger "Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR."
if [ $? != 0 ]; then QuickLogger "Can be enabled on boot with [systemctl enable $SERVICE_NAME@instance.conf]."
QuickLogger "Cannot copy pmoct-srv to [$SERVICE_DIR_INIT]." QuickLogger "In userland, active with [systemctl --user start $SERVICE_NAME@instance.conf]."
else elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_INIT" ]); then
chmod 755 "$SERVICE_DIR_INIT/$PMOCR_SERVICE_FILE_INIT" CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "755"
QuickLogger "Created osync-srv service in [$SERVICE_DIR_INIT]."
QuickLogger "Can be activated with [service $PMOCR_SERVICE_FILE_INIT start]." QuickLogger "Created osync-srv service in [$SERVICE_DIR_INIT]."
QuickLogger "Can be enabled on boot with [chkconfig $PMOCR_SERVICE_FILE_INIT on]." QuickLogger "Can be activated with [service $OSYNC_SERVICE_FILE_INIT start]."
fi QuickLogger "Can be enabled on boot with [chkconfig $OSYNC_SERVICE_FILE_INIT on]."
fi fi
} }
@ -335,6 +336,32 @@ function Statistics {
return 1 return 1
} }
function RemoveFile {
local file="${1}"
if [ -f "$file" ]; then
rm -f "$file"
if [ $? != 0 ]; then
QuickLogger "Could not remove file [$file]."
else
QuickLogger "Removed file [$file]."
fi
else
QuickLogger "File [$file] not found. Skipping."
fi
}
function RemoveAll {
RemoveFile "$BIN_DIR/$PROGRAM_BINARY"
RemoveFile "$BIN_DIR/$PROGRAM_BATCH"
RemoveFile "$BIN_DIR/$SSH_FILTER"
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_SYSTEM"
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
QuickLogger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually."
}
function Usage { function Usage {
echo "Installs $PROGRAM into $BIN_DIR" echo "Installs $PROGRAM into $BIN_DIR"
echo "options:" echo "options:"
@ -345,6 +372,8 @@ function Usage {
_LOGGER_SILENT=false _LOGGER_SILENT=false
_STATS=1 _STATS=1
ACTION="install"
for i in "$@" for i in "$@"
do do
case $i in case $i in
@ -354,6 +383,9 @@ do
--no-stats) --no-stats)
_STATS=0 _STATS=0
;; ;;
--remove)
ACTION="uninstall"
;;
--help|-h|-?) --help|-h|-?)
Usage Usage
esac esac
@ -365,21 +397,27 @@ fi
GetLocalOS GetLocalOS
SetLocalOSSettings SetLocalOSSettings
CreateConfDir
CopyExampleFiles
CopyProgram
GetInit GetInit
CopyServiceFiles
STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS" STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$OS&action=$ACTION"
if [ "$ACTION" == "uninstall" ]; then
RemoveAll
QuickLogger "$PROGRAM uninstalled."
else
CreateConfDir
CopyExampleFiles
CopyProgram
CopyServiceFiles
QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
fi
QuickLogger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
if [ $_STATS -eq 1 ]; then if [ $_STATS -eq 1 ]; then
if [ $_LOGGER_SILENT == true ]; 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 usage statistics, the script would like to connect to $STATS_LINK"
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])
exit exit

Loading…
Cancel
Save