4
0

package-plugins.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. # LYNX's plugins for other hosts as the optional download of a release (round 188b, docs/PLUGIN_EXPORT.md): one archive per
  3. # OS, never inside the app's installer. The names must not end like the app's files (the updater picks those by suffix,
  4. # core/UpdateCheck.cpp; tests/PluginExport180bTests.inc checks it):
  5. # LYNX-Plugins-<label>-win-x64.zip (windows)
  6. # LYNX-Plugins-<label>-win-x64.7z (windows, the same folder in one solid LZMA2 stream; round 190pu)
  7. # LYNX-Plugins-<label>-linux-x86_64.tar.xz (linux)
  8. # LYNX-Plugins-<label>-macos-universal.tar.xz (macos)
  9. # Inside: LYNX-Plugins-<label>/{CLAP/LYNX Plugins.clap, VST3/*.vst3, LV2/*.lv2 (Linux, round 190ov), PLUGINS.txt, README.txt, install script, LICENSE,
  10. # THIRD_PARTY.md}. The plugins come from the build's plugins/ folder (cmake/LynxPlugins.cmake, scripts/build-windows-zig.sh).
  11. #
  12. # scripts/package-plugins.sh <windows|linux|macos> <plugins dir> <label> <dist dir>
  13. # scripts/package-plugins.sh --sums <label> <dist dir> LYNX-Plugins-<label>-SHA256SUMS.txt over the archives there
  14. set -euo pipefail
  15. cd "$(dirname "$0")/.."
  16. if [[ "${1:-}" == --sums ]]; then
  17. label="$2" dist="$3"
  18. cd "$dist"
  19. shopt -s nullglob
  20. files=(LYNX-Plugins-"$label"-*.zip LYNX-Plugins-"$label"-*.7z LYNX-Plugins-"$label"-*.tar.xz)
  21. (( ${#files[@]} > 0 )) || { echo "no plugin archives for $label in $dist" >&2; exit 1; }
  22. sha256sum -- "${files[@]}" > "LYNX-Plugins-$label-SHA256SUMS.txt"
  23. cat "LYNX-Plugins-$label-SHA256SUMS.txt"
  24. exit 0
  25. fi
  26. os="$1" plugins="$2" label="$3" dist="$4"
  27. case "$os" in
  28. windows) archive="LYNX-Plugins-$label-win-x64.zip" osname="Windows x64" ;;
  29. linux) archive="LYNX-Plugins-$label-linux-x86_64.tar.xz" osname="Linux x86_64" ;;
  30. macos) archive="LYNX-Plugins-$label-macos-universal.tar.xz" osname="macOS, Apple silicon and Intel" ;;
  31. *) echo "unknown OS: $os" >&2; exit 2 ;;
  32. esac
  33. [[ -e "$plugins/LYNX Plugins.clap" ]] || { echo "no LYNX Plugins.clap in $plugins" >&2; exit 1; }
  34. mkdir -p "$dist"
  35. dist="$(cd "$dist" && pwd)"
  36. work="$(mktemp -d)"
  37. trap 'rm -rf "${work:?}"' EXIT
  38. top="LYNX-Plugins-$label"
  39. pkg="$work/$top"
  40. mkdir -p "$pkg/CLAP" "$pkg/VST3"
  41. cp -R "$plugins/LYNX Plugins.clap" "$pkg/CLAP/"
  42. # the table says which entries ship, and which of them as VST3 (built = 2); every one of those must be there
  43. {
  44. echo "LYNX plugins $label ($osname)"
  45. echo
  46. printf '%-26s %-11s %s\n' "Plugin" "Kind" "Formats"
  47. } > "$pkg/PLUGINS.txt"
  48. missing=0
  49. # (LV2 only when the build made LV2 bundles: cmake option LYNX_PLUGINS_LV2)
  50. lv2build=0
  51. compgen -G "$plugins/*.lv2" > /dev/null && lv2build=1
  52. while IFS='~' read -r name instrument built; do
  53. kind=effect; [[ "$instrument" == 1 ]] && kind=instrument
  54. formats=CLAP
  55. if [[ "$built" == 2 ]]; then
  56. formats="CLAP, VST3"
  57. if [[ -e "$plugins/$name.vst3" ]]; then cp -R "$plugins/$name.vst3" "$pkg/VST3/"; else echo "missing: $plugins/$name.vst3" >&2; missing=1; fi
  58. if [[ "$os" == linux && $lv2build == 1 ]]; then # (round 190ov: LV2 bundles, dashes for the name's other characters)
  59. lv2="${name//[^A-Za-z0-9]/-}.lv2"
  60. formats="CLAP, VST3, LV2"
  61. mkdir -p "$pkg/LV2"
  62. if [[ -e "$plugins/$lv2/manifest.ttl" ]]; then cp -R "$plugins/$lv2" "$pkg/LV2/"; else echo "missing: $plugins/$lv2" >&2; missing=1; fi
  63. fi
  64. fi
  65. printf '%-26s %-11s %s\n' "$name" "$kind" "$formats" >> "$pkg/PLUGINS.txt"
  66. done < <(sed -nE 's/^LYNX_PLUGIN \("([^"]+)", ([01]), [^,]+, [^,]+, "[^"]+", 0x[0-9a-f]+, "[^"]+", ([12])\)$/\1~\2~\3/p' src/plugin/plugins.def)
  67. [[ $missing == 0 ]] || exit 1
  68. sed -e "s/@LABEL@/$label/g" -e "s/@OS@/$osname/g" resources/plugin/README.txt > "$pkg/README.txt"
  69. cp LICENSE THIRD_PARTY.md "$pkg/"
  70. ./scripts/collect-licenses.sh "$pkg/licenses" > /dev/null # third-party licence texts (round 190nk)
  71. if [[ "$os" == windows ]]; then
  72. for f in README.txt PLUGINS.txt; do sed -i 's/$/\r/' "$pkg/$f"; done # (Notepad)
  73. sed 's/$/\r/' resources/plugin/install.cmd > "$pkg/install.cmd"
  74. else
  75. install -m 755 resources/plugin/install.sh "$pkg/install.sh"
  76. fi
  77. # smaller, and no build paths inside: Linux strips the symbols; macOS strips the local ones and then signs each bundle ad
  78. # hoc (an arm64 binary must carry a signature; there is no Apple Developer ID yet), the signature last
  79. if [[ "$os" == linux ]]; then
  80. find "$pkg" -type f \( -name '*.so' -o -name '*.clap' \) -exec strip --strip-unneeded {} +
  81. elif [[ "$os" == macos ]]; then
  82. find "$pkg" -type f -path '*/Contents/MacOS/*' -exec strip -x {} +
  83. for b in "$pkg/CLAP/"*.clap "$pkg/VST3/"*.vst3; do
  84. [[ -e "$b" ]] && codesign --force --sign - --timestamp=none "$b"
  85. done
  86. fi
  87. rm -f "${dist:?}/$archive"
  88. case "$os" in
  89. # (a zip compresses every file alone, so its 12 binaries, which share nearly all their bytes, cost 12 times as much; the
  90. # .7z next to it is one solid LZMA2 stream (128 MiB dictionary, about 1.5 GB to pack, 128 MB to unpack), the same trick as the tar.xz
  91. # below: 195 MB -> 20 MB in round 190pu. The zip stays for Explorer and every older unpacker.
  92. # Round 190sh: the zip is written by 7-Zip's Deflate encoder (258-byte matches, 5 passes): plain Deflate as before, which
  93. # every unzip reads, 3.3 % smaller than Info-ZIP's zip -9 (-mpass=15 gains 0.03 % more for 4x the time; Deflate64 would be
  94. # 5 % but not every unpacker reads it))
  95. windows)
  96. sevenz="$(command -v 7zz || command -v 7z || command -v 7za || true)"
  97. [[ -n "$sevenz" ]] || { echo "no 7zz / 7z: needed for the zip and the .7z (apt install 7zip)" >&2; exit 1; }
  98. ( cd "$work" && "$sevenz" a -tzip -mx=9 -mm=Deflate -mfb=258 -mpass=5 -mmt="${PACK_THREADS:-$(nproc)}" -bso0 -bsp0 "$dist/$archive" "$top" )
  99. archive7="${archive%.zip}.7z"
  100. rm -f "${dist:?}/$archive7"
  101. ( cd "$work" && "$sevenz" a -t7z -mx=9 -m0=lzma2 -md=128m -mfb=273 -ms=on -mmt=1 -bso0 -bsp0 "$dist/$archive7" "$top" )
  102. ls -la "$dist/$archive7" ;;
  103. # (one solid stream with a dictionary larger than a plugin: the VST3s share most of their bytes with the CLAP; macOS'
  104. # Archive Utility opens it too, and the bundles' signatures are files inside them)
  105. linux|macos) tar -C "$work" -cf - "$top" | xz -T1 --lzma2=preset=9e,dict=256MiB > "$dist/$archive" ;;
  106. esac
  107. ls -la "$dist/$archive"