2016-08-07 22:16:38 +00:00
#!/usr/bin/env bash
2017-03-14 20:12:38 +00:00
## Installer script suitable for osync / obackup / pmocr
2017-03-14 21:35:39 +00:00
PROGRAM = [ prgname]
2017-03-14 20:12:38 +00:00
PROGRAM_VERSION = $( grep "PROGRAM_VERSION=" $PROGRAM .sh)
PROGRAM_VERSION = ${ PROGRAM_VERSION #*= }
2016-08-07 22:16:38 +00:00
PROGRAM_BINARY = $PROGRAM ".sh"
PROGRAM_BATCH = $PROGRAM "-batch.sh"
2017-02-07 15:00:23 +00:00
SSH_FILTER = "ssh_filter.sh"
2020-04-29 10:44:17 +00:00
SCRIPT_BUILD = 2020042901
2018-10-01 18:43:27 +00:00
INSTANCE_ID = " installer- $SCRIPT_BUILD "
2016-08-07 22:16:38 +00:00
## osync / obackup / pmocr / zsnap install script
2016-12-11 21:58:31 +00:00
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8, 10 and 11
2016-08-07 22:16:38 +00:00
## Please adapt this to fit your distro needs
2018-10-02 16:09:21 +00:00
include #### OFUNCTIONS MICRO SUBSET ####
2018-10-01 18:43:27 +00:00
2016-11-11 23:07:38 +00:00
# Get current install.sh path from http://stackoverflow.com/a/246128/2635443
SCRIPT_PATH = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2017-07-27 21:15:35 +00:00
_LOGGER_SILENT = false
_STATS = 1
ACTION = "install"
FAKEROOT = ""
2016-08-07 22:16:38 +00:00
## Default log file
2017-02-07 15:00:23 +00:00
if [ -w " $FAKEROOT /var/log " ] ; then
2016-12-11 19:54:40 +00:00
LOG_FILE = " $FAKEROOT /var/log/ $PROGRAM -install.log "
2016-08-07 22:16:38 +00:00
elif ( [ " $HOME " != "" ] && [ -w " $HOME " ] ) ; then
2016-12-11 19:54:40 +00:00
LOG_FILE = " $HOME / $PROGRAM -install.log "
2016-08-07 22:16:38 +00:00
else
2016-12-11 19:54:40 +00:00
LOG_FILE = " ./ $PROGRAM -install.log "
2016-08-07 22:16:38 +00:00
fi
2016-12-11 21:40:27 +00:00
include #### UrlEncode SUBSET ####
include #### GetLocalOS SUBSET ####
2017-02-07 21:04:50 +00:00
include #### GetConfFileValue SUBSET ####
2020-03-15 21:31:07 +00:00
include #### CleanUp SUBSET ####
2020-03-15 21:50:56 +00:00
include #### GenericTrapQuit SUBSET ####
2017-02-07 21:04:50 +00:00
2016-12-11 21:40:27 +00:00
function SetLocalOSSettings {
2016-11-24 13:27:04 +00:00
USER = root
2020-01-28 02:33:50 +00:00
DO_INIT = true
2016-08-07 22:16:38 +00:00
2016-12-28 22:37:07 +00:00
# LOCAL_OS and LOCAL_OS_FULL are global variables set at GetLocalOS
2016-12-11 21:40:27 +00:00
case $LOCAL_OS in
2016-08-07 22:16:38 +00:00
*"BSD" *)
GROUP = wheel
; ;
2016-12-11 21:40:27 +00:00
*"MacOSX" *)
2016-08-07 22:16:38 +00:00
GROUP = admin
2020-01-28 02:33:50 +00:00
DO_INIT = false
2016-08-07 22:16:38 +00:00
; ;
2020-04-29 10:44:17 +00:00
*"Cygwin" *| *"Android" *| *"msys" *| *"BusyBox" *)
2016-08-07 22:16:38 +00:00
USER = ""
GROUP = ""
2020-04-29 10:44:17 +00:00
DO_INIT = false
2016-08-07 22:16:38 +00:00
; ;
2016-08-29 15:53:11 +00:00
*)
GROUP = root
; ;
2016-08-07 22:16:38 +00:00
esac
2017-02-08 14:01:41 +00:00
if [ " $LOCAL_OS " = = "Android" ] || [ " $LOCAL_OS " = = "BusyBox" ] ; then
2019-02-26 11:07:35 +00:00
Logger " Cannot be installed on [ $LOCAL_OS ]. Please use $PROGRAM .sh directly. " "CRITICAL"
2016-12-11 21:40:27 +00:00
exit 1
fi
2016-08-28 19:15:19 +00:00
if ( [ " $USER " != "" ] && [ " $( whoami) " != " $USER " ] && [ " $FAKEROOT " = = "" ] ) ; then
2019-02-26 11:07:35 +00:00
Logger " Must be run as $USER . " "CRITICAL"
2016-08-07 22:16:38 +00:00
exit 1
fi
2016-12-28 22:37:07 +00:00
OS = $( UrlEncode " $LOCAL_OS_FULL " )
2016-08-07 22:16:38 +00:00
}
function GetInit {
2018-06-25 22:21:00 +00:00
if [ -f /sbin/openrc-run ] ; then
init = "openrc"
2019-02-26 11:07:35 +00:00
Logger "Detected openrc." "NOTICE"
2018-06-25 22:21:00 +00:00
elif [ -f /sbin/init ] ; then
2016-08-07 22:16:38 +00:00
if file /sbin/init | grep systemd > /dev/null; then
init = "systemd"
2019-02-26 11:07:35 +00:00
Logger "Detected systemd." "NOTICE"
2016-08-07 22:16:38 +00:00
else
init = "initV"
2019-02-26 11:07:35 +00:00
Logger "Detected initV." "NOTICE"
2016-08-07 22:16:38 +00:00
fi
else
2019-02-26 11:07:35 +00:00
Logger " Can't detect initV, systemd or openRC. Service files won't be installed. You can still run $PROGRAM manually or via cron. " "WARN"
2016-08-07 22:16:38 +00:00
init = "none"
fi
}
2017-02-07 22:39:20 +00:00
function CreateDir {
local dir = " ${ 1 } "
2018-10-02 21:20:26 +00:00
local dirMask = " ${ 2 } "
2018-10-02 20:36:30 +00:00
local dirUser = " ${ 3 } "
local dirGroup = " ${ 4 } "
2017-02-07 22:39:20 +00:00
if [ ! -d " $dir " ] ; then
2018-10-02 21:20:26 +00:00
(
if [ $( IsInteger $dirMask ) -eq 1 ] ; then
umask $dirMask
fi
2017-07-27 21:15:35 +00:00
mkdir -p " $dir "
2018-10-02 21:20:26 +00:00
)
2016-08-07 22:16:38 +00:00
if [ $? = = 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Created directory [ $dir ]. " "NOTICE"
2016-08-07 22:16:38 +00:00
else
2019-02-26 11:07:35 +00:00
Logger " Cannot create directory [ $dir ]. " "CRITICAL"
2016-08-07 22:16:38 +00:00
exit 1
fi
fi
2018-10-02 20:36:30 +00:00
2018-10-02 21:06:33 +00:00
if [ " $dirUser " != "" ] ; then
2018-10-02 20:36:30 +00:00
userGroup = " $dirUser "
2018-10-02 21:06:33 +00:00
if [ " $dirGroup " != "" ] ; then
2018-10-02 20:36:30 +00:00
userGroup = " $userGroup " " : $dirGroup "
fi
2018-10-02 21:06:33 +00:00
chown " $userGroup " " $dir "
2018-10-02 20:36:30 +00:00
if [ $? != 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Could not set directory ownership on [ $dir ] to [ $userGroup ]. " "CRITICAL"
2018-10-02 20:36:30 +00:00
exit 1
else
2019-02-26 11:07:35 +00:00
Logger " Set file ownership on [ $dir ] to [ $userGroup ]. " "NOTICE"
2018-10-02 20:36:30 +00:00
fi
fi
2016-08-07 22:16:38 +00:00
}
2017-02-07 15:00:23 +00:00
function CopyFile {
local sourcePath = " ${ 1 } "
local destPath = " ${ 2 } "
2018-06-25 22:21:00 +00:00
local sourceFileName = " ${ 3 } "
local destFileName = " ${ 4 } "
local fileMod = " ${ 5 } "
local fileUser = " ${ 6 } "
local fileGroup = " ${ 7 } "
local overwrite = " ${ 8 :- false } "
2017-02-07 15:00:23 +00:00
local userGroup = ""
2018-06-25 22:21:00 +00:00
if [ " $destFileName " = = "" ] ; then
destFileName = " $sourceFileName "
fi
if [ -f " $destPath / $destFileName " ] && [ $overwrite = = false ] ; then
2019-05-22 18:33:49 +00:00
destFileName = " $sourceFileName .new "
Logger " Copying [ $sourceFileName ] to [ $destPath / $destFileName ]. " "NOTICE"
2016-08-07 22:16:38 +00:00
fi
2018-06-25 22:21:00 +00:00
cp " $sourcePath / $sourceFileName " " $destPath / $destFileName "
2016-08-07 22:16:38 +00:00
if [ $? != 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Cannot copy [ $sourcePath / $sourceFileName ] to [ $destPath / $destFileName ]. Make sure to run install script in the directory containing all other files. " "CRITICAL"
Logger " Also make sure you have permissions to write to [ $BIN_DIR ]. " "ERROR"
2016-08-07 22:16:38 +00:00
exit 1
else
2019-02-26 11:07:35 +00:00
Logger " Copied [ $sourcePath / $sourceFileName ] to [ $destPath / $destFileName ]. " "NOTICE"
2018-10-02 21:06:33 +00:00
if [ " $( IsInteger $fileMod ) " -eq 1 ] ; then
2018-06-25 22:21:00 +00:00
chmod " $fileMod " " $destPath / $destFileName "
2017-02-07 15:00:23 +00:00
if [ $? != 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Cannot set file permissions of [ $destPath / $destFileName ] to [ $fileMod ]. " "CRITICAL"
2017-02-07 15:00:23 +00:00
exit 1
else
2019-02-26 11:07:35 +00:00
Logger " Set file permissions to [ $fileMod ] on [ $destPath / $destFileName ]. " "NOTICE"
2017-02-07 15:00:23 +00:00
fi
2018-10-02 20:36:30 +00:00
elif [ " $fileMod " != "" ] ; then
2019-02-26 11:07:35 +00:00
Logger " Bogus filemod [ $fileMod ] for [ $destPath ] given. " "WARN"
2016-08-07 22:16:38 +00:00
fi
2017-02-07 15:00:23 +00:00
if [ " $fileUser " != "" ] ; then
userGroup = " $fileUser "
if [ " $fileGroup " != "" ] ; then
userGroup = " $userGroup " " : $fileGroup "
fi
2018-06-25 22:21:00 +00:00
chown " $userGroup " " $destPath / $destFileName "
2017-02-07 15:00:23 +00:00
if [ $? != 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Could not set file ownership on [ $destPath / $destFileName ] to [ $userGroup ]. " "CRITICAL"
2017-02-07 15:00:23 +00:00
exit 1
else
2019-02-26 11:07:35 +00:00
Logger " Set file ownership on [ $destPath / $destFileName ] to [ $userGroup ]. " "NOTICE"
2016-08-07 22:16:38 +00:00
fi
fi
fi
}
2017-02-07 15:00:23 +00:00
function CopyExampleFiles {
exampleFiles = ( )
exampleFiles[ 0] = "sync.conf.example" # osync
exampleFiles[ 1] = "host_backup.conf.example" # obackup
exampleFiles[ 2] = "exclude.list.example" # osync & obackup
exampleFiles[ 3] = "snapshot.conf.example" # zsnap
exampleFiles[ 4] = "default.conf" # pmocr
for file in " ${ exampleFiles [@] } " ; do
if [ -f " $SCRIPT_PATH / $file " ] ; then
2018-06-25 22:21:00 +00:00
CopyFile " $SCRIPT_PATH " " $CONF_DIR " " $file " " $file " "" "" "" false
2016-08-07 22:16:38 +00:00
fi
2017-02-07 15:00:23 +00:00
done
}
function CopyProgram {
binFiles = ( )
binFiles[ 0] = " $PROGRAM_BINARY "
2017-03-13 10:46:44 +00:00
if [ " $PROGRAM " = = "osync" ] || [ " $PROGRAM " = = "obackup" ] ; then
binFiles[ 1] = " $PROGRAM_BATCH "
binFiles[ 2] = " $SSH_FILTER "
fi
2017-02-07 15:00:23 +00:00
local user = ""
local group = ""
if ( [ " $USER " != "" ] && [ " $FAKEROOT " = = "" ] ) ; then
user = " $USER "
fi
if ( [ " $GROUP " != "" ] && [ " $FAKEROOT " = = "" ] ) ; then
group = " $GROUP "
2016-08-07 22:16:38 +00:00
fi
2017-02-07 15:00:23 +00:00
for file in " ${ binFiles [@] } " ; do
2018-06-25 22:21:00 +00:00
CopyFile " $SCRIPT_PATH " " $BIN_DIR " " $file " " $file " 755 " $user " " $group " true
2017-02-07 15:00:23 +00:00
done
}
function CopyServiceFiles {
if ( [ " $init " = = "systemd" ] && [ -f " $SCRIPT_PATH / $SERVICE_FILE_SYSTEMD_SYSTEM " ] ) ; then
2017-07-27 21:15:35 +00:00
CreateDir " $SERVICE_DIR_SYSTEMD_SYSTEM "
2018-06-25 22:21:00 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_SYSTEMD_SYSTEM " " $SERVICE_FILE_SYSTEMD_SYSTEM " " $SERVICE_FILE_SYSTEMD_SYSTEM " "" "" "" true
2017-07-27 21:15:35 +00:00
if [ -f " $SCRIPT_PATH / $SERVICE_FILE_SYSTEMD_USER " ] ; then
CreateDir " $SERVICE_DIR_SYSTEMD_USER "
2018-06-25 22:21:00 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_SYSTEMD_USER " " $SERVICE_FILE_SYSTEMD_USER " " $SERVICE_FILE_SYSTEMD_USER " "" "" "" true
2017-03-14 21:41:39 +00:00
fi
2019-05-20 12:55:59 +00:00
if [ -f " $SCRIPT_PATH / $TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM " ] ; then
2020-01-10 10:15:52 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_SYSTEMD_SYSTEM " " $TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM " " $TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM " "" "" "" true
2019-05-20 12:55:59 +00:00
Logger " Created optional service [ $TARGET_HELPER_SERVICE_NAME ] with same specifications as below. " "NOTICE"
fi
if [ -f " $SCRIPT_PATH / $TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER " ] ; then
2020-01-10 10:15:52 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_SYSTEMD_USER " " $TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER " " $TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER " "" "" "" true
2019-05-20 12:55:59 +00:00
fi
2019-02-26 11:07:35 +00:00
Logger " Created [ $SERVICE_NAME ] service in [ $SERVICE_DIR_SYSTEMD_SYSTEM ] and [ $SERVICE_DIR_SYSTEMD_USER ]. " "NOTICE"
Logger " Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR . " "NOTICE"
Logger " Can be enabled on boot with [systemctl enable $SERVICE_NAME @instance.conf]. " "NOTICE"
Logger " In userland, active with [systemctl --user start $SERVICE_NAME @instance.conf]. " "NOTICE"
2017-02-07 21:10:24 +00:00
elif ( [ " $init " = = "initV" ] && [ -f " $SCRIPT_PATH / $SERVICE_FILE_INIT " ] && [ -d " $SERVICE_DIR_INIT " ] ) ; then
2018-06-25 22:21:00 +00:00
#CreateDir "$SERVICE_DIR_INIT"
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_INIT " " $SERVICE_FILE_INIT " " $SERVICE_FILE_INIT " "755" "" "" true
2019-05-20 12:55:59 +00:00
if [ -f " $SCRIPT_PATH / $TARGET_HELPER_SERVICE_FILE_INIT " ] ; then
2020-01-10 10:15:52 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_INIT " " $TARGET_HELPER_SERVICE_FILE_INIT " " $TARGET_HELPER_SERVICE_FILE_INIT " "755" "" "" true
2019-05-20 12:55:59 +00:00
Logger " Created optional service [ $TARGET_HELPER_SERVICE_NAME ] with same specifications as below. " "NOTICE"
fi
2019-02-26 11:07:35 +00:00
Logger " Created [ $SERVICE_NAME ] service in [ $SERVICE_DIR_INIT ]. " "NOTICE"
Logger " Can be activated with [service $SERVICE_FILE_INIT start]. " "NOTICE"
Logger " Can be enabled on boot with [chkconfig $SERVICE_FILE_INIT on]. " "NOTICE"
2018-07-02 07:58:25 +00:00
elif ( [ " $init " = = "openrc" ] && [ -f " $SCRIPT_PATH / $SERVICE_FILE_OPENRC " ] && [ -d " $SERVICE_DIR_OPENRC " ] ) ; then
2018-06-25 22:21:00 +00:00
# Rename service to usual service file
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_OPENRC " " $SERVICE_FILE_OPENRC " " $SERVICE_FILE_INIT " "755" "" "" true
2019-05-20 12:55:59 +00:00
if [ -f " $SCRPT_PATH / $TARGET_HELPER_SERVICE_FILE_OPENRC " ] ; then
2020-01-10 10:15:52 +00:00
CopyFile " $SCRIPT_PATH " " $SERVICE_DIR_OPENRC " " $TARGET_HELPER_SERVICE_FILE_OPENRC " " $TARGET_HELPER_SERVICE_FILE_OPENRC " "755" "" "" true
2019-05-20 12:55:59 +00:00
Logger " Created optional service [ $TARGET_HELPER_SERVICE_NAME ] with same specifications as below. " "NOTICE"
fi
2019-02-26 11:07:35 +00:00
Logger " Created [ $SERVICE_NAME ] service in [ $SERVICE_DIR_OPENRC ]. " "NOTICE"
Logger " Can be activated with [rc-update add $SERVICE_NAME .instance] where instance is a configuration file found in /etc/osync. " "NOTICE"
2017-02-07 21:10:24 +00:00
else
2019-02-26 11:07:35 +00:00
Logger "Cannot properly find how to deal with init on this system. Skipping service file installation." "NOTICE"
2016-08-07 22:16:38 +00:00
fi
}
function Statistics {
2016-12-11 19:54:40 +00:00
if type wget > /dev/null; then
wget -qO- " $STATS_LINK " > /dev/null 2>& 1
if [ $? = = 0 ] ; then
return 0
fi
2016-08-07 22:16:38 +00:00
fi
2016-12-11 19:54:40 +00:00
if type curl > /dev/null; then
curl " $STATS_LINK " -o /dev/null > /dev/null 2>& 1
if [ $? = = 0 ] ; then
return 0
fi
2016-08-07 22:16:38 +00:00
fi
2019-02-26 11:07:35 +00:00
Logger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." "WARN"
2016-12-11 19:54:40 +00:00
return 1
2016-08-07 22:16:38 +00:00
}
2017-02-07 15:00:23 +00:00
function RemoveFile {
local file = " ${ 1 } "
if [ -f " $file " ] ; then
rm -f " $file "
if [ $? != 0 ] ; then
2019-02-26 11:07:35 +00:00
Logger " Could not remove file [ $file ]. " "ERROR"
2017-02-07 15:00:23 +00:00
else
2019-02-26 11:07:35 +00:00
Logger " Removed file [ $file ]. " "NOTICE"
2017-02-07 15:00:23 +00:00
fi
else
2019-02-26 11:07:35 +00:00
Logger " File [ $file ] not found. Skipping. " "NOTICE"
2017-02-07 15:00:23 +00:00
fi
}
function RemoveAll {
RemoveFile " $BIN_DIR / $PROGRAM_BINARY "
2017-04-11 11:25:36 +00:00
if [ " $PROGRAM " = = "osync" ] || [ " $PROGRAM " = = "obackup" ] ; then
RemoveFile " $BIN_DIR / $PROGRAM_BATCH "
fi
2017-02-10 10:43:05 +00:00
if [ ! -f " $BIN_DIR /osync.sh " ] && [ ! -f " $BIN_DIR /obackup.sh " ] ; then # Check if any other program requiring ssh filter is present before removal
2017-02-10 10:28:43 +00:00
RemoveFile " $BIN_DIR / $SSH_FILTER "
else
2019-02-26 11:07:35 +00:00
Logger " Skipping removal of [ $BIN_DIR / $SSH_FILTER ] because other programs present that need it. " "NOTICE"
2017-02-10 10:28:43 +00:00
fi
2017-02-07 15:00:23 +00:00
RemoveFile " $SERVICE_DIR_SYSTEMD_SYSTEM / $SERVICE_FILE_SYSTEMD_SYSTEM "
2017-07-27 21:15:35 +00:00
RemoveFile " $SERVICE_DIR_SYSTEMD_USER / $SERVICE_FILE_SYSTEMD_USER "
2017-02-07 15:00:23 +00:00
RemoveFile " $SERVICE_DIR_INIT / $SERVICE_FILE_INIT "
2020-01-10 10:15:52 +00:00
RemoveFile " $TARGET_HELPER_SERVICE_DIR_SYSTEMD_SYSTEM / $SERVICE_FILE_SYSTEMD_SYSTEM "
RemoveFile " $TARGET_HELPER_SERVICE_DIR_SYSTEMD_USER / $SERVICE_FILE_SYSTEMD_USER "
RemoveFile " $TARGET_HELPER_SERVICE_DIR_INIT / $SERVICE_FILE_INIT "
2019-02-26 11:07:35 +00:00
Logger " Skipping configuration files in [ $CONF_DIR ]. You may remove this directory manually. " "NOTICE"
2017-02-07 15:00:23 +00:00
}
2016-08-07 22:16:38 +00:00
function Usage {
echo " Installs $PROGRAM into $BIN_DIR "
echo "options:"
echo "--silent Will log and bypass user interaction."
echo "--no-stats Used with --silent in order to refuse sending anonymous install stats."
2017-03-21 21:48:44 +00:00
echo "--remove Remove the program."
2017-07-27 21:16:51 +00:00
echo "--prefix=/path Use prefix to install path."
2016-08-07 22:16:38 +00:00
exit 127
}
2018-10-01 18:43:27 +00:00
############################## Script entry point
2020-01-22 17:39:34 +00:00
function GetCommandlineArguments {
for i in " $@ " ; do
case $i in
--prefix= *)
FAKEROOT = " ${ i ##*= } "
; ;
--silent)
_LOGGER_SILENT = true
; ;
--no-stats)
_STATS = 0
; ;
--remove)
ACTION = "uninstall"
; ;
--help| -h| -?)
Usage
; ;
*)
Logger " Unknown option ' $i ' " "ERROR"
Usage
exit
; ;
esac
done
}
GetCommandlineArguments " $@ "
CONF_DIR = $FAKEROOT /etc/$PROGRAM
BIN_DIR = " $FAKEROOT /usr/local/bin "
SERVICE_DIR_INIT = $FAKEROOT /etc/init.d
# 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_USER = $FAKEROOT /etc/systemd/user
SERVICE_DIR_OPENRC = $FAKEROOT /etc/init.d
if [ " $PROGRAM " = = "osync" ] ; then
SERVICE_NAME = "osync-srv"
TARGET_HELPER_SERVICE_NAME = "osync-target-helper-srv"
TARGET_HELPER_SERVICE_FILE_INIT = " $TARGET_HELPER_SERVICE_NAME "
TARGET_HELPER_SERVICE_FILE_SYSTEMD_SYSTEM = " $TARGET_HELPER_SERVICE_NAME @.service "
TARGET_HELPER_SERVICE_FILE_SYSTEMD_USER = " $TARGET_HELPER_SERVICE_NAME @.service.user "
TARGET_HELPER_SERVICE_FILE_OPENRC = " $TARGET_HELPER_SERVICE_NAME -openrc "
elif [ " $PROGRAM " = = "pmocr" ] ; then
SERVICE_NAME = "pmocr-srv"
fi
SERVICE_FILE_INIT = " $SERVICE_NAME "
SERVICE_FILE_SYSTEMD_SYSTEM = " $SERVICE_NAME @.service "
SERVICE_FILE_SYSTEMD_USER = " $SERVICE_NAME @.service.user "
SERVICE_FILE_OPENRC = " $SERVICE_NAME -openrc "
## Generic code
2020-03-15 21:50:56 +00:00
trap GenericTrapQuit TERM EXIT HUP QUIT
2018-10-01 18:49:53 +00:00
2018-10-01 18:43:27 +00:00
if [ ! -w " $( dirname $LOG_FILE ) " ] ; then
echo " Cannot write to log [ $( dirname $LOG_FILE ) ]. "
else
Logger " Script begin, logging to [ $LOG_FILE ]. " "DEBUG"
fi
2018-10-02 21:20:26 +00:00
# Set default umask
umask 0022
2018-10-01 18:43:27 +00:00
2016-12-11 21:40:27 +00:00
GetLocalOS
SetLocalOSSettings
2020-01-28 02:33:50 +00:00
# On Mac OS this always produces a warning which causes the installer to fail with exit code 2
# Since we know it won't work anyway, and that's fine, just skip this step
if $DO_INIT ; then
GetInit
fi
2016-08-07 22:16:38 +00:00
2017-02-07 15:00:23 +00:00
STATS_LINK = " http://instcount.netpower.fr?program= $PROGRAM &version= $PROGRAM_VERSION &os= $OS &action= $ACTION "
if [ " $ACTION " = = "uninstall" ] ; then
RemoveAll
2019-02-26 11:07:35 +00:00
Logger " $PROGRAM uninstalled. " "NOTICE"
2017-02-07 15:00:23 +00:00
else
2017-02-07 22:39:20 +00:00
CreateDir " $CONF_DIR "
2018-10-02 21:20:26 +00:00
CreateDir " $BIN_DIR "
2017-02-07 15:00:23 +00:00
CopyExampleFiles
CopyProgram
2017-04-17 18:28:22 +00:00
if [ " $PROGRAM " = = "osync" ] || [ " $PROGRAM " = = "pmocr" ] ; then
CopyServiceFiles
fi
2019-02-26 11:07:35 +00:00
Logger " $PROGRAM installed. Use with $BIN_DIR / $PROGRAM_BINARY " "NOTICE"
2017-02-08 12:51:41 +00:00
if [ " $PROGRAM " = = "osync" ] || [ " $PROGRAM " = = "obackup" ] ; then
2018-06-25 12:12:05 +00:00
echo ""
2019-02-26 11:07:35 +00:00
Logger "If connecting remotely, consider setup ssh filter to enhance security." "NOTICE"
2018-06-25 12:12:05 +00:00
echo ""
2017-02-08 12:51:41 +00:00
fi
2017-02-07 15:00:23 +00:00
fi
2016-08-07 22:16:38 +00:00
if [ $_STATS -eq 1 ] ; then
2016-12-13 19:52:09 +00:00
if [ $_LOGGER_SILENT = = true ] ; then
2016-08-07 22:16:38 +00:00
Statistics
else
2019-02-26 11:07:35 +00:00
Logger " In order to make usage statistics, the script would like to connect to $STATS_LINK " "NOTICE"
2017-02-07 15:00:23 +00:00
read -r -p "No data except those in the url will be send. Allow [Y/n] " response
2016-08-07 22:16:38 +00:00
case $response in
[ nN] )
exit
; ;
*)
Statistics
exit $?
; ;
esac
fi
fi