diff mbox series

[OpenWrt-Devel] build: do not deref symlinks when INSTALL_XX

Message ID 20190615151248.87950-1-yszhou4tech@gmail.com
State Changes Requested, archived
Headers show
Series [OpenWrt-Devel] build: do not deref symlinks when INSTALL_XX | expand

Commit Message

Yousong Zhou June 15, 2019, 3:12 p.m. UTC
This intends to serve as a guard against future use of the following
that may lead to multiple copies of the same binary be packaged and
installed to the target system

	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libyy.so.* $(1)

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
If this got accepted, pull requests like openwrt/packages#9233 will no
longer be necessary

 include/shell.sh | 29 +++++++++++++++++++++++++++++
 rules.mk         |  8 ++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/include/shell.sh b/include/shell.sh
index 6ee0cf6030..fe72056099 100644
--- a/include/shell.sh
+++ b/include/shell.sh
@@ -13,3 +13,32 @@  isset() {
 	eval "var=\"\${$1}\""
 	[ -n "$var" ]
 }
+
+install() {
+	local arg
+	local dest
+	local args=()
+	local symlinks=()
+	local n=0
+
+	for arg in "$@"; do
+		if [ "${arg#-}" = "$arg" ]; then
+			dest="$arg"
+			if [ -h "$arg" ]; then
+				symlinks+=("$arg")
+			else
+				args+=("$arg")
+				n=$((n+1))
+			fi
+		else
+			args+=("$arg")
+		fi
+	done
+
+	if [ "$n" -ge 2 ]; then
+		command install "${args[@]}" || return 1
+	fi
+	if [ "${#symlinks[@]}" -ge 1 ]; then
+		cp --force --preserve --no-dereference "${symlinks[@]}" "$dest" || return 1
+	fi
+}
diff --git a/rules.mk b/rules.mk
index 80cb3d63f4..2b7f9ec873 100644
--- a/rules.mk
+++ b/rules.mk
@@ -278,11 +278,11 @@  FIND:=find
 PATCH:=patch
 PYTHON:=python
 
-INSTALL_BIN:=install -m0755
-INSTALL_SUID:=install -m4755
 INSTALL_DIR:=install -d -m0755
-INSTALL_DATA:=install -m0644
-INSTALL_CONF:=install -m0600
+INSTALL_BIN:=$(SH_FUNC) install -m0755
+INSTALL_SUID:=$(SH_FUNC) install -m4755
+INSTALL_DATA:=$(SH_FUNC) install -m0644
+INSTALL_CONF:=$(SH_FUNC) install -m0600
 
 TARGET_CC_NOCACHE:=$(TARGET_CC)
 TARGET_CXX_NOCACHE:=$(TARGET_CXX)