From 1595d59bda136e2daf2ac2ef8abd221560e669d4 Mon Sep 17 00:00:00 2001 From: q Date: Sat, 14 Sep 2024 19:05:29 -0400 Subject: [PATCH] Check if file exists before patching --- patches/remove-share-to-nonfree-services.sh | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/patches/remove-share-to-nonfree-services.sh b/patches/remove-share-to-nonfree-services.sh index b64e441..4660b0e 100755 --- a/patches/remove-share-to-nonfree-services.sh +++ b/patches/remove-share-to-nonfree-services.sh @@ -15,6 +15,9 @@ # You should have received a copy of the GNU General Public License # along with element-web-patches. If not, see . +set -euo pipefail +LWD="$PWD" + echo "Removing links to nonfree services..." error() { @@ -22,7 +25,11 @@ error() { exit 1 } -patch_content=$(cat << EOF +cd "${1}" + +if test -f "./node_modules/matrix-react-sdk/lib/components/views/dialogs/ShareDialog.js"; then + +patchjs_content=$(cat << EOF --- a/node_modules/matrix-react-sdk/lib/components/views/dialogs/ShareDialog.js +++ b/node_modules/matrix-react-sdk/lib/components/views/dialogs/ShareDialog.js @@ -37,28 +37,6 @@ @@ -54,6 +61,15 @@ patch_content=$(cat << EOF name: "email", img: require("../../../../res/img/social/email-1.png"), url: url => \`mailto:?body=\${url}\` +EOF +) + +echo "${patchjs_content}" | patch -t -p1 || error +fi + +if test -f "./node_modules/matrix-react-sdk/src/components/views/dialogs/ShareDialog.tsx"; then + +patchtsx_content=$(cat << EOF --- a/node_modules/matrix-react-sdk/src/components/views/dialogs/ShareDialog.tsx +++ b/node_modules/matrix-react-sdk/src/components/views/dialogs/ShareDialog.tsx @@ -31,30 +31,6 @@ @@ -90,8 +106,6 @@ patch_content=$(cat << EOF EOF ) -(cd "${1}" && echo "${patch_content}" | patch -p1) || error -rm -f "${1}"/node_modules/matrix-react-sdk/res/img/social/facebook.png \ - "${1}"/node_modules/matrix-react-sdk/res/img/social/linkedin.png \ - "${1}"/node_modules/matrix-react-sdk/res/img/social/reddit.png \ - "${1}"/node_modules/matrix-react-sdk/res/img/social/twitter-2.png \ +echo "${patchtsx_content}" | patch -t -p1 || error +fi +cd $LWD