Skip to content

Instantly share code, notes, and snippets.

@Ashark
Last active September 10, 2020 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashark/a194db36c8acd53f3cff496b617628fb to your computer and use it in GitHub Desktop.
Save Ashark/a194db36c8acd53f3cff496b617628fb to your computer and use it in GitHub Desktop.
remake PKGBUILD for davinci-resolve
# Maintainer: Alex S. <shantanna_at_hotmail_dot_com>
# Contributor: Jonathon Fernyhough <jonathon_at_manjaro_dot_org>
# Contributor: Andrew Shark <ashark#linuxcomp.ru>
# Hardware support is limited.
# See https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=56878&p=456990#p456924
pkgname=davinci-resolve
_pkgname=resolve
pkgver=15.2.3
pkgrel=2
pkgdesc='Professional A/V post-production software suite from Blackmagic Design'
arch=('x86_64')
url="https://www.blackmagicdesign.com/"
license=('Commercial')
depends=('glu' 'gtk2' 'gstreamer' 'libpng12' 'lib32-libpng12' 'ocl-icd' 'openssl-1.0'
'opencl-driver' 'qt4' 'qt5-base' 'qt5-svg' 'qt5-webkit'
'qt5-webengine' 'qt5-websockets')
# TODO check that all of these needed. Also explore `ldd ./installer` and `ldd resolve`.
makedepends=('libarchive')
options=('!strip')
install=${pkgname}.install
conflicts=('davinci-resolve-beta' 'davinci-resolve-studio' 'davinci-resolve-studio-beta')
# This was originally written by Daniel Bermond in blackmagic-decklink-sdk pkgbuild
# It is sufficient to just replace _downloadid to correspond new release version
# It can be obtained from chromium -> Developer Tools -> Network -> XHR and Fetch -> the next one after latest-version
_downloadid='89633cfa41e142c9bdc1724fbb5ff873' # dr 15.2.3
_referid='4f929ebb222c4ce68567cbe38d735ffe'
_srcurl="https://www.blackmagicdesign.com/api/register/us/download/${_downloadid}"
source=("DaVinci_Resolve_${pkgver}_Linux.zip"::"$_srcurl")
sha256sums=('d0123739c68b3b03565a1478625a3ebafbb067eb5631a7c7b0a41726f5d5c854')
_useragent="User-Agent: Mozilla/5.0 (X11; Linux ${CARCH}) \
AppleWebKit/537.36 (KHTML, like Gecko) \
Chrome/70.0.3538.77 \
Safari/537.36"
_reqjson="{ \
\"platform\": \"Linux\", \
\"country\": \"us\", \
\"firstname\": \"Arch\", \
\"lastname\": \"Linux\", \
\"email\": \"someone@archlinux.org\", \
\"phone\": \"202-555-0194\", \
\"state\": \"New York\", \
\"city\": \"AUR\", \
\"hasAgreedToTerms\": true, \
\"product\": \"Desktop Video ${pkgver} SDK\" \
}"
_reqjson="$( printf '%s' "$_reqjson" | sed 's/[[:space:]]\+/ /g')"
_useragent="$(printf '%s' "$_useragent" | sed 's/[[:space:]]\+/ /g')"
_useragent_escaped="${_useragent// /\\ }"
DLAGENTS=("https::/usr/bin/curl \
-gqb '' -C - --retry 3 --retry-delay 3 \
-H Host:\ sw.blackmagicdesign.com \
-H Upgrade-Insecure-Requests:\ 1 \
-H ${_useragent_escaped} \
-H Accept:\ text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 \
-H Accept-Language:\ en-US,en;q=0.9 \
-o %o \
--compressed \
$(curl \
-s \
-H 'Host: www.blackmagicdesign.com' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Origin: https://www.blackmagicdesign.com' \
-H "$_useragent" \
-H 'Content-Type: application/json;charset=UTF-8' \
-H "Referer: https://www.blackmagicdesign.com/support/download/${_referid}/Linux" \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Authority: www.blackmagicdesign.com' \
-H 'Cookie: _ga=GA1.2.1849503966.1518103294; _gid=GA1.2.953840595.1518103294' \
--data-binary "$_reqjson" \
--compressed \
"$_srcurl"
)"
)
PKGEXT=".pkg.tar" # for maintainers
# Order of the official installation procedure:
# You download .zip from blackmagicdesign site.
# Then you unpack it. Two files are inside: pdf and run.
# In pdf there is a link to dedicated centos iso installer with dr, which we may use for tests.
# .run file is actually AppImage. It starts AppRun file, which calls "installer" executable.
# For some reason they made it binary, so we cannot see what else it does. But here is order of its actions:
# - run scripts/pre_install.sh
# - copy all files except AppRun and .DirIcon to /opt/resolve
# - run scripts/post_install.sh
# So this pkgbuild is remake of these actions.
prepare() {
rm -rf "${srcdir}/unpacked" # to prevent removed from distribution files to be copied to new versions builds
mkdir -p "${srcdir}"/unpacked
bsdtar x -f DaVinci_Resolve_${pkgver}_Linux.run -C "${srcdir}"/unpacked
}
package() {
# pre_install.sh reimplementation start
INSTALL_DIR="${pkgdir}"/opt/resolve
# USER_UID=0
# USER_HOME="${pkgdir}"/root
# Installing Resolve as root may cause issues with file permissions when running Resolve as a non-root user. # from pdf manual. Check for correctness.
# mkdir -m 0775 -p "$INSTALL_DIR" # this is from original script
# chown $USER_UID "$INSTALL_DIR" -R # this is from original script
# We will instead give 777 permissions to specific dirs to allow users to write there but deny touching package files
# Alternatively, we could require user to be in users group and change group of files/dirs to users to allow writing
mkdir -p "$INSTALL_DIR"
# Permissions tweaks are done below
# pre_install.sh reimplementation end
# ./installer reimplementation start
cp -rpT "${srcdir}"/unpacked "${pkgdir}/opt/resolve"
rm "${pkgdir}"/opt/resolve/{AppRun,.DirIcon,installer,installer.dat,filelist.txt}
rm "${pkgdir}"/opt/resolve/graphics/watermark.png # clutter used by gui installer
rm "${pkgdir}"/opt/resolve/docs/Welcome.txt # clutter used by gui installer
rm "${pkgdir}"/opt/resolve/scripts/{pre_install.sh,post_install.sh,uninstall.sh,script.update} # not needed
# ./installer reimplementation end
# post_install.sh reimplementation start
# COMMON_DATA_DIR=/var/davinci/resolve # never used
RESOLVE_APP_NAME=com.blackmagicdesign.resolve
# DBUS_SERVICE_DIR=/usr/share/dbus-1/services # never used
FILES=(
"${pkgdir}"/opt/resolve/share/DaVinciResolve.desktop
"${pkgdir}"/opt/resolve/share/DaVinciResolveInstaller.desktop
"${pkgdir}"/opt/resolve/share/DaVinciResolveCaptureLogs.desktop
"${pkgdir}"/opt/resolve/share/DaVinciResolvePanelSetup.desktop
"${pkgdir}"/opt/resolve/share/DaVinciResolve.directory
"${pkgdir}"/opt/resolve/share/DaVinciResolve.menu
)
ABSOLUTE_INSTALL_DIR="/opt/resolve"
for file in "${FILES[@]}"; do
sed -i -e "s:RESOLVE_INSTALL_LOCATION:${ABSOLUTE_INSTALL_DIR}:g" "$file"
done
mkdir -p "${pkgdir}"/usr/share/applications/
mkdir -p "${pkgdir}"/usr/share/desktop-directories/
mkdir -p "${pkgdir}"/etc/xdg/menus/applications-merged
mv "${pkgdir}"/opt/resolve/share/DaVinciResolve.desktop "${pkgdir}"/usr/share/applications/${RESOLVE_APP_NAME}.desktop
sed -i 's/Revolutionary new tools for editing, visual effects, color correction and professional audio post production, all in a single application!/Professional non-linear editing/g' "${pkgdir}"/usr/share/applications/${RESOLVE_APP_NAME}.desktop # my own patch
echo "Categories=AudioVideo;AudioVideoEditing;" >> "${pkgdir}"/usr/share/applications/${RESOLVE_APP_NAME}.desktop # my own patch
rm "${pkgdir}"/opt/resolve/share/DaVinciResolveInstaller.desktop
rm "${pkgdir}"/opt/resolve/graphics/DV_Uninstall.png
mv "${pkgdir}"/opt/resolve/share/DaVinciResolveCaptureLogs.desktop "${pkgdir}"/usr/share/applications/${RESOLVE_APP_NAME}-CaptureLogs.desktop
mv "${pkgdir}"/opt/resolve/share/DaVinciResolvePanelSetup.desktop "${pkgdir}"/usr/share/applications/${RESOLVE_APP_NAME}-Panels.desktop
mv "${pkgdir}"/opt/resolve/share/DaVinciResolve.directory "${pkgdir}"/usr/share/desktop-directories/${RESOLVE_APP_NAME}.directory
mv "${pkgdir}"/opt/resolve/share/DaVinciResolve.menu "${pkgdir}"/etc/xdg/menus/applications-merged/${RESOLVE_APP_NAME}.menu
sed -i 's/<Filename>com.blackmagicdesign.resolve-Installer.desktop<\/Filename>//g' "${pkgdir}"/etc/xdg/menus/applications-merged/${RESOLVE_APP_NAME}.menu
mkdir -p "${pkgdir}"/usr/share/icons/hicolor/128x128
mkdir -p "${pkgdir}"/usr/share/mime/packages
XDG_DATA_DIRS="${pkgdir}"/usr/share
xdg-icon-resource install --size 128 "${INSTALL_DIR}"/graphics/DV_Resolve.png DaVinci-Resolve
xdg-icon-resource install --size 128 "${INSTALL_DIR}"/graphics/DV_ResolveProj.png DaVinci-ResolveProj
xdg-icon-resource install --size 128 --context mimetypes "${INSTALL_DIR}"/graphics/DV_ResolveProj.png application-x-resolveproj
# xdg-mime install --novendor "${INSTALL_DIR}"/share/resolve.xml # not needed, handled by pacman
# instead we just copy resolve.xml
cp "${INSTALL_DIR}"/share/resolve.xml "${pkgdir}"/usr/share/mime/packages
mkdir -p "${pkgdir}"/usr/lib/udev/rules.d/
echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="096e", MODE="0666"' > "${pkgdir}"/usr/lib/udev/rules.d/75-davincipanel.rules
echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1edb", MODE="0666"' > "${pkgdir}"/usr/lib/udev/rules.d/75-sdx.rules
PANEL_DRIVER_DIR="${pkgdir}/usr/lib"
mkdir -p "${pkgdir}"/usr/lib # already created in udev rules, but just to be sure
tar -xf "${INSTALL_DIR}"/share/panels/dvpanel-framework-linux-x86_64.tgz libDaVinciPanelAPI.so # I have not used a lib folder from archive
mv libDaVinciPanelAPI.so "${PANEL_DRIVER_DIR}"
rm "${INSTALL_DIR}"/share/panels/dvpanel-framework-linux-x86_64.tgz
# From original:
# # We install the default app associations here, because xdg-mime is buggy in centos6
# install_default_application ${RESOLVE_APP_NAME}.desktop application/x-resolveproj
# # We install the default application system-wide. Per user default-app preferences are buggy for Centos6
# install_default_application()
# {
# $1 is .desktop
# $2 is mime/type
# DEFAULT_MIME_FILE="/usr/share/applications/defaults.list"
# grep -v "$2=" $DEFAULT_MIME_FILE > ${DEFAULT_MIME_FILE}.new 2> /dev/null
# if ! grep "[Default Applications]" ${DEFAULT_MIME_FILE}.new > /dev/null; then
# echo "[Default Applications]" >> ${DEFAULT_MIME_FILE}.new
# fi
# echo $2=$1 >> ${DEFAULT_MIME_FILE}.new
# mv ${DEFAULT_MIME_FILE}.new $DEFAULT_MIME_FILE
# }
#
# We do not need this defaults.list in Arch, because it is deprecated and out of current desktop spec.
# See this: https://specifications.freedesktop.org/mime-apps-spec/latest/
# This is from original script
# LIST_OF_USER_FILES=(
# "configs"
# "easyDCP"
# "logs"
# "Developer"
# "DolbyVision"
# "LUT"
# ".LUT"
# ".license"
# ".crashreport"
# "Resolve Disk Database"
# "Fairlight"
# "Media"
# )
#
# for file in "${LIST_OF_USER_FILES[@]}"; do
# mkdir -p -m 0775 "$INSTALL_DIR/$file"
# chown $USER_UID "$INSTALL_DIR/$file"
# done
# This is ours
# We will create dirs, to which dr wants to write and allow everybody to write there
# I have added only directories, that I am sure dr really wants to write to.
# If you notice that dr unable to write to some dir, please contact maintainer and he will add it to writable dirs.
LIST_OF_WRITABLE_DIRS=(
"configs" # needed
# "easyDCP"
"logs" # needed
# "Developer"
# "DolbyVision"
"LUT" # needed
".LUT" # needed
# ".license"
# ".crashreport"
"Resolve Disk Database" # needed
"Fairlight" # needed
"Media" # not necessary, but can be used
)
for dir in "${LIST_OF_WRITABLE_DIRS[@]}"; do
mkdir -m 0777 -p "${pkgdir}/opt/${_pkgname}/$dir"
done
# to actually watch what else files dr may create, we need to allow it to create files in install dir.
# chmod 777 "${pkgdir}/opt/${_pkgname}" # for maintainers
backup=( opt/resolve/configs/config.dat
opt/resolve/configs/log-conf.xml
opt/resolve/DolbyVision/config.bin )
# We will keep default configs in unwritable share for simplicity of restoring. See restore-opt-resolve.sh
cp "${INSTALL_DIR}"/share/default-config-linux.dat "${INSTALL_DIR}"/configs/config.dat
chmod 777 "${INSTALL_DIR}"/configs/config.dat # allow write to normal user
cp "${INSTALL_DIR}"/share/log-conf.xml "${INSTALL_DIR}"/configs/log-conf.xml
chmod 777 "${INSTALL_DIR}"/configs/log-conf.xml # allow write to normal user
mkdir "${INSTALL_DIR}"/DolbyVision
cp "${INSTALL_DIR}"/share/default_cm_config.bin "${INSTALL_DIR}"/DolbyVision/config.bin
chmod 777 "${INSTALL_DIR}"/DolbyVision/config.bin # allow write to normal user
# post_install.sh reimplementation end
# for simplicity of launching I'll create symlink
mkdir "${pkgdir}"/usr/bin/
ln -s "/opt/resolve/bin/resolve" "${pkgdir}"/usr/bin/davinci-resolve
# export BMD_PLUGIN_PATH=$CURRENT_DIR/libs/plugins # from AppRun, used by ./installer. Do not know its effect.
}
pre_install() {
# From pre_install.sh
# uninstall_legacy_bmdPanelDaemon()
# {
# # Uninstall BMD panel daemon
# SVC_NAME=bmdpaneld
#
# # Kill the daemon in case it is running
# killall -9 ${SVC_NAME}
#
# if [ -f /etc/init.d/${SVC_NAME} ]; then
# echo "#Uninstalling BMD panel service..."
# service ${SVC_NAME} stop
# /sbin/chkconfig --del ${SVC_NAME}
# rm -f /etc/init.d/${SVC_NAME}
# fi
# }
# uninstall_legacy_bmdPanelDaemon
#
# I've commented this out, in case such service could be provided by any package in Arch
# There is bmdpaneld file in /opt/resolve/bin/, but I do not know when it is invoked
# systemctl stop bmdpaneld
if [ -d "/opt/resolve" ]; then
echo "Setting 755 mode for /opt/resolve"
chmod 755 "/opt/resolve" # to deny renaming of writable dirs
fi
}
# post_install() {
# From post_install.sh install_mime_files()
# gtk-update-icon-cache "/usr/share/icons/hicolor" -f 2>&1 >> /dev/null # not needed, handled by pacman
# update-mime-database "/usr/share/mime/" 2>&1 >> /dev/null # not needed, handled by pacman
# udevadm control --reload-rules #2>&1 # not needed, handled by pacman
# udevadm trigger #2>&1 # # not needed, handled by pacman
# We do not need this, because usb permissions were already set in udev rules
# ensure_usb_permissions()
# {
# # Ensure panel permissions are correctly set for the current session
# DEVICES=`lsusb | grep "ID $1" | sed -e "s/:/ /g" | awk '{print"/dev/bus/usb/"$2"/"$4}'`
# for DEV in $DEVICES
# do
# echo "Fixing usb permissions for $DEV"
# chmod a+w $DEV
# done
# }
#
# ensure_usb_permissions "1edb"
# ensure_usb_permissions "096e"
# }
pre_upgrade() {
pre_install
}
# post_upgrade() {
# post_install
# }
#pre_remove() {
# do something here
#}
post_remove() {
# From uninstall.sh
# xdg-mime uninstall --novendor "${INSTALL_DIR}/share/resolve.xml" 2>&1 >> /dev/null # not needed, handled by pacman
# xdg-icon-resource uninstall --size 128 DaVinci-Resolve 2>&1 >> /dev/null # not needed, removed with package
# xdg-icon-resource uninstall --size 128 DaVinci-ResolveProj 2>&1 >> /dev/null # not needed, removed with package
# gtk-update-icon-cache "${SHARE_DIR}/icons/hicolor" -f 2>&1 >> /dev/null # not needed, handled by pacman
# update-mime-database "${SHARE_DIR}/mime/" 2>&1 >> /dev/null # not needed, handled by pacman
# Remove GPUCache dir, because it did not came with package. This is done in original uninstaller.
rm -rvf "/opt/resolve/GPUCache"
if [ -d "/opt/resolve" ]; then
echo "Setting 777 mode for /opt/resolve" # not possible in install file?
chmod 777 "/opt/resolve" # to allow to rm files from install dir
echo "You may need to remove /opt/resolve manually"
fi
}
#!/bin/bash
# Remove all user files, then restore default configs.
# Allows to get state of just installed package without actually reinstalling.
# For maintainers only, users do not need this file.
show_out_of_package_files() {
find -L /opt/resolve \( -type d -printf "%p/\n" , -type f -print \) | sort > /tmp/current-files.txt
# sort filelist.txt > filelist_sorted.txt
pacman -Ql davinci-resolve | grep "/opt/resolve" | sed -r 's/^davinci-resolve //' | sort > /tmp/package-files.txt
diff /tmp/package-files.txt /tmp/current-files.txt | grep -v "^[0-9c0-9]"
}
remove_out_of_package_files() {
for file in `show_out_of_package_files | grep "> " | sed -r 's/^> //'`
do
rm -rfv $file
done
}
remove_out_of_package_files
echo -e "Remaining out of package files:\n$(show_out_of_package_files)"
restore_configs() {
echo Restoring default configs
rm -v "/opt/resolve/configs/config.dat"
rm -v "/opt/resolve/configs/log-conf.xml"
rm -v "/opt/resolve/DolbyVision/config.bin"
# files will not be owned by root, but it does not matter
cp -v "/opt/resolve/share/default-config-linux.dat" "/opt/resolve/configs/config.dat"
cp -v "/opt/resolve/share/log-conf.xml" "/opt/resolve/configs/log-conf.xml"
cp -v "/opt/resolve/share/default_cm_config.bin" "/opt/resolve/DolbyVision/config.bin"
}
restore_configs
@ShayBox
Copy link

ShayBox commented Jan 10, 2019

Way too long and complex for something that is be easier to script than previously.

@Ashark
Copy link
Author

Ashark commented Jan 18, 2019

It repeats steps of the installer script except some things that pacman handles automatically.
Previous script was with errors and was done for other type of installer (it was sh, not it is run, which actually is appimage).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment