From 555ef2d3f7c9703c724b1e2975ef9a8512d4d7b5 Mon Sep 17 00:00:00 2001 From: Ryosuke Ito Date: Thu, 18 May 2023 03:54:31 +0900 Subject: [PATCH 1/2] Use awk instead of sed just in case DEVELOPER_DIR contains meta characters of sed --- Package/Scripts/preinstall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package/Scripts/preinstall b/Package/Scripts/preinstall index 0869764..c715f01 100755 --- a/Package/Scripts/preinstall +++ b/Package/Scripts/preinstall @@ -27,6 +27,6 @@ IFS=' ' # newline for old_rpath in $(get_rpaths "${INSTALLER_PAYLOAD_DIR}/usr/local/bin/xcnew") do - new_rpath="$(echo "$old_rpath" | /usr/bin/sed -e "s|.*/Contents/Developer|$developer_dir|")" + new_rpath="$(echo "$old_rpath" | /usr/bin/awk -v developer_dir="$developer_dir" '{sub(".*/Contents/Developer", developer_dir); print}')" /usr/bin/install_name_tool -rpath "$old_rpath" "$new_rpath" "${INSTALLER_PAYLOAD_DIR}/usr/local/bin/xcnew" done From 96af4e49e67b66f07d533a331d1291420c018dc5 Mon Sep 17 00:00:00 2001 From: Ryosuke Ito Date: Thu, 18 May 2023 03:59:36 +0900 Subject: [PATCH 2/2] Use printf instead of echo just in case run paths contain hyphens --- Package/Scripts/preinstall | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Package/Scripts/preinstall b/Package/Scripts/preinstall index c715f01..7ac3e41 100755 --- a/Package/Scripts/preinstall +++ b/Package/Scripts/preinstall @@ -14,12 +14,12 @@ get_rpaths() { developer_dir="$(/usr/bin/xcode-select --print-path)" if ! is_developer_dir_in_xcode "$developer_dir"; then # shellcheck disable=SC2016 - echo 'error: DEVELOPER_DIR is not in Xcode. Run `xcode-select --switch /path/to/Xcode.app/Contents/Developer` to set it to the correct path.' >&2 + /usr/bin/printf 'error: DEVELOPER_DIR is not in Xcode. Run `xcode-select --switch /path/to/Xcode.app/Contents/Developer` to set it to the correct path.\n' >&2 exit 1 fi if [ -z "$INSTALLER_PAYLOAD_DIR" ]; then - echo 'error: INSTALLER_PAYLOAD_DIR is not set. Do not run this script outside of installer context.' >&2 + /usr/bin/printf 'error: INSTALLER_PAYLOAD_DIR is not set. Do not run this script outside of installer context.\n' >&2 exit 1 fi @@ -27,6 +27,6 @@ IFS=' ' # newline for old_rpath in $(get_rpaths "${INSTALLER_PAYLOAD_DIR}/usr/local/bin/xcnew") do - new_rpath="$(echo "$old_rpath" | /usr/bin/awk -v developer_dir="$developer_dir" '{sub(".*/Contents/Developer", developer_dir); print}')" + new_rpath="$(/usr/bin/printf "%s\n" "$old_rpath" | /usr/bin/awk -v developer_dir="$developer_dir" '{sub(".*/Contents/Developer", developer_dir); print}')" /usr/bin/install_name_tool -rpath "$old_rpath" "$new_rpath" "${INSTALLER_PAYLOAD_DIR}/usr/local/bin/xcnew" done