package-plugins.sh 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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>-linux-x86_64.tar.xz (linux)
  7. # LYNX-Plugins-<label>-macos-universal.tar.xz (macos)
  8. # Inside: LYNX-Plugins-<label>/{CLAP/LYNX Plugins.clap, VST3/*.vst3, PLUGINS.txt, README.txt, install script, LICENSE,
  9. # THIRD_PARTY.md}. The plugins come from the build's plugins/ folder (cmake/LynxPlugins.cmake, scripts/build-windows-zig.sh).
  10. #
  11. # scripts/package-plugins.sh <windows|linux|macos> <plugins dir> <label> <dist dir>
  12. # scripts/package-plugins.sh --sums <label> <dist dir> LYNX-Plugins-<label>-SHA256SUMS.txt over the archives there
  13. set -euo pipefail
  14. cd "$(dirname "$0")/.."
  15. if [[ "${1:-}" == --sums ]]; then
  16. label="$2" dist="$3"
  17. cd "$dist"
  18. shopt -s nullglob
  19. files=(LYNX-Plugins-"$label"-*.zip LYNX-Plugins-"$label"-*.tar.xz)
  20. (( ${#files[@]} > 0 )) || { echo "no plugin archives for $label in $dist" >&2; exit 1; }
  21. sha256sum -- "${files[@]}" > "LYNX-Plugins-$label-SHA256SUMS.txt"
  22. cat "LYNX-Plugins-$label-SHA256SUMS.txt"
  23. exit 0
  24. fi
  25. os="$1" plugins="$2" label="$3" dist="$4"
  26. case "$os" in
  27. windows) archive="LYNX-Plugins-$label-win-x64.zip" osname="Windows x64" ;;
  28. linux) archive="LYNX-Plugins-$label-linux-x86_64.tar.xz" osname="Linux x86_64" ;;
  29. macos) archive="LYNX-Plugins-$label-macos-universal.tar.xz" osname="macOS, Apple silicon and Intel" ;;
  30. *) echo "unknown OS: $os" >&2; exit 2 ;;
  31. esac
  32. [[ -e "$plugins/LYNX Plugins.clap" ]] || { echo "no LYNX Plugins.clap in $plugins" >&2; exit 1; }
  33. mkdir -p "$dist"
  34. dist="$(cd "$dist" && pwd)"
  35. work="$(mktemp -d)"
  36. trap 'rm -rf "${work:?}"' EXIT
  37. top="LYNX-Plugins-$label"
  38. pkg="$work/$top"
  39. mkdir -p "$pkg/CLAP" "$pkg/VST3"
  40. cp -R "$plugins/LYNX Plugins.clap" "$pkg/CLAP/"
  41. # the table says which entries ship, and which of them as VST3 (built = 2); every one of those must be there
  42. {
  43. echo "LYNX plugins $label ($osname)"
  44. echo
  45. printf '%-26s %-11s %s\n' "Plugin" "Kind" "Formats"
  46. } > "$pkg/PLUGINS.txt"
  47. missing=0
  48. while IFS='~' read -r name instrument built; do
  49. kind=effect; [[ "$instrument" == 1 ]] && kind=instrument
  50. formats=CLAP
  51. if [[ "$built" == 2 ]]; then
  52. formats="CLAP, VST3"
  53. if [[ -e "$plugins/$name.vst3" ]]; then cp -R "$plugins/$name.vst3" "$pkg/VST3/"; else echo "missing: $plugins/$name.vst3" >&2; missing=1; fi
  54. fi
  55. printf '%-26s %-11s %s\n' "$name" "$kind" "$formats" >> "$pkg/PLUGINS.txt"
  56. done < <(sed -nE 's/^LYNX_PLUGIN \("([^"]+)", ([01]), [^,]+, [^,]+, "[^"]+", 0x[0-9a-f]+, "[^"]+", ([12])\)$/\1~\2~\3/p' src/plugin/plugins.def)
  57. [[ $missing == 0 ]] || exit 1
  58. sed -e "s/@LABEL@/$label/g" -e "s/@OS@/$osname/g" resources/plugin/README.txt > "$pkg/README.txt"
  59. cp LICENSE THIRD_PARTY.md "$pkg/"
  60. ./scripts/collect-licenses.sh "$pkg/licenses" > /dev/null # third-party licence texts (round 190nk)
  61. if [[ "$os" == windows ]]; then
  62. for f in README.txt PLUGINS.txt; do sed -i 's/$/\r/' "$pkg/$f"; done # (Notepad)
  63. sed 's/$/\r/' resources/plugin/install.cmd > "$pkg/install.cmd"
  64. else
  65. install -m 755 resources/plugin/install.sh "$pkg/install.sh"
  66. fi
  67. # smaller, and no build paths inside: Linux strips the symbols; macOS strips the local ones and then signs each bundle ad
  68. # hoc (an arm64 binary must carry a signature; there is no Apple Developer ID yet), the signature last
  69. if [[ "$os" == linux ]]; then
  70. find "$pkg" -type f \( -name '*.so' -o -name '*.clap' \) -exec strip --strip-unneeded {} +
  71. elif [[ "$os" == macos ]]; then
  72. find "$pkg" -type f -path '*/Contents/MacOS/*' -exec strip -x {} +
  73. for b in "$pkg/CLAP/"*.clap "$pkg/VST3/"*.vst3; do
  74. [[ -e "$b" ]] && codesign --force --sign - --timestamp=none "$b"
  75. done
  76. fi
  77. rm -f "${dist:?}/$archive"
  78. case "$os" in
  79. windows) ( cd "$work" && zip -q -r -9 -X "$dist/$archive" "$top" ) ;;
  80. # (one solid stream with a dictionary larger than a plugin: the VST3s share most of their bytes with the CLAP; macOS'
  81. # Archive Utility opens it too, and the bundles' signatures are files inside them)
  82. linux|macos) tar -C "$work" -cf - "$top" | xz -T1 --lzma2=preset=9e,dict=256MiB > "$dist/$archive" ;;
  83. esac
  84. ls -la "$dist/$archive"