-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheos-optimus-manager-installer
executable file
·196 lines (162 loc) · 4.67 KB
/
eos-optimus-manager-installer
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
##### EXPERIMENTAL !!! ######
# Version: 2021.02.08-4
# Help installing optimus manager for Nvidia-Intel and Nvidia-AMD systems.
echo2() { echo "$@" >&2 ; }
DIE() {
echo2 "$progname: error: $1"
if [ -n "$tmpdir" ] && [ -d "$tmpdir" ] ; then
echo2 "Note: folder $tmpdir may contain useful debugging info."
fi
exit 1
}
STOP() {
echo2 "$progname: $1"
exit 0
}
source /usr/share/endeavouros/scripts/eos-script-lib-yad || DIE "no script lib found"
export -f eos_yad__detectDE
export -f eos_yad_GetDesktopName
Pushd() { pushd "$@" >/dev/null || DIE "'$FUNCNAME $*' failed" ; }
Popd() { popd "$@" >/dev/null ; }
IsInstalled() {
local pkg="$1"
pacman -Q "$pkg" >& /dev/null
}
InstallNeeded () {
local pkg="$1"
if (! IsInstalled "$pkg") ; then
sudo pacman -S "$pkg"
fi
}
CheckDM() {
local data=$(systemctl list-units)
local dm
for dm in sddm lightdm gdm ; do
if [ -n "$(echo "$data" | grep -w "$dm\.service" | grep -w running)" ] ; then
echo2 "DM: OK ($dm)"
return 0
fi
done
echo2 "Your Display Manager is not supported or does not exist."
echo2 "Please see: https://github.com/Askannz/optimus-manager how to proceed."
return 1
}
DetectGPUs() {
local data="$(device-info --graphics)" # lspci -vnn | grep -Pw '3D|Display|VGA'
local result
local nvidia=no
local intel=no
local amd=no
# Find what GPU hardware we have
[ -n "$(echo "$data" | grep -w NVIDIA)" ] && nvidia=yes
[ -n "$(echo "$data" | grep -w Intel)" ] && intel=yes
[ -n "$(echo "$data" | grep -w AMD)" ] && amd=yes
# Now check various GPU combinations
if [ "$nvidia" = "yes" ] ; then
result="nvidia"
[ "$intel" = "yes" ] && result+="-intel"
[ "$amd" = "yes" ] && result+="-amd"
echo "$result"
return
fi
if [ "$amd" = "yes" ] ; then
result="amd"
[ "$intel" = "yes" ] && result+="-intel"
echo result
return
fi
if [ "$intel" = "yes" ] ; then
echo "intel"
return
fi
echo "ERROR"
}
OptimusInstall_makepkg() {
local pkg pkgs
case "$DE" in
KDE | LXQT | DEEPIN)
pkgs=(python-py3nvml optimus-manager-git optimus-manager-qt-git) ;;
*)
pkgs=(optimus-manager) ;;
esac
for pkg in "${pkgs[@]}" ; do
yay -Ga $pkg || DIE "fetching the PKGBUILD of $pkg failed"
Pushd $pkg
if [ "$pkg" = "optimus-manager-qt-git" ] ; then
case "$DE" in
KDE) sed -i PKGBUILD -e 's|^_with_plasma=false$|_with_plasma=true|' ;; # only for KDE
esac
fi
makepkg -si || DIE "'makepkg -si' for $pkg failed"
Popd
done
}
OptimusInstall() {
local tmpdir=$(mktemp -d)
Pushd $tmpdir
OptimusInstall_makepkg
Popd
rm -rf $tmpdir
}
Options() {
local arg
for arg in "$@" ; do
case "$arg" in
--no-dm) do_dm_check=no ;;
--help | -h) cat <<EOF
Usage: $progname [options]
Options:
--help | -h This help.
--skip-dm Skip checking the Display Manager.
EOF
exit 0
;;
-*) DIE "unsupported option $arg" ;;
*) DIE "unsupported parameter $arg" ;;
esac
done
}
Main()
{
local progname="$(basename "$0")"
local do_dm_check=yes
Options "$@"
local DE=$(eos_yad_GetDesktopName)
local GPUs=$(DetectGPUs)
local prefix=""
if [ "$do_dm_check" = "yes" ] ; then
if (! CheckDM) ; then
Options --help
fi
fi
# Check if we have an optimus machine:
case "$GPUs" in
nvidia-intel | nvidia-amd)
nvidia-installer-check
case "$?" in
0) ;;
1) return 1 ;;
2) STOP "Your Nvidia card is supported by nvidia-390xx-dkms. Please install optimus-manager manually." ;;
esac
;;
*)
STOP "Optimus GPU cards (either 'NVIDIA + Intel' or 'NVIDIA + AMD') not detected."
;;
esac
# Optimus card hardware detected. Install optimus manager:
OptimusInstall
# Install GPU drivers:
case "$GPUs" in
nvidia-intel)
InstallNeeded nvidia-dkms
IsInstalled xf86-video-intel && prefix=un
echo2 "Note: if Intel video causes issues, ${prefix}installing xf86-video-intel may be needed."
;;
nvidia-amd)
InstallNeeded xf86-video-amdgpu
echo2 "Note: if AMD video does causes issues, consider installing xf86-video-ati instead of xf86-video-amdgpu."
;;
esac
}
Main "$@"