diff --git a/dev/merge.sh b/dev/merge.sh index 31075c3..42948ad 100755 --- a/dev/merge.sh +++ b/dev/merge.sh @@ -3,6 +3,8 @@ ## Merges ofunctions.sh and $PROGRAM PROGRAM=osync +VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh) +VERSION=${VERSION#*=} FUNC_PATH=/home/git/common PARANOIA_DEBUG_LINE="#__WITH_PARANOIA_DEBUG" @@ -36,7 +38,8 @@ function CleanDebug { } function CopyCommons { - sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_install.sh > ../install.sh + sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_install.sh > ../tmp_install.sh + sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_batch.sh > ../$PROGRAM-batch.sh chmod +x ../install.sh chmod +x ../$PROGRAM-batch.sh @@ -46,4 +49,5 @@ Unexpand Merge CleanDebug rm -f tmp_$PROGRAM.sh +rm -f tmp_install.sh CopyCommons diff --git a/install.sh b/install.sh index 86b9c55..f420447 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash PROGRAM=osync +PROGRAM_VERSION=1.1-dev PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BATCH=$PROGRAM"-batch.sh" -SCRIPT_BUILD=2016031401 +SCRIPT_BUILD=2016032502 ## osync / obackup daemon install script ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10 @@ -13,8 +14,27 @@ CONF_DIR=/etc/$PROGRAM BIN_DIR=/usr/local/bin SERVICE_DIR=/etc/init.d -if [ "$(whoami)" != "root" ]; then - echo "Must be run as root." +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 + ;; + *) + GROUP=root + ;; +esac + +if [ "$(whoami)" != "$USER" ]; then + echo "Must be run as $USER." exit 1 fi @@ -42,23 +62,37 @@ if [ -f "./exlude.list.example" ]; then cp "./exclude.list.example" "/etc/$PROGRAM" fi +if [ -f "./snapshot.conf" ]; then + cp "./snapshot.conf" "/etc/$PROGRAM/snapshot.conf.example" +fi + cp "./$PROGRAM_BINARY" "$BIN_DIR" if [ $? != 0 ]; then echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]." else + chmod 755 "$BIN_DIR/$PROGRAM_BINARY" echo "Copied $PROGRAM_BINARY to [$BIN_DIR]." fi -cp "./$PROGRAM_BATCH" "/usr/local/bin" -if [ $? != 0 ]; then - echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]." -else - echo "Copied $PROGRAM_BATCH to [$BIN_DIR]." + +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 fi -cp "./ssh_filter.sh" "/usr/local/bin" -if [ $? != 0 ]; then - echo "Cannot copy ssh_filter.sh to [$BIN_DIR]." -else - echo "Copied ssh_filter.sh to [$BIN_DIR]." + +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" + chown $USER:$GROUP "$BIN_DIR/ssh_filter.sh" + echo "Copied ssh_filter.sh to [$BIN_DIR]." + fi fi if [ -f "./osync-srv" ]; then @@ -66,12 +100,41 @@ if [ -f "./osync-srv" ]; then if [ $? != 0 ]; then echo "Cannot copy osync-srv to [$SERVICE_DIR]." else + chmod 755 "$SERVICE_DIR/osync-srv" echo "Created osync-srv service in [$SERVICE_DIR]." - chmod 755 "/etc/init.d/osync-srv" fi fi -chmod 755 "/usr/local/bin/$PROGRAM_BINARY" -chmod 755 "/usr/local/bin/$PROGRAM_BATCH" -chmod 755 "/usr/local/bin/ssh_filter.sh" -chown root:root "/usr/local/bin/ssh_filter.sh" +function Statistics { + + local link="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSION" + if type wget > /dev/null; then + wget $link > /dev/null 2>&1 + if [ $? == 0 ]; then + exit 0 + fi + fi + + if type curl > /dev/null; then + curl $link > /dev/null 2>&1 + if [ $? == 0 ]; then + exit 0 + fi + fi + + echo "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." + exit +} + +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 + ;; +esac