spacedrive/scripts/fix-deb.sh

184 lines
5.1 KiB
Bash
Raw Normal View History

[ENG-1184, ENG-1286, ENG-1330] Rework native dependencies (+ deb fixes) (#1685) * Almost working * Downgrade libplacebo - FFMpeg 6.0 uses some now removed deprecated functions * Use -Oz for zimg * Fix CI script to run the new ffmpeg build script * Fix heif step name + Ignore docker cache while building in CI * Fix Opencl build on linux * Fix adding incorrect -target argument to linker - Update zig for windows target * Disable opengl for ffmpeg, it only uses it as an outdev, not for processing - Disable opengl and directx for libplacebo, ffmpeg only supports vulkan when using it - Add WIN32_LEAN_AND_MEAN to global cflags to optimize windows api usage - Fix 99-heif.sh incorrect bsdtar flag * Remove WIN32_LEAN_AND_MEAN from global CFLAGS as that was breaking OpenCL build - Fix Dockerfile step for cleaning up the out dir - Improve licensing handling * x86_64 windows and linux builds are working * Fix aarch64 build for windows and linux * Fix symbol visibility in linux builds - Fix soxr failing to download due to sourcefourge - Only patch zimg on windows targets - Tell cmake to hide libheif symbols * Fix Linux .so rpath - Add lzo dependency - Publish source for the built libs - Add warning for missing nasm in tauri.mjs - Remove ffmpeg install from setup.sh - Add download logic for our linux ffmpeg bundle in preprep.mjs * Remove jobs, docker doesn't support this * Fix typing * Change ffmpeg references to native deps - Rename FFMpeg.framework to Spacedrive.framework - Centralize the macOS native deps build with the windows and linux one - Change the preprep script to only download our native deps - Remove old macOS ffmpeg build scripts * Compress native deps before creating github artifact - The zip implementation for github artifact does not mantain symlinks and permissions - Remove conditional protoc, it is now always included * Don't strip dylibs, it was breaking them - Only download macOS Framework for darwin targets - Fix preprep script - Improve README.md for native-deps - Fix not finding native-deps src * Attempt to fix macOS dylib * Fix macOS dylibs - Replace lld.ld64 with apple's own linker - Add stages for building apple's compiler tools to use instead of LLVM ones * Ensure sourced file exists * All targets should build now - Fix environment sourcing in build.sh - Some minor improvements to cc.sh - Fix incorrect flag in zlib.sh - Improve how -f[...] flags are passed to compiler and linker - Add more stack hardening flags * We now can support macOS 11.0 on arm64 * Improve macOS Framework generation - Remove installed unused deps - Improve cleanup and organization logic in Dockerfile last step - Move libav* .dll.a to .lib to fix missing files in windows target - Remove apple tools from /srv folder after installation to prevent their files from being copied by other stage steps - Create all the necessary symlinks for the macOS targets while building - Remove symlink logic for macOS target from preprep.mjs * Remove native-deps from spacedrive repo - It now resides in https://github.com/spacedriveapp/native-deps - Modify preprep script to dowload native-deps from new location - Remove Github API code from scripts (not needed anymore) - Add flock.mjs to allow running tauri.mjs cleanup as soon as cargo finishes building in linux * Handle flock not present in system - Allow macOS to try using flock * Fix preprep on macOS * Add script that patch deb to fix errors and warnings raised by lintian * Fix ctrl+c/ctrl+v typo * Remove gstreamer1.0-gtk3 from deb dependencies * eval is evil * Handle tauri build release with an explicit target in fix-deb.sh * Preserve environment variables when re-executing fix-deb with sudo * Only execute fix-deb.sh when building a deb bundle * Improvements fix-deb.sh * Improve setup.sh (Add experiemental alpine support)
2023-11-17 19:20:14 +00:00
#!/usr/bin/env bash
set -eEuo pipefail
if [ "${CI:-}" = "true" ]; then
set -x
fi
if [ "$(id -u)" -ne 0 ]; then
echo "This script requires root privileges." >&2
exec sudo -E env _UID="$(id -u)" _GID="$(id -g)" "$0" "$@"
fi
echo "Fixing deb bundle..." >&2
umask 0
err() {
for _line in "$@"; do
echo "$_line" >&2
done
exit 1
}
has() {
for prog in "$@"; do
if ! command -v "$prog" 1>/dev/null 2>&1; then
return 1
fi
done
}
if ! has tar curl gzip strip; then
err 'Dependencies missing.' \
"This script requires 'tar', 'curl', 'gzip' and 'strip' to be installed and available on \$PATH."
fi
# Go to script root
CDPATH='' cd -- "$(dirname "$0")"
_root="$(pwd -P)"
if [ -n "${TARGET:-}" ]; then
cd "../target/${TARGET}/release/bundle/deb" || err 'Failed to find deb bundle'
else
cd ../target/release/bundle/deb || err 'Failed to find deb bundle'
fi
# Find deb file with the highest version number, name format: spacedrive_<version>_<arch>.deb
_deb="$(find . -type f -name '*.deb' | sort -t '_' -k '2,2' -V | tail -n 1)"
# Clean up build unused artifacts
rm -rf "$(basename "$_deb" .deb)"
# Make a backup of deb
cp "$_deb" "$_deb.bak"
# Temporary directory
_tmp="$(mktemp -d)"
cleanup() {
_err=$?
rm -rf "$_tmp"
# Restore backed up deb if something goes wrong
if [ $_err -ne 0 ]; then
mv "${_deb:?}.bak" "$_deb"
fi
# Ensure deb owner is the same as the user who ran the script
chown "${_UID:-0}:${_GID:-0}" "$_deb" 2>/dev/null || true
rm -f "${_deb:?}.bak"
exit "$_err"
}
trap 'cleanup' EXIT
# Extract deb to a tmp dir
ar x "$_deb" --output="$_tmp"
# Extract data.tar.xz
mkdir -p "${_tmp}/data"
tar -xzf "${_tmp}/data.tar.gz" -C "${_tmp}/data"
# Extract control.tar.xz
mkdir -p "${_tmp}/control"
tar -xzf "${_tmp}/control.tar.gz" -C "${_tmp}/control"
# Fix files owner
chown -R root:root "$_tmp"
# Rename sd-desktop to spacedrive
find "${_tmp}" -name 'sd-desktop' -o \( -type f -name 'sd-desktop.*' \) | while IFS= read -r file
do
filename="$(basename "$file")"
if [ "$filename" = "sd-desktop" ]; then
mv "$file" "$(dirname "$file")/spacedrive"
else
mv "$file" "$(dirname "$file")/spacedrive.${filename#*.}"
fi
done
[ENG-1184, ENG-1286, ENG-1330] Rework native dependencies (+ deb fixes) (#1685) * Almost working * Downgrade libplacebo - FFMpeg 6.0 uses some now removed deprecated functions * Use -Oz for zimg * Fix CI script to run the new ffmpeg build script * Fix heif step name + Ignore docker cache while building in CI * Fix Opencl build on linux * Fix adding incorrect -target argument to linker - Update zig for windows target * Disable opengl for ffmpeg, it only uses it as an outdev, not for processing - Disable opengl and directx for libplacebo, ffmpeg only supports vulkan when using it - Add WIN32_LEAN_AND_MEAN to global cflags to optimize windows api usage - Fix 99-heif.sh incorrect bsdtar flag * Remove WIN32_LEAN_AND_MEAN from global CFLAGS as that was breaking OpenCL build - Fix Dockerfile step for cleaning up the out dir - Improve licensing handling * x86_64 windows and linux builds are working * Fix aarch64 build for windows and linux * Fix symbol visibility in linux builds - Fix soxr failing to download due to sourcefourge - Only patch zimg on windows targets - Tell cmake to hide libheif symbols * Fix Linux .so rpath - Add lzo dependency - Publish source for the built libs - Add warning for missing nasm in tauri.mjs - Remove ffmpeg install from setup.sh - Add download logic for our linux ffmpeg bundle in preprep.mjs * Remove jobs, docker doesn't support this * Fix typing * Change ffmpeg references to native deps - Rename FFMpeg.framework to Spacedrive.framework - Centralize the macOS native deps build with the windows and linux one - Change the preprep script to only download our native deps - Remove old macOS ffmpeg build scripts * Compress native deps before creating github artifact - The zip implementation for github artifact does not mantain symlinks and permissions - Remove conditional protoc, it is now always included * Don't strip dylibs, it was breaking them - Only download macOS Framework for darwin targets - Fix preprep script - Improve README.md for native-deps - Fix not finding native-deps src * Attempt to fix macOS dylib * Fix macOS dylibs - Replace lld.ld64 with apple's own linker - Add stages for building apple's compiler tools to use instead of LLVM ones * Ensure sourced file exists * All targets should build now - Fix environment sourcing in build.sh - Some minor improvements to cc.sh - Fix incorrect flag in zlib.sh - Improve how -f[...] flags are passed to compiler and linker - Add more stack hardening flags * We now can support macOS 11.0 on arm64 * Improve macOS Framework generation - Remove installed unused deps - Improve cleanup and organization logic in Dockerfile last step - Move libav* .dll.a to .lib to fix missing files in windows target - Remove apple tools from /srv folder after installation to prevent their files from being copied by other stage steps - Create all the necessary symlinks for the macOS targets while building - Remove symlink logic for macOS target from preprep.mjs * Remove native-deps from spacedrive repo - It now resides in https://github.com/spacedriveapp/native-deps - Modify preprep script to dowload native-deps from new location - Remove Github API code from scripts (not needed anymore) - Add flock.mjs to allow running tauri.mjs cleanup as soon as cargo finishes building in linux * Handle flock not present in system - Allow macOS to try using flock * Fix preprep on macOS * Add script that patch deb to fix errors and warnings raised by lintian * Fix ctrl+c/ctrl+v typo * Remove gstreamer1.0-gtk3 from deb dependencies * eval is evil * Handle tauri build release with an explicit target in fix-deb.sh * Preserve environment variables when re-executing fix-deb with sudo * Only execute fix-deb.sh when building a deb bundle * Improvements fix-deb.sh * Improve setup.sh (Add experiemental alpine support)
2023-11-17 19:20:14 +00:00
# Create doc directory
mkdir -p "$_tmp"/data/usr/share/{doc/spacedrive,man/man1}
# Create changelog.gz
curl -LSs 'https://gist.githubusercontent.com/HeavenVolkoff/0993c42bdb0b952eb5bf765398e9b921/raw/changelog' \
| gzip -9 >"${_tmp}/data/usr/share/doc/spacedrive/changelog.gz"
# Copy LICENSE to copyright
cp "${_root}/../LICENSE" "${_tmp}/data/usr/share/doc/spacedrive/copyright"
# Copy dependencies licenses
(
for _license in "${_root}"/../apps/.deps/licenses/*; do
cat <<EOF
$(basename "$_license"):
$(cat "$_license")
===============================================================================
EOF
done
) | gzip -9 >"${_tmp}/data/usr/share/doc/spacedrive/thrid-party-licenses.gz"
# Create manual page
curl -LSs 'https://gist.githubusercontent.com/HeavenVolkoff/0993c42bdb0b952eb5bf765398e9b921/raw/spacedrive.1' \
| gzip -9 >"${_tmp}/data/usr/share/man/man1/spacedrive.1.gz"
# Fill the Categories entry in .desktop file
sed -i 's/^Categories=.*/Categories=System;FileTools;FileManager;/' "${_tmp}/data/usr/share/applications/spacedrive.desktop"
# Fix data permissions
find "${_tmp}/data" -type d -exec chmod 755 {} +
find "${_tmp}/data" -type f -exec chmod 644 {} +
# Fix main executable permission
chmod 755 "${_tmp}/data/usr/bin/spacedrive"
# Make generic named shared libs symlinks to the versioned ones
find "${_tmp}/data/usr/lib" -type f -name '*.so.*' -exec sh -euc \
'for _lib in "$@"; do _link="$_lib" && while { _link="${_link%.*}" && [ "$_link" != "${_lib%.so*}" ]; }; do if [ -f "$_link" ]; then ln -sf "$(basename "$_lib")" "$_link"; fi; done; done' \
sh {} +
# Strip all executables and shared libs
find "${_tmp}/data/usr/bin" "${_tmp}/data/usr/lib" -type f -exec strip --strip-unneeded {} \;
# Add Section field to control file, if it doesnt exists
if ! grep -q '^Section:' "${_tmp}/control/control"; then
echo 'Section: contrib/utils' >>"${_tmp}/control/control"
fi
# Add Recommends field to control file after Depends field
_recomends='gstreamer1.0-plugins-ugly'
if grep -q '^Recommends:' "${_tmp}/control/control"; then
sed -i "s/^Recommends:.*/Recommends: ${_recomends}/" "${_tmp}/control/control"
else
sed -i "/^Depends:/a Recommends: ${_recomends}" "${_tmp}/control/control"
fi
# Add Suggests field to control file after Recommends field
_suggests='gstreamer1.0-plugins-bad'
if grep -q '^Suggests:' "${_tmp}/control/control"; then
sed -i "s/^Suggests:.*/Suggests: ${_suggests}/" "${_tmp}/control/control"
else
sed -i "/^Recommends:/a Suggests: ${_suggests}" "${_tmp}/control/control"
fi
# Re-calculate md5sums
(cd "${_tmp}/data" && find . -type f -exec md5sum {} + >"${_tmp}/control/md5sums")
# Fix control files permission
find "${_tmp}/control" -type f -exec chmod 644 {} +
# Compress data.tar.xz
tar -czf "${_tmp}/data.tar.gz" -C "${_tmp}/data" .
# Compress control.tar.xz
tar -czf "${_tmp}/control.tar.gz" -C "${_tmp}/control" .
# Compress deb
ar rcs "$_deb" "${_tmp}/debian-binary" "${_tmp}/control.tar.gz" "${_tmp}/data.tar.gz"