2
0
mirror of https://github.com/deajan/osync synced 2024-11-19 03:25:37 +00:00
osync/install.sh

212 lines
6.2 KiB
Bash
Raw Normal View History

2014-05-26 22:50:46 +00:00
#!/usr/bin/env bash
2015-11-12 00:37:43 +00:00
PROGRAM=osync
2016-05-25 18:10:08 +00:00
PROGRAM_VERSION=1.1-RC1
2015-11-12 00:37:43 +00:00
PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh"
2016-05-24 22:36:00 +00:00
SCRIPT_BUILD=2016052501
2014-05-21 17:12:19 +00:00
2016-04-06 18:14:41 +00:00
## osync / obackup / pmocr / zsnap install script
2016-03-14 20:51:29 +00:00
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10
2014-05-21 17:12:19 +00:00
## Please adapt this to fit your distro needs
2015-11-12 00:37:43 +00:00
CONF_DIR=/etc/$PROGRAM
2015-09-28 12:43:42 +00:00
BIN_DIR=/usr/local/bin
SERVICE_DIR_INIT=/etc/init.d
2016-05-24 22:36:00 +00:00
# Should be /usr/lib/systemd/system, but /lib/systemd/system exists on debian & rhel / fedora
SERVICE_DIR_SYSTEMD_SYSTEM=/lib/systemd/system
2016-04-06 18:14:41 +00:00
SERVICE_DIR_SYSTEMD_USER=/etc/systemd/user
## osync specific code
OSYNC_SERVICE_FILE_INIT="osync-srv"
OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM="osync-srv@.service"
OSYNC_SERVICE_FILE_SYSTEMD_USER="osync-srv@.service.user"
2016-04-08 19:10:54 +00:00
## pmocr specfic code
PMOCR_SERVICE_FILE_INIT="pmocr-srv"
PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM="pmocr-srv.service"
2016-04-06 18:14:41 +00:00
## Generic code
2015-09-28 12:43:42 +00:00
2016-03-25 22:08:48 +00:00
USER=root
local_os_var="$(uname -spio 2>&1)"
if [ $? != 0 ]; then
local_os_var="$(uname -v 2>&1)"
if [ $? != 0 ]; then
local_os_var="$(uname)"
fi
fi
case $local_os_var in
*"BSD"*)
GROUP=wheel
;;
*"Darwin"*)
GROUP=admin
;;
2016-03-25 22:08:48 +00:00
*)
GROUP=root
;;
2016-04-08 19:10:54 +00:00
*"MINGW32"*|*"CYGWIN"*)
USER=""
GROUP=""
;;
2016-03-25 22:08:48 +00:00
esac
2016-04-08 19:10:54 +00:00
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ]); then
2016-03-25 22:08:48 +00:00
echo "Must be run as $USER."
2015-07-02 14:44:05 +00:00
exit 1
fi
if [ -f /sbin/init ]; then
if file /sbin/init | grep systemd > /dev/null; then
2016-05-25 15:35:25 +00:00
init="systemd"
else
2016-05-25 15:35:25 +00:00
init="initV"
fi
else
2016-05-25 15:35:25 +00:00
echo "Can't detect initV or systemd. Service files won't be installed. You can still run $PROGRAM manually or via cron."
init=none
fi
2015-11-12 00:37:43 +00:00
if [ ! -d "$CONF_DIR" ]; then
mkdir "$CONF_DIR"
2015-09-28 12:43:42 +00:00
if [ $? == 0 ]; then
2015-11-12 00:37:43 +00:00
echo "Created directory [$CONF_DIR]."
else
echo "Cannot create directory [$CONF_DIR]."
exit 1
2015-09-28 12:43:42 +00:00
fi
else
2015-11-12 00:37:43 +00:00
echo "Config directory [$CONF_DIR] exists."
2015-09-08 10:37:37 +00:00
fi
2016-04-14 16:01:56 +00:00
if [ -f "./sync.conf.example" ]; then
cp "./sync.conf.example" "/etc/$PROGRAM/sync.conf.example"
2015-11-12 00:37:43 +00:00
fi
2016-04-14 16:01:56 +00:00
if [ -f "./host_backup.conf.example" ]; then
cp "./host_backup.conf.example" "/etc/$PROGRAM/host_backup.conf.example"
2015-11-12 00:37:43 +00:00
fi
2016-03-14 20:51:29 +00:00
if [ -f "./exlude.list.example" ]; then
cp "./exclude.list.example" "/etc/$PROGRAM"
2015-11-12 00:37:43 +00:00
fi
2016-04-14 16:01:56 +00:00
if [ -f "./snapshot.conf.example" ]; then
cp "./snapshot.conf.example" "/etc/$PROGRAM/snapshot.conf.example"
2016-03-25 22:08:48 +00:00
fi
2016-03-14 20:51:29 +00:00
cp "./$PROGRAM_BINARY" "$BIN_DIR"
2015-09-28 12:43:42 +00:00
if [ $? != 0 ]; then
2015-11-12 00:37:43 +00:00
echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]."
2015-09-28 12:43:42 +00:00
else
2016-03-25 22:08:48 +00:00
chmod 755 "$BIN_DIR/$PROGRAM_BINARY"
2015-11-12 00:37:43 +00:00
echo "Copied $PROGRAM_BINARY to [$BIN_DIR]."
2015-09-28 12:43:42 +00:00
fi
2016-03-25 22:08:48 +00:00
if [ -f "./$PROGRAM_BATCH" ]; then
cp "./$PROGRAM_BATCH" "$BIN_DIR"
if [ $? != 0 ]; then
echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]."
else
chmod 755 "$BIN_DIR/$PROGRAM_BATCH"
echo "Copied $PROGRAM_BATCH to [$BIN_DIR]."
fi
2015-09-28 12:43:42 +00:00
fi
2016-03-25 22:08:48 +00:00
if [ -f "./ssh_filter.sh" ]; then
cp "./ssh_filter.sh" "$BIN_DIR"
if [ $? != 0 ]; then
echo "Cannot copy ssh_filter.sh to [$BIN_DIR]."
else
chmod 755 "$BIN_DIR/ssh_filter.sh"
2016-04-08 19:10:54 +00:00
if ([ "$USER" != "" ] && [ "$GROUP" != "" ]); then
chown $USER:$GROUP "$BIN_DIR/ssh_filter.sh"
fi
2016-03-25 22:08:48 +00:00
echo "Copied ssh_filter.sh to [$BIN_DIR]."
fi
2015-09-28 12:43:42 +00:00
fi
2015-11-12 00:37:43 +00:00
2016-05-25 15:35:25 +00:00
2016-04-08 19:10:54 +00:00
# OSYNC SPECIFIC
if ([ "$init" == "systemd" ] && [ -f "./$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
cp "./$OSYNC_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM" && cp "./$OSYNC_SERVICE_FILE_SYSTEMD_USER" "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_SYSTEM"
if [ $? != 0 ]; then
echo "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
else
echo "Created osync-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
echo "Can be activated with [systemctl start osync-srv@instance.conf] where instance.conf is the name of the config file in /etc/osync."
echo "Can be enabled on boot with [systemctl enable osync-srv@instance.conf]."
echo "In userland, active with [systemctl --user start osync-srv@instance.conf]."
fi
2016-05-25 15:35:25 +00:00
elif ( "$init" == "initV" ] && [ -f "./$OSYNC_SERVICE_FILE_INIT" ]); then
2016-04-08 19:10:54 +00:00
cp "./$OSYNC_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT"
if [ $? != 0 ]; then
echo "Cannot copy osync-srv to [$SERVICE_DIR_INIT]."
else
chmod 755 "$SERVICE_DIR_INIT/$OSYNC_SERVICE_FILE_INIT"
echo "Created osync-srv service in [$SERVICE_DIR_INIT]."
echo "Can be activated with [service $OSYNC_SERVICE_FILE_INIT start]."
echo "Can be enabled on boot with [chkconfig $OSYNC_SERVICE_FILE_INIT on]."
fi
fi
# PMOCR SPECIFIC
if ([ "$init" == "systemd" ] && [ -f "./$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" ]); then
cp "./$PMOCR_SERVICE_FILE_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_SYSTEM"
if [ $? != 0 ]; then
echo "Cannot copy the systemd file to [$SERVICE_DIR_SYSTEMD_SYSTEM] or [$SERVICE_DIR_SYSTEMD_USER]."
else
echo "Created pmocr-srv service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]."
echo "Can be activated with [systemctl start pmocr-srv] after configuring file options in [$BIN_DIR/$PROGRAM]."
echo "Can be enabled on boot with [systemctl enable pmocr-srv]."
fi
2016-05-25 15:35:25 +00:00
elif ([ "$init" == "initV" ] && [ -f "./$PMOCR_SERVICE_FILE_INIT" ]); then
2016-04-08 19:10:54 +00:00
cp "./$PMOCR_SERVICE_FILE_INIT" "$SERVICE_DIR_INIT"
if [ $? != 0 ]; then
echo "Cannot copy pmoct-srv to [$SERVICE_DIR_INIT]."
else
chmod 755 "$SERVICE_DIR_INIT/$PMOCR_SERVICE_FILE_INIT"
echo "Created osync-srv service in [$SERVICE_DIR_INIT]."
echo "Can be activated with [service $PMOCR_SERVICE_FILE_INIT start]."
echo "Can be enabled on boot with [chkconfig $PMOCR_SERVICE_FILE_INIT on]."
2015-11-12 00:37:43 +00:00
fi
2015-09-28 12:43:42 +00:00
fi
2015-11-12 00:37:43 +00:00
2016-03-25 22:08:48 +00:00
function Statistics {
local link="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION&os=$local_os_var"
2016-04-06 18:14:41 +00:00
if type wget > /dev/null; then
wget -qO- $link > /dev/null 2>&1
2016-03-25 22:08:48 +00:00
if [ $? == 0 ]; then
2016-04-08 19:10:54 +00:00
return 0
2016-03-25 22:08:48 +00:00
fi
fi
if type curl > /dev/null; then
2016-04-08 19:11:38 +00:00
curl -o /dev/null $link > /dev/null 2>&1
2016-03-25 22:08:48 +00:00
if [ $? == 0 ]; then
2016-04-08 19:10:54 +00:00
return 0
2016-03-25 22:08:48 +00:00
fi
fi
echo "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please."
2016-04-08 19:10:54 +00:00
retun 1
2016-03-25 22:08:48 +00:00
}
echo "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM"
echo ""
echo "In order to make install statistics, the script would like to connect to http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION"
read -r -p "No data except those in the url will be send. Allow [Y/n]" response
case $response in
[nN])
exit
;;
*)
Statistics
2016-04-08 19:10:54 +00:00
exit $?
2016-03-25 22:08:48 +00:00
;;
esac