File: //opt/resolve/scripts/post_install.sh
#!/bin/bash
# Post install script for Resolve
# Installer will replace PRODUCT_INSTALL_LOCATION with actual install path
INSTALL_DIR="PRODUCT_INSTALL_LOCATION"
COMMON_DATA_DIR="/var/BlackmagicDesign/DaVinci Resolve"
DVP_RULES=/usr/lib/udev/rules.d/75-davincipanel.rules
DVK_RULES=/usr/lib/udev/rules.d/75-davincikb.rules
SDX_RULES=/usr/lib/udev/rules.d/75-sdx.rules
RESOLVE_APP_NAME=com.blackmagicdesign.resolve
DBUS_SERVICE_DIR=/usr/share/dbus-1/services
if [[ $EUID -ne 0 ]]; then
# Script being run as non-root user
USER_UID=$EUID
else
# Script being run as root
USER_UID=$SUDO_UID
if [ -z "$USER_UID" ]; then
USER_UID=$PKEXEC_UID
fi
if [ -z "$USER_UID" ]; then
USER_UID=0
fi
fi
USER_HOME=`awk -v val=$USER_UID -F ":" '\$3==val{print \$6;exit}' /etc/passwd`
if [[ "${1}" == "--install-plugin" ]]; then
INSTALL_PLUGIN="1"
else
INSTALL_PLUGIN="0"
fi
install_patched_shortcuts()
{
sed -e "s:RESOLVE_INSTALL_LOCATION:${INSTALL_DIR}:g" "$1" > "$2"
chmod +x "$2"
}
install_user_file()
{
cp "$1" "$2"
chown $USER_UID "$2"
}
# 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
}
install_desktop_shortcut()
{
# Install desktop shortcut
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.desktop" ${USER_HOME}/Desktop/${RESOLVE_APP_NAME}.desktop
# set permissions
chown ${USER_UID} "${USER_HOME}/Desktop/${RESOLVE_APP_NAME}.desktop"
}
uninstall_old_files()
{
# Remove older version of Resolve if installed
LIST_OF_OLD_FILES=(
"${USER_HOME}/Desktop/DaVinci Resolve.desktop"
"${USER_HOME}/.config/menus/applications.menu"
"${USER_HOME}/.local/share/applications/DaVinci Resolve.desktop"
"${USER_HOME}/.local/share/applications/DaVinci Resolve Stop.desktop"
)
if [[ $EUID -eq 0 ]]; then
LIST_OF_OLD_FILES+=("/usr/share/applications/DaVinci Resolve.desktop")
fi
echo "Removing obsolete files"
for file in "${LIST_OF_OLD_FILES[@]}"; do
rm -vf "${file}"
done
}
install_app_shortcuts()
{
if [[ $EUID -ne 0 ]]; then
# Create a few dirs that may be missing
mkdir -p "${USER_HOME}/.config/menus/"
mkdir -p "${USER_HOME}/.local/share/applications"
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.desktop" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolveInstaller.desktop" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}-Installer.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolveCaptureLogs.desktop" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}-CaptureLogs.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciControlPanelsSetup.desktop" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}-Panels.desktop
# install the raw player and speed test
install_patched_shortcuts "${INSTALL_DIR}/share/blackmagicraw-player.desktop" ${USER_HOME}/.local/share/applications/com.blackmagicdesign.rawplayer.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/blackmagicraw-speedtest.desktop" ${USER_HOME}/.local/share/applications/com.blackmagicdesign.rawspeedtest.desktop
if [ -f "${INSTALL_DIR}/share/DaVinciRemoteMonitoring.desktop" ]; then
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciRemoteMonitoring.desktop" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}-DaVinciRemoteMonitoring.desktop
fi
if [ -e "${USER_HOME}/.config/menus/applications-merged" ]; then
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.menu" ${USER_HOME}/.config/menus/applications-merged/${RESOLVE_APP_NAME}.menu
else
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.menu" ${USER_HOME}/.config/menus/${RESOLVE_APP_NAME}.menu
fi
else
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.desktop" /usr/share/applications/${RESOLVE_APP_NAME}.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolveInstaller.desktop" /usr/share/applications/${RESOLVE_APP_NAME}-Installer.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolveCaptureLogs.desktop" /usr/share/applications/${RESOLVE_APP_NAME}-CaptureLogs.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciControlPanelsSetup.desktop" /usr/share/applications/${RESOLVE_APP_NAME}-Panels.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.directory" /usr/share/desktop-directories/${RESOLVE_APP_NAME}.directory
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciResolve.menu" /etc/xdg/menus/applications-merged/${RESOLVE_APP_NAME}.menu
# install the raw player and speed test
install_patched_shortcuts "${INSTALL_DIR}/share/blackmagicraw-player.desktop" /usr/share/applications/com.blackmagicdesign.rawplayer.desktop
install_patched_shortcuts "${INSTALL_DIR}/share/blackmagicraw-speedtest.desktop" /usr/share/applications/com.blackmagicdesign.rawspeedtest.desktop
if [ -f "${INSTALL_DIR}/share/DaVinciRemoteMonitoring.desktop" ]; then
install_patched_shortcuts "${INSTALL_DIR}/share/DaVinciRemoteMonitoring.desktop" /usr/share/applications/${RESOLVE_APP_NAME}-DaVinciRemoteMonitoring.desktop
fi
fi
}
install_mime_files()
{
if [[ $EUID -eq 0 ]]; then
SHARE_DIR=/usr/share
else
SHARE_DIR="${USER_HOME}/.local/share"
fi
echo "Installing Application icons"
xdg-icon-resource install --size 64 "${INSTALL_DIR}/graphics/DV_Resolve.png" DaVinci-Resolve 2>&1 >> /dev/null
xdg-icon-resource install --size 64 "${INSTALL_DIR}/graphics/DV_ResolveProj.png" DaVinci-ResolveProj 2>&1 >> /dev/null
xdg-icon-resource install --size 64 "${INSTALL_DIR}/graphics/DV_ServerAccess.png" DaVinci-ResolveDbKey 2>&1 >> /dev/null
xdg-icon-resource install --size 48 "${INSTALL_DIR}/graphics/blackmagicraw-player_48x48_apps.png" blackmagicraw-player 2>&1 >> /dev/null
xdg-icon-resource install --size 48 "${INSTALL_DIR}/graphics/blackmagicraw-speedtest_48x48_apps.png" blackmagicraw-speedtest 2>&1 >> /dev/null
xdg-icon-resource install --size 48 --context mimetypes "${INSTALL_DIR}/graphics/application-x-braw-clip_48x48_mimetypes.png" application-x-braw-clip 2>&1 >> /dev/null
xdg-icon-resource install --size 48 --context mimetypes "${INSTALL_DIR}/graphics/application-x-braw-sidecar_48x48_mimetypes.png" application-x-braw-sidecar 2>&1 >> /dev/null
xdg-icon-resource install --size 256 "${INSTALL_DIR}/graphics/blackmagicraw-player_256x256_apps.png" blackmagicraw-player 2>&1 >> /dev/null
xdg-icon-resource install --size 256 "${INSTALL_DIR}/graphics/blackmagicraw-speedtest_256x256_apps.png" blackmagicraw-speedtest 2>&1 >> /dev/null
xdg-icon-resource install --size 256 --context mimetypes "${INSTALL_DIR}/graphics/application-x-braw-clip_256x256_mimetypes.png" application-x-braw-clip 2>&1 >> /dev/null
xdg-icon-resource install --size 256 --context mimetypes "${INSTALL_DIR}/graphics/application-x-braw-sidecar_256x256_mimetypes.png" application-x-braw-sidecar 2>&1 >> /dev/null
xdg-icon-resource install --size 64 --context mimetypes "${INSTALL_DIR}/graphics/DV_ResolveBin.png" application-x-resolvebin 2>&1 >> /dev/null
xdg-icon-resource install --size 64 --context mimetypes "${INSTALL_DIR}/graphics/DV_ResolveProj.png" application-x-resolveproj 2>&1 >> /dev/null
xdg-icon-resource install --size 64 --context mimetypes "${INSTALL_DIR}/graphics/DV_ResolveTimeline.png" application-x-resolvetimeline 2>&1 >> /dev/null
xdg-icon-resource install --size 64 --context mimetypes "${INSTALL_DIR}/graphics/DV_ServerAccess.png" application-x-resolvedbkey 2>&1 >> /dev/null
xdg-icon-resource install --size 64 --context mimetypes "${INSTALL_DIR}/graphics/DV_TemplateBundle.png" application-x-resolvetemplatebundle 2>&1 >> /dev/null
xdg-mime install --novendor "${INSTALL_DIR}/share/resolve.xml" 2>&1 >> /dev/null
xdg-mime install --novendor "${INSTALL_DIR}/share/blackmagicraw.xml" 2>&1 >> /dev/null
echo "Updating icon cache"
gtk-update-icon-cache "${SHARE_DIR}/icons/hicolor" -f 2>&1 >> /dev/null
update-mime-database "${SHARE_DIR}/mime/" 2>&1 >> /dev/null
# Running update-mime-database will sometime ruin the permissions of mime dir
chmod -R go+r "${SHARE_DIR}/mime/" 2>&1 >> /dev/null
}
create_config_files()
{
LIST_OF_USER_FILES=(
"easyDCP"
"LUT"
".license")
for file in "${LIST_OF_USER_FILES[@]}"; do
mkdir -p -m 0775 "$INSTALL_DIR/$file"
chown $USER_UID "$INSTALL_DIR/$file"
done
if [ ! -d "$COMMON_DATA_DIR" ]; then
echo "Creating Common Data Dir : $COMMON_DATA_DIR"
mkdir -p -m 0777 "$COMMON_DATA_DIR" 2>&1
else
echo "Using a pre-existing Data dir : $COMMON_DATA_DIR"
chmod 0777 "$COMMON_DATA_DIR" 2>&1
fi
}
install_dvpanel_libs()
{
echo "Setting up dvpanels"
PANEL_DRIVER_DIR=/usr/lib64
# Some of the modern distros dont use lib64 anymore, just /usr/lib
if [ ! -e "$PANEL_DRIVER_DIR" ];then
PANEL_DRIVER_DIR=/usr/lib
fi
tar -xvf "${INSTALL_DIR}/share/panels/dvpanel-framework-linux-x86_64.tgz" -C "${PANEL_DRIVER_DIR}"
}
install_resolve_plugin()
{
PLUGIN_SRC="${INSTALL_DIR}/share/DaVinci Resolve Renderer.ofx.bundle"
if [[ -d "${PLUGIN_SRC}" ]]; then
echo "Setting up Resolve Plugin"
mkdir -p /usr/OFX/Plugins
PLUGIN_DST="/usr/OFX/Plugins/DaVinci Resolve Renderer.ofx.bundle"
rm -rf "${PLUGIN_DST}"
cp -a "${PLUGIN_SRC}" "${PLUGIN_DST}"
rm -rf "${PLUGIN_SRC}"
fi
}
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
}
install_udev_rules()
{
echo "Installing udev rules"
cat ${INSTALL_DIR}/share/etc/udev/rules.d/99-BlackmagicDevices.rules > $DVP_RULES
echo 'KERNEL=="hidraw*", SUBSYSTEM=="hidraw", MODE="0777", GROUP="resolve"' >> $DVP_RULES
cat ${INSTALL_DIR}/share/etc/udev/rules.d/99-ResolveKeyboardHID.rules > $DVK_RULES
echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="096e", MODE="0666"' > $SDX_RULES
# reload the udev rules
udevadm control --reload-rules 2>&1
udevadm trigger 2>&1
ensure_usb_permissions "1edb"
ensure_usb_permissions "096e"
}
fix_file_ownership()
{
# Fix the file ownership if installing as SuperUser on a DVD install
echo "Fixing file ownership"
while IFS= read -r file || [[ -n "${file}" ]]; do
#set the file ownership same as /home/resolve
chown --reference=${INSTALL_DIR} "${INSTALL_DIR}/${file}"
done < "${INSTALL_DIR}/filelist.txt"
}
restart_panel_daemon()
{
# If the BMD panel daemon is running, restart it. The new Resolve binary might have updated graphics.
# NOTE: This must be the LAST step as this may need to reboot the system in case a firmware update is needed.
service bmdpaneld status | grep "bmdpaneld is running..." >& /dev/null
if [ $? -eq 0 ]
then
echo "Restarting BMDPanelDaemon"
sh ${INSTALL_DIR}/.kde/Autostart/StartBMDPanelDaemon
fi
}
remove_dph()
{
DPH_SERVICE_FILE="/etc/rc.d/init.d/dph"
# Remove the old files
if [ -f ${DPH_SERVICE_FILE} ]; then
# Disable the service
chkconfig --del dph >& /dev/null
${DPH_SERVICE_FILE} stop
rm -f ${DPH_SERVICE_FILE}
fi
}
fixup_dvd_install()
{
fix_file_ownership
# move the scripts to Cyclone dir
mv -vf ${INSTALL_DIR}/scripts/script* ${INSTALL_DIR}/Cyclone
# move the User Manual
mv -vf ${INSTALL_DIR}/docs/DaVinci_Resolve_Manual.pdf ${INSTALL_DIR}/Cyclone
# Remove old DPH service
remove_dph
if [[ $EUID -eq 0 ]]; then
# Update the BMD panel daemon
echo "Installing Panel Daemon"
# Create the Autostart dir before installing PanelDaemon
mkdir -p "${INSTALL_DIR}/.kde/Autostart"
sh ${INSTALL_DIR}/share/panels/BMDPanelDaemon.sh --nox11
# Fixup the CaptureLogs application path
sed -i -e "s:${INSTALL_DIR}/scripts:${INSTALL_DIR}/Cyclone:g" /usr/share/applications/${RESOLVE_APP_NAME}-CaptureLogs.desktop
# Do this last as we may need to reboot the system in case a firmware update is needed.
restart_panel_daemon
else
# Fixup the CaptureLogs application path
sed -i -e "s:${INSTALL_DIR}/scripts:${INSTALL_DIR}/Cyclone:g" ${USER_HOME}/.local/share/applications/${RESOLVE_APP_NAME}-CaptureLogs.desktop
fi
}
#Actual entry point of the script
echo "#Doing post-install"
uninstall_old_files
install_desktop_shortcut
install_app_shortcuts
install_mime_files
if [[ $EUID -eq 0 ]]; then
install_udev_rules
install_dvpanel_libs
if [[ "${INSTALL_PLUGIN}" == "1" ]]; then
install_resolve_plugin
fi
# We install the default app associations here, because xdg-mime is buggy in centos6
install_default_application ${RESOLVE_APP_NAME}.desktop application/x-resolveproj
install_default_application ${RESOLVE_APP_NAME}.desktop application/x-resolvebin
install_default_application ${RESOLVE_APP_NAME}.desktop application/x-resolvetimeline
install_default_application ${RESOLVE_APP_NAME}.desktop application/x-resolvetemplatebundle
fi
create_config_files
if [[ ${INSTALL_DIR} == /home/resolve* ]]; then
fixup_dvd_install
else
# no need to change install dir permission for DVD installs
chmod 0755 "${INSTALL_DIR}"
fi
echo "DaVinci Resolve installed to ${INSTALL_DIR}"
exit 0