File: //opt/resolve/scripts/pre_install.sh
#!/bin/bash
# Installer will replace PRODUCT_INSTALL_LOCATION with actual install path
INSTALL_DIR="PRODUCT_INSTALL_LOCATION"
USER_UID=$SUDO_UID
if [ -z "$USER_UID" ]; then
USER_UID=$PKEXEC_UID
fi
if [ -z "$USER_UID" ]; then
USER_UID=0
fi
USER_HOME=`awk -v val=$USER_UID -F ":" '\$3==val{print \$6;exit}' /etc/passwd`
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
}
remove_old_dirs()
{
DIRS_TO_REMOVE=(
"Onboarding"
"bin"
"libs"
"plugins"
"UI_Resource"
"DaVinci Control Panels Setup"
"DaVinci Resolve Panels Setup")
if [[ -d ${INSTALL_DIR} ]]; then
echo "Removing old files"
for dir in "${DIRS_TO_REMOVE[@]}"; do
rm -rf "$INSTALL_DIR/$dir"
done
fi
}
# Entry for pre_install script
#Note: The installer copies the files as normal user,
#make sure the set the permission while making the target dir
# Add system info to log
echo -e "#Starting DaVinci Resolve install"
uname -a
echo "Install Location : $INSTALL_DIR "
echo "User ID: $USER_UID "
echo "User Home: $USER_HOME"
if [[ $EUID -ne 0 ]]; then
# Starting install as non-root user
mkdir -p "$INSTALL_DIR"
exit 0
fi
remove_old_dirs
if [[ -d ${INSTALL_DIR} && ${INSTALL_DIR} == /home/resolve* ]]; then
chown $USER_UID "$INSTALL_DIR"
else
# Uninstall the panel daemon only on Standalone install
uninstall_legacy_bmdPanelDaemon
mkdir -m 0775 -p "$INSTALL_DIR"
chown $USER_UID "$INSTALL_DIR" -R
fi
exit 0