-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.sh
executable file
·135 lines (121 loc) · 4.13 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
container_type=""
container_create_prefix=""
container_run_prefix=""
davincibox_flavor=""
installer_path=""
nvidia_gpu=false
valid_installer=false
set_container_type () {
container_manager=$1
if [[ $container_manager == "toolbox" ]]; then
echo "Toolbox found."
container_type="toolbox"
container_create_prefix="toolbox create -c davincibox"
container_run_prefix="toolbox run --container davincibox"
elif [[ $container_manager == "distrobox" ]]; then
echo "Distrobox found."
container_type="distrobox"
container_create_prefix="distrobox create -n davincibox"
container_run_prefix="distrobox enter davincibox --"
fi
}
get_gpu_type () {
if command -v lshw &> /dev/null; then
if lshw -c video 2>/dev/null | grep -qi "driver=nvidia"; then
echo "Nvidia GPU detected."
nvidia_gpu=true
davincibox_flavor="davincibox"
else
echo "No NVIDIA GPU detected. Using OpenCL"
nvidia_gpu=false
davincibox_flavor="davincibox-opencl"
fi
else
echo "WARNING: lshw not found. Could not determine GPU vendor."
nvidia_gpu=false
davincibox_flavor="davincibox-opencl"
fi
}
check_davinci_installer () {
installer=$1
if [[ ! -f $installer ]]; then
echo "$1 is not a valid filename."
echo "Re-run this script with a valid DaVinci Resolve installer."
echo "e.g. ./setup.sh DaVinci_Resolve_18.5.1_Linux.run"
valid_installer=false
else
valid_installer=true
fi
}
run_davinci_setup () {
installer=$1
# Extract DaVinci installer
echo "Extracting ${installer} ..."
$installer --appimage-extract
if [[ $? -eq 0 ]]; then
# Run setup-davinci
extracted_installer="squashfs-root/AppRun"
$container_run_prefix setup-davinci $extracted_installer $container_type
rm -rf squashfs-root/
else
echo "${installer} could not be extracted."
echo "Please double-check that it is a valid DaVinci Resolve installer."
exit
fi
}
create_davincibox_container () {
echo "Setting up $davincibox_flavor..."
# Do this separately here to ensure the latest image is present
# before the container is created.
# See https://github.com/zelikos/davincibox/issues/26#issuecomment-1850642631
podman image pull "ghcr.io/zelikos/$davincibox_flavor:latest"
$container_create_prefix -i "ghcr.io/zelikos/$davincibox_flavor:latest"
# Ensure packages are up-to-date in case of old container build
$container_run_prefix sudo dnf -y update
$container_run_prefix echo "davincibox initialized"
}
remove_davincibox_container () {
podman container stop davincibox
podman container rm davincibox
echo "davincibox removed."
}
# Check if distrobox is installed
if ! command -v distrobox &> /dev/null; then
# If no distrobox, check for toolbox
echo "Distrobox not found. Checking for toolbox..."
if ! command -v toolbox &> /dev/null; then
echo "Toolbox not found."
# If neither are installed, inform the user, then exit
echo "Please install either distrobox or toolbox to use this script."
exit
else
set_container_type "toolbox"
fi
else
set_container_type "distrobox"
get_gpu_type
if [[ $nvidia_gpu == true ]]; then
container_create_prefix+=" --nvidia"
fi
fi
if [[ $1 == "remove" ]]; then
$container_run_prefix add-davinci-launcher remove
echo "Removing DaVinci Resolve and davincibox..."
remove_davincibox_container
elif [[ $1 == "upgrade" ]]; then
echo "Removing davincibox container..."
remove_davincibox_container
echo "To complete the upgrade, re-run this setup script"
echo "as you would for a fresh installation."
echo "e.g. ./setup.sh DaVinci_Resolve_18.5.1_Linux.run"
else
installer_path=$(readlink -e $1)
# Create davincibox container on user's system
create_davincibox_container
# Check that provided installer path is valid
check_davinci_installer $installer_path
if [[ $valid_installer == true ]]; then
run_davinci_setup $installer_path
fi
fi