From 5a4d25e91d2fc2f913a00a98a8b0a161282017e2 Mon Sep 17 00:00:00 2001 From: Dave Vasilevsky Date: Sun, 12 May 2024 03:07:04 -0400 Subject: [PATCH] Portability improvements in scripts * Not all systems have GNU sed, so don't assume `sed -i` works * Not all systems have /bin/bash, so use `env` to find bash --- bundle_calibre_plugin.sh | 22 +++++++++++++++------- bundle_migration_plugin.sh | 2 +- package_modules.sh | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bundle_calibre_plugin.sh b/bundle_calibre_plugin.sh index fcb5919..e2c3ed0 100755 --- a/bundle_calibre_plugin.sh +++ b/bundle_calibre_plugin.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2021-2023 Leseratte10 # This file is part of the ACSM Input Plugin by Leseratte10 @@ -7,6 +7,14 @@ # For more information, see: # https://github.com/Leseratte10/acsm-calibre-plugin +sed_i() { + script="$1" + path="$2" + tmpfile="$path.tmp" + sed "$script" "$path" > "$tmpfile" + mv "$tmpfile" "$path" +} + [ ! -f calibre-plugin/asn1crypto.zip ] && ./package_modules.sh [ ! -f calibre-plugin/oscrypto.zip ] && ./package_modules.sh @@ -25,15 +33,15 @@ base64 decrypt_win32.exe > decrypt_win32_b64.txt base64 decrypt_win64.exe > decrypt_win64_b64.txt # Base64-encode binaries and place them inside decryptor.py: -sed "/@@@CALIBRE_DECRYPTOR_WIN32_B64@@@/ { +sed_i "/@@@CALIBRE_DECRYPTOR_WIN32_B64@@@/ { r decrypt_win32_b64.txt d -}" -i ../keyextractDecryptor.py +}" ../keyextractDecryptor.py -sed "/@@@CALIBRE_DECRYPTOR_WIN64_B64@@@/ { +sed_i "/@@@CALIBRE_DECRYPTOR_WIN64_B64@@@/ { r decrypt_win64_b64.txt d -}" -i ../keyextractDecryptor.py +}" ../keyextractDecryptor.py rm decrypt_win32_b64.txt decrypt_win64_b64.txt rm decrypt_win32.exe decrypt_win64.exe @@ -57,10 +65,10 @@ for file in **/*.py; do #echo $file # Inject Python2 compat code: - sed '/#@@CALIBRE_COMPAT_CODE@@/ { + sed_i '/#@@CALIBRE_COMPAT_CODE@@/ { r __calibre_compat_code.py d - }' -i $file + }' $file done diff --git a/bundle_migration_plugin.sh b/bundle_migration_plugin.sh index ad5a1c7..98566fb 100755 --- a/bundle_migration_plugin.sh +++ b/bundle_migration_plugin.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2021-2023 Leseratte10 # This file is part of the ACSM Input Plugin by Leseratte10 diff --git a/package_modules.sh b/package_modules.sh index 3a6c853..b5c1593 100755 --- a/package_modules.sh +++ b/package_modules.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2021-2023 Leseratte10 # This file is part of the ACSM Input Plugin by Leseratte10