From 757fa94239e67aed08ec8ada776415e08a18987a Mon Sep 17 00:00:00 2001
From: Niek Vlessert <niekvlessert@gmail.com>
Date: Tue, 20 Oct 2015 23:21:50 +0200
Subject: [PATCH] FS-8369 Debian8/CentOS7 systemd installer additions

After builing Freeswitch this makes actually run it easy by offering
an installer script.

* Changes to configure.ac to detect Debian8/CentOS 7 and create installer script
* Changes to build/Makefile.am to display the option
* Added build/startup directory with templates and other files
* Deleted outdated build/freeswitch.service and tmpfiles.conf
* Unit file based on the latest systemd service file FS-8194
* Won't interfere with other platforms (afaik)
* Supports all bindir directory prefixes ./configure can have
* Detects if Debian8/CentOS7 use systemd
* Can be used with a user with sudo permissions
---
 build/Makefile.am                             | 6 +++---
 {init => build/startup}/freeswitch.default    | 0
 {init => build/startup}/freeswitch.service.in | 0
 {init => build/startup}/freeswitch.tmpfile    | 0
 {init => build/startup}/install_systemd.sh.in | 8 ++++----
 configure.ac                                  | 7 ++++---
 6 files changed, 11 insertions(+), 10 deletions(-)
 rename {init => build/startup}/freeswitch.default (100%)
 rename {init => build/startup}/freeswitch.service.in (100%)
 rename {init => build/startup}/freeswitch.tmpfile (100%)
 rename {init => build/startup}/install_systemd.sh.in (91%)

diff --git a/build/Makefile.am b/build/Makefile.am
index 38202826da..dbda77330e 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -57,10 +57,10 @@ install:
 	@echo " +               $(MK) samples                     +"
 if KNOWN_INIT
 	@echo " +                                                 +"
-	@echo " +       Install init scripts:                     +"
-	@echo " +       ---------------------                     +"
+	@echo " +       Install startup scripts:                  +"
+	@echo " +       ------------------------                  +"
 	@echo " +                                                 +"
-	@echo " +       init/install_systemd.sh                   +"
+	@echo " +       build/startup/install_systemd.sh          +"
 endif
 	@echo " +                                                 +"
 	@echo " +                                                 +"
diff --git a/init/freeswitch.default b/build/startup/freeswitch.default
similarity index 100%
rename from init/freeswitch.default
rename to build/startup/freeswitch.default
diff --git a/init/freeswitch.service.in b/build/startup/freeswitch.service.in
similarity index 100%
rename from init/freeswitch.service.in
rename to build/startup/freeswitch.service.in
diff --git a/init/freeswitch.tmpfile b/build/startup/freeswitch.tmpfile
similarity index 100%
rename from init/freeswitch.tmpfile
rename to build/startup/freeswitch.tmpfile
diff --git a/init/install_systemd.sh.in b/build/startup/install_systemd.sh.in
similarity index 91%
rename from init/install_systemd.sh.in
rename to build/startup/install_systemd.sh.in
index 60253a141a..6fe5374a5c 100644
--- a/init/install_systemd.sh.in
+++ b/build/startup/install_systemd.sh.in
@@ -25,11 +25,11 @@ echo "- Create user freeswitch and add it to group freeswitch"
 FSPATH=@prefix@
 if [[ $FSPATH == *"freeswitch"* ]]
 then
-	echo "- Set permissions on @prefix@ and files in @bindir@"
+	echo "- Set permissions on @prefix@ and files in @bindir_expanded@"
 fi
 echo "- Install systemd unit file"
 echo "- Install /etc/@environmentfilelocation@/freeswitch"
-echo 
+echo
 read -p "Do you want to continue? (y/n) " -n 1 -r
 if [[ $REPLY =~ ^[yY]$ ]]
 then
@@ -45,7 +45,7 @@ then
 	then
 		$SUDO chown -R freeswitch:freeswitch @prefix@
 		$SUDO chmod -R ug=rwX,o= @prefix@
-		$SUDO chmod -R u=rwx,g=rx @bindir@/*
+		$SUDO chmod -R u=rwx,g=rx @bindir_expanded@/*
 	fi
 	$SUDO cp init/freeswitch.service /etc/systemd/system/
 	$SUDO cp init/freeswitch.tmpfile /etc/tmpfiles.d/freeswitch.conf
@@ -58,5 +58,5 @@ then
 	else
 		echo "Make sure your config files are in place in @confdir@, if they are you can start Freeswitch using 'systemctl start freeswitch'"
 	fi
-	echo "Then start fs_cli by running @bindir@/fs_cli"
+	echo "Then start fs_cli by running @bindir_expanded@/fs_cli"
 fi
diff --git a/configure.ac b/configure.ac
index df050a0001..a1d8010a39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,7 +83,7 @@ default_certsdir="$prefix/certs"
 default_fontsdir="$prefix/fonts"
 default_imagesdir="$prefix/images"
 
-bindir="$exec_prefix/bin"
+eval bindir_expanded="${bindir}"
 
 if test "${enable_fhs}" = "yes"; then
     eval full_datadir="${datadir}/freeswitch"
@@ -789,8 +789,9 @@ case "$host" in
 					AC_SUBST(DISTRO)
 					AC_SUBST(rundir)
 					AC_SUBST(environmentfilelocation)
-					AC_CONFIG_FILES([init/install_systemd.sh], [chmod +x init/install_systemd.sh])
-					AC_CONFIG_FILES([init/freeswitch.service])
+					AC_SUBST(bindir_expanded)
+					AC_CONFIG_FILES([build/startup/install_systemd.sh], [chmod +x build/startup/install_systemd.sh])
+					AC_CONFIG_FILES([build/startup/freeswitch.service])
 				fi
 				;;
 			*)