From f5d9c6d2c5193c1adb863e791a9361b6fa7236e7 Mon Sep 17 00:00:00 2001 From: Christian Colglazier Date: Mon, 24 Aug 2020 16:13:45 -0400 Subject: [PATCH] Resolve automatic install --- scripts/installers/bitwig-install.sh | 4 +- scripts/installers/blackmagic-parser.py | 42 ++++++++++++++++ scripts/installers/dragonframe-install.sh | 7 +-- scripts/installers/install-lib.sh | 19 +++++-- scripts/installers/resolve-install.sh | 61 +++++++++++++++++++++++ scripts/update.sh | 3 +- 6 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 scripts/installers/blackmagic-parser.py create mode 100644 scripts/installers/resolve-install.sh diff --git a/scripts/installers/bitwig-install.sh b/scripts/installers/bitwig-install.sh index 37a56d0..b4fea65 100644 --- a/scripts/installers/bitwig-install.sh +++ b/scripts/installers/bitwig-install.sh @@ -5,13 +5,15 @@ # Import library source $(dirname ${BASH_SOURCE[0]})/install-lib.sh -bitwig=$(dnf list | grep bitwig-studio) +bitwig=$(sudo dnf list | grep bitwig-studio) bitwigVersion=$(echo $bitwig | awk '{print $2;}'| filterVersion) url=$(curl -s https://www.bitwig.com/en/download.html | grep .deb | grep -Po '(?<=href=")[^"]*.deb') urlVersion=$(echo $url | awk -F "-" '{ print $3 }' | rev | cut -f 2- -d '.' | rev) checkUptoDate Bitwig $bitwigVersion $urlVersion +echo Installing Bitwig Studio $urlVersion + # Setting up and downloading package mkdir -p ~/Downloads/installers cd ~/Downloads/installers diff --git a/scripts/installers/blackmagic-parser.py b/scripts/installers/blackmagic-parser.py new file mode 100644 index 0000000..baa9da1 --- /dev/null +++ b/scripts/installers/blackmagic-parser.py @@ -0,0 +1,42 @@ +import json +import os +import urllib.request + +# getJSONData returns JSON data from Blackmagic Design's website. +def getJSONData(): + with urllib.request.urlopen('https://www.blackmagicdesign.com/api/support/us/downloads.json') as url: + return json.loads(url.read().decode()) + +# getDownloads() returns a list of downloads. +def getDownloads(): + return getJSONData()['downloads'] + +# getResolveStudioDownloads() returns a list of DaVinci Resolve Studio downlaods. +def getResolveStudioDownloads(): + return [d for d in getDownloads() if 'davinci-resolve-and-fusion' in d['relatedFamilies'][0] and + 'Studio' in d['name'] and 'Resolve' in d['name']] + +# filterOnlyLinuxSupport() filters a list of downloads to only ones that +# support Linux. +def filterOnlyLinuxSupport(downloads): + return [d for d in downloads if 'Linux' in d['platforms']] + +# getLinuxURL() returns the Linux download info. +def getLinuxURL(download): + return download['urls']['Linux'][0] + +# getURLId() returns the download id. +def getURLId(url): + return url['downloadId'] + +# getURLVersion() returns the url version number. +def getURLVersion(url): + return '{}.{}.{}'.format(url['major'], url['minor'], url['releaseNum']) + +# getDownloadId() returns downlaod id hash. +def getDownloadId(download): + return download['id'] + +for d in filterOnlyLinuxSupport(getResolveStudioDownloads()): + linux = getLinuxURL(d) + print(getURLVersion(linux), getURLId(linux), getDownloadId(d)) diff --git a/scripts/installers/dragonframe-install.sh b/scripts/installers/dragonframe-install.sh index f8daa3e..bb187b9 100644 --- a/scripts/installers/dragonframe-install.sh +++ b/scripts/installers/dragonframe-install.sh @@ -5,16 +5,13 @@ # Import library source $(dirname ${BASH_SOURCE[0]})/install-lib.sh -dragonframe=$(dnf list | grep dragonframe) +dragonframe=$(sudo dnf list | grep dragonframe) dragonframeVersion=$(echo $dragonframe | awk '{print $2;}') url=$(curl -s https://www.dragonframe.com/downloads/ | grep .rpm | grep downloadButton | grep -Po '(?<=href=")[^"]*.rpm') urlVersion=$(echo $url | awk -F "-" '{ print $2 }') # Check if installed to the most recent version -if versionGreater $dragonframeVersion $urlVersion; then - echo Dragonframe is up to date. Installed version $dragonframeVersion Web version $urlVersion - exit -fi +checkUptoDate dragonframe $dragonframeVersion $urlVersion echo Installing Dragonframe $urlVersion # Setting up and downloading package diff --git a/scripts/installers/install-lib.sh b/scripts/installers/install-lib.sh index 5ca664c..fcfff47 100644 --- a/scripts/installers/install-lib.sh +++ b/scripts/installers/install-lib.sh @@ -1,4 +1,4 @@ -# Program version number comparison +# Program version number comparison. function versionGreater() { if [[ $1 == $2 ]];then return 0 @@ -24,14 +24,25 @@ function versionGreater() { return 0 } -# Check if installed to the most recent version +# Check if installed to the most recent version. function checkUptoDate() { if versionGreater $2 $3; then - echo $1 is up to date. Installed version $2 Web version $3 + echo $1 is up to date. Installed version $2 web version $3 exit + else + echo Updating $1 from $2 to $3... fi } +# Filters string to Semantic Versioning. function filterVersion() { - grep -Go [0-9]\.[0-9]\.[0-9] + grep -Po -m 1 '\d{1,4}\.\d{1,4}\.\d{1,4}' +} + +# Downloads a file to the given download directory with +# the given name. +function downloadPackage() { + mkdir -p ~/Downloads/installers/$1 + cd ~/Downloads/installers/$1 + wget -O $3 $2 } diff --git a/scripts/installers/resolve-install.sh b/scripts/installers/resolve-install.sh new file mode 100644 index 0000000..0ad108b --- /dev/null +++ b/scripts/installers/resolve-install.sh @@ -0,0 +1,61 @@ +#! /bin/bash + +# Automatic install script for DaVinci Resolve + +# Import library +source $(dirname ${BASH_SOURCE[0]})/install-lib.sh + +resolveVersion=$(cat /opt/resolve/docs/ReadMe.html | grep 'DaVinci Resolve Studio' | filterVersion) +url=$(python $(dirname ${BASH_SOURCE[0]})/blackmagic-parser.py | head -n 1) +urlVersion=$(echo $url | awk '{print $1;}') +downloadID=$(echo $url | awk '{print $2;}') +referId=$(echo $url | awk '{print $3;}') +packageName="DaVinci_Resolve_Studio_${urlVersion}.zip" + +checkUptoDate Resolve $resolveVersion $urlVersion + +downloadUrl="https://www.blackmagicdesign.com/api/register/us/download/${downloadID}" +useragent="User-Agent: Mozilla/5.0 (X11; Linux) \ + AppleWebKit/537.36 (KHTML, like Gecko) \ + Chrome/77.0.3865.75 \ + Safari/537.36" +reqjson="{ \ + \"firstname\": \"Fedora\", \ + \"lastname\": \"Linux\", \ + \"email\": \"user@getfedora.org\", \ + \"phone\": \"919-555-7428\", \ + \"country\": \"us\", \ + \"state\": \"North Carolina\", \ + \"city\": \"Raleigh\", \ + \"product\": \"DaVinci Resolve\" \ +}" +zipUrl="$(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-ascii "$reqjson" \ + --compressed \ + "$downloadUrl")" + +# Setting up and downloading package +downloadPackage resolve $zipUrl $packageName + +# Installing package +sudo dnf install libxcrypt-compat +unzip -o $packageName +sudo ./*16.2.5*.run -i -y + +# Graphics card fix +sudo rm /etc/OpenCL/vendors/mesa.icd +sudo rm /etc/OpenCL/vendors/pocl.icd + +# Keyboard mapping fix +setxkbmap -option 'caps:super' diff --git a/scripts/update.sh b/scripts/update.sh index 77c67ad..148f316 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -30,7 +30,7 @@ function flatpakUpdate { # Checks if a program is installed and if it is runs an updater script function updateProgram { if command -v $1 &> /dev/null; then - sudo sh $2 + sh $2 fi } @@ -41,6 +41,7 @@ function manualUpdate { updateProgram bitwig-studio ~/.config/scripts/installers/bitwig-install.sh updateProgram dragonframe ~/.config/scripts/installers/dragonframe-install.sh updateProgram reaper ~/.config/scripts/installers/reaper-install.sh + updateProgram /opt/resolve/bin/resolve ~/.config/scripts/installers/resolve-install.sh fi }