[asterisk-commits] tzafrir: trunk r408059 - in /trunk: Makefile build_tools/install_subst

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 14 02:52:18 CST 2014


Author: tzafrir
Date: Fri Feb 14 02:52:07 2014
New Revision: 408059

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408059
Log:
install_subst: helper script for installing with path substitution

A helper script to copy a source file substituting any
__ASTERISK_<foo>_DIR__ with the content of $AST<foo>DIR.

Review: https://reviewboard.asterisk.org/r/3202/

Added:
    trunk/build_tools/install_subst   (with props)
Modified:
    trunk/Makefile

Modified: trunk/Makefile
URL: http://svnview.digium.com/svn/asterisk/trunk/Makefile?view=diff&rev=408059&r1=408058&r2=408059
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Fri Feb 14 02:52:07 2014
@@ -566,9 +566,7 @@
 	$(INSTALL) -m 755 contrib/scripts/astgenkey "$(DESTDIR)$(ASTSBINDIR)/"
 	$(INSTALL) -m 755 contrib/scripts/autosupport "$(DESTDIR)$(ASTSBINDIR)/"
 	if [ ! -f "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" -a ! -f /sbin/launchd ]; then \
-		cat contrib/scripts/safe_asterisk | sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;s|__ASTERISK_LOG_DIR__|$(ASTLOGDIR)|;' > contrib/scripts/safe.tmp ; \
-		$(INSTALL) -m 755 contrib/scripts/safe.tmp "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk" ; \
-		rm -f contrib/scripts/safe.tmp ; \
+		./build_tools/install_subst contrib/scripts/safe_asterisk "$(DESTDIR)$(ASTSBINDIR)/safe_asterisk"; \
 	fi
 	$(INSTALL) -m 644 include/asterisk.h "$(DESTDIR)$(includedir)"
 	$(INSTALL) -m 644 include/asterisk/*.h "$(DESTDIR)$(ASTHEADERDIR)"
@@ -784,9 +782,7 @@
 config:
 	@if [ "${OSARCH}" = "linux-gnu" ]; then \
 		if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
-			cat contrib/init.d/rc.redhat.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.redhat.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
 			if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \
 				$(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
 			fi ; \
@@ -794,9 +790,7 @@
 				/sbin/chkconfig --add asterisk ; \
 			fi ; \
 		elif [ -f /etc/debian_version ] ; then \
-			cat contrib/init.d/rc.debian.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.debian.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
 			if [ ! -f "$(DESTDIR)/etc/default/asterisk" ] ; then \
 				$(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/default/asterisk" ; \
 			fi ; \
@@ -804,16 +798,12 @@
 				/usr/sbin/update-rc.d asterisk defaults 50 91 ; \
 			fi ; \
 		elif [ -f /etc/gentoo-release ] ; then \
-			cat contrib/init.d/rc.gentoo.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ; \
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.gentoo.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
 			if [ -z "$(DESTDIR)" ] ; then \
 				/sbin/rc-update add asterisk default ; \
 			fi ; \
 		elif [ -f /etc/mandrake-release -o -f /etc/mandriva-release ] ; then \
-			cat contrib/init.d/rc.mandriva.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/init.d/asterisk" ; \
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.mandriva.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
 			if [ ! -f /etc/sysconfig/asterisk ] ; then \
 				$(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
 			fi ; \
@@ -821,9 +811,7 @@
 				/sbin/chkconfig --add asterisk ; \
 			fi ; \
 		elif [ -f /etc/SuSE-release -o -f /etc/novell-release ] ; then \
-			cat contrib/init.d/rc.suse.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/init.d/asterisk" ;\
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.suse.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
 			if [ ! -f /etc/sysconfig/asterisk ] ; then \
 				$(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \
 			fi ; \
@@ -831,19 +819,13 @@
 				/sbin/chkconfig --add asterisk ; \
 			fi ; \
 		elif [ -f /etc/arch-release -o -f /etc/arch-release ] ; then \
-			cat contrib/init.d/rc.archlinux.asterisk | sed 's|__ASTERISK_ETC_DIR__|$(ASTETCDIR)|;s|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;s|__ASTERISK_VARRUN_DIR__|$(ASTVARRUNDIR)|;' > contrib/init.d/rc.asterisk.tmp ; \
-			$(INSTALL) -m 755 contrib/init.d/rc.asterisk.tmp "$(DESTDIR)/etc/rc.d/asterisk" ; \
-			rm -f contrib/init.d/rc.asterisk.tmp ; \
+			./build_tools/install_subst contrib/init.d/rc.archlinux.asterisk  "$(DESTDIR)/etc/init.d/asterisk"; \
 		elif [ -d "$(DESTDIR)/Library/LaunchDaemons" ]; then \
 			if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist" ]; then \
-				sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.asterisk.plist > asterisk.plist ; \
-				$(INSTALL) -m 644 asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
-				rm -f asterisk.plist; \
+				./build_tools/install_subst contrib/init.d/org.asterisk.asterisk.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist"; \
 			fi; \
 			if [ ! -f "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist" ]; then \
-				sed 's|__ASTERISK_SBIN_DIR__|$(ASTSBINDIR)|;' < contrib/init.d/org.asterisk.muted.plist > muted.plist ; \
-				$(INSTALL) -m 644 muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
-				rm -f muted.plist; \
+				./build_tools/install_subst contrib/init.d/org.asterisk.muted.plist "$(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist"; \
 			fi; \
 		elif [ -f /etc/slackware-version ]; then \
 			echo "Slackware is not currently supported, although an init script does exist for it."; \

Added: trunk/build_tools/install_subst
URL: http://svnview.digium.com/svn/asterisk/trunk/build_tools/install_subst?view=auto&rev=408059
==============================================================================
--- trunk/build_tools/install_subst (added)
+++ trunk/build_tools/install_subst Fri Feb 14 02:52:07 2014
@@ -1,0 +1,43 @@
+#!/bin/sh
+
+# install_subst: install a script while doing path substitution
+
+# install_subst [-d] source destination
+#
+# -d: file is data (rather than script)
+
+install_args=
+if [ "$1" = '-d' ]; then
+	install_args="-m 644"
+	shift
+fi
+
+set -e
+
+tmp=`mktemp install_subst_XXXXXX`
+
+cleanup_tmp() {
+	rm -f "$tmp"
+}
+
+# Delete it on exit
+trap cleanup_tmp 0
+
+src="$1"
+dst="$2"
+sed <"$src" \
+	-e "s|__ASTERISK_DATA_DIR__|$ASTDATADIR|g" \
+	-e "s|__ASTERISK_DB_DIR__|$ASTDBDIR|g" \
+	-e "s|__ASTERISK_ETC_DIR__|$ASTETCDIR|g" \
+	-e "s|__ASTERISK_HEADER_DIR__|$ASTHEADERDIR|g" \
+	-e "s|__ASTERISK_LIB_DIR__|$ASTLIBDIR|g" \
+	-e "s|__ASTERISK_LOG_DIR__|$ASTLOGDIR|g" \
+	-e "s|__ASTERISK_MOD_DIR__|$ASTMODDIR|g" \
+	-e "s|__ASTERISK_MAN_DIR__|$ASTMANDIR|g" \
+	-e "s|__ASTERISK_SBIN_DIR__|$ASTSBINDIR|g" \
+	-e "s|__ASTERISK_SPOOL_DIR__|$ASTSPOOLDIR|g" \
+	-e "s|__ASTERISK_VARLIB_DIR__|$ASTVARLIBDIR|g" \
+	-e "s|__ASTERISK_VARRUN_DIR__|$ASTVARRUNDIR|g" \
+	> "$tmp"
+
+install $install_args "$tmp" "$dst"

Propchange: trunk/build_tools/install_subst
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/build_tools/install_subst
------------------------------------------------------------------------------
    svn:executable = *

Propchange: trunk/build_tools/install_subst
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/build_tools/install_subst
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list