2024-05-12 13:07:04 +06:00
|
|
|
#!/usr/bin/env bash
|
2021-09-20 15:24:11 +06:00
|
|
|
|
2023-02-24 19:11:15 +06:00
|
|
|
# Copyright (c) 2021-2023 Leseratte10
|
|
|
|
# This file is part of the ACSM Input Plugin by Leseratte10
|
|
|
|
# ACSM Input Plugin for Calibre / acsm-calibre-plugin
|
|
|
|
#
|
|
|
|
# For more information, see:
|
|
|
|
# https://github.com/Leseratte10/acsm-calibre-plugin
|
|
|
|
|
2024-05-12 13:07:04 +06:00
|
|
|
sed_i() {
|
|
|
|
script="$1"
|
|
|
|
path="$2"
|
|
|
|
tmpfile="$path.tmp"
|
|
|
|
sed "$script" "$path" > "$tmpfile"
|
|
|
|
mv "$tmpfile" "$path"
|
|
|
|
}
|
|
|
|
|
2023-02-24 19:11:15 +06:00
|
|
|
|
2021-09-25 20:24:03 +06:00
|
|
|
[ ! -f calibre-plugin/asn1crypto.zip ] && ./package_modules.sh
|
|
|
|
[ ! -f calibre-plugin/oscrypto.zip ] && ./package_modules.sh
|
2021-09-20 15:24:11 +06:00
|
|
|
|
2022-01-16 22:43:29 +06:00
|
|
|
rm -rf calibre-plugin-tmp || /bin/true
|
|
|
|
|
|
|
|
cp -r calibre-plugin calibre-plugin-tmp
|
|
|
|
|
|
|
|
pushd calibre-plugin-tmp
|
2021-11-25 14:15:37 +06:00
|
|
|
pushd keyextract
|
2021-11-20 19:14:59 +06:00
|
|
|
|
2021-12-17 03:26:44 +06:00
|
|
|
# Compile C programs:
|
2021-11-20 19:14:59 +06:00
|
|
|
make
|
|
|
|
|
2022-06-15 23:29:55 +06:00
|
|
|
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:
|
2024-05-12 13:07:04 +06:00
|
|
|
sed_i "/@@@CALIBRE_DECRYPTOR_WIN32_B64@@@/ {
|
2022-06-15 23:29:55 +06:00
|
|
|
r decrypt_win32_b64.txt
|
|
|
|
d
|
2024-05-12 13:07:04 +06:00
|
|
|
}" ../keyextractDecryptor.py
|
2022-06-15 23:29:55 +06:00
|
|
|
|
2024-05-12 13:07:04 +06:00
|
|
|
sed_i "/@@@CALIBRE_DECRYPTOR_WIN64_B64@@@/ {
|
2022-06-15 23:29:55 +06:00
|
|
|
r decrypt_win64_b64.txt
|
|
|
|
d
|
2024-05-12 13:07:04 +06:00
|
|
|
}" ../keyextractDecryptor.py
|
2022-06-15 23:29:55 +06:00
|
|
|
|
|
|
|
rm decrypt_win32_b64.txt decrypt_win64_b64.txt
|
|
|
|
rm decrypt_win32.exe decrypt_win64.exe
|
|
|
|
|
2021-11-20 19:14:59 +06:00
|
|
|
popd
|
2021-09-20 15:24:11 +06:00
|
|
|
|
2021-12-20 03:13:19 +06:00
|
|
|
# Delete cache
|
|
|
|
rm -r __pycache__
|
2022-01-16 23:34:52 +06:00
|
|
|
rm *.pyc
|
2021-12-20 03:13:19 +06:00
|
|
|
|
2021-12-17 03:26:44 +06:00
|
|
|
# Set module ID. This needs to be changed if any of the module ZIPs change.
|
2023-12-19 11:45:01 +06:00
|
|
|
echo -n "2023-12-19-01" > module_id.txt
|
2021-12-15 15:09:52 +06:00
|
|
|
|
2022-01-16 15:12:55 +06:00
|
|
|
# Copy LICENSE and README.md so it'll be included in the ZIP.
|
2021-12-17 03:26:44 +06:00
|
|
|
cp ../LICENSE LICENSE
|
2022-01-16 15:12:55 +06:00
|
|
|
cp ../README.md README.md
|
2021-12-17 03:26:44 +06:00
|
|
|
|
2022-01-16 22:43:29 +06:00
|
|
|
shopt -s globstar
|
|
|
|
echo "Injecting Python2 compat code ..."
|
|
|
|
for file in **/*.py;
|
|
|
|
do
|
|
|
|
#echo $file
|
|
|
|
# Inject Python2 compat code:
|
2024-05-12 13:07:04 +06:00
|
|
|
sed_i '/#@@CALIBRE_COMPAT_CODE@@/ {
|
2022-01-16 22:43:29 +06:00
|
|
|
r __calibre_compat_code.py
|
|
|
|
d
|
2024-05-12 13:07:04 +06:00
|
|
|
}' $file
|
2022-01-16 22:43:29 +06:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-17 03:26:44 +06:00
|
|
|
# Create ZIP file from calibre-plugin folder.
|
2021-09-20 15:24:11 +06:00
|
|
|
zip -r ../calibre-plugin.zip *
|
|
|
|
|
|
|
|
popd
|
2022-01-16 22:43:29 +06:00
|
|
|
rm -rf calibre-plugin-tmp
|
2021-09-20 15:24:11 +06:00
|
|
|
|