-
Notifications
You must be signed in to change notification settings - Fork 0
/
dock-egpu
executable file
·76 lines (56 loc) · 1.4 KB
/
dock-egpu
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
#!/bin/bash
set -e
#Functions
function getGpus() {
gpus="$(lspci | grep -i "vga")";
gpuCount=0;
while IFS= read -r line; do
gpuCount=$((gpuCount+1))
echo "[$gpuCount] $line"
done <<< "$gpus"
}
function setupXorg() {
sudo cp $XORG_EGPU_SOURCE $XORG_MAIN_SOURCE;
SOURCE_SIZE=$(stat -c%s $1)
DEST_SIZE=$(stat -c%s $2)
if [[ "$SOURCE_SIZE" -eq "$DEST_SIZE" ]]
then
echo "configured";
fi;
}
#Variables
XORG_MAIN_SOURCE="/etc/X11/xorg.conf";
XORG_EGPU_SOURCE="/etc/X11/xorg.conf.egpu";
echo -e "Listing gpus...\n";
echo -e "$(getGpus)\n";
read -p "Is your eGPU listed? [y/n]:" ans
if [[ "$ans" =~ ^[Yy]$ ]]
then
echo -e "Activating eGPU...\n";
sudo prime-select nvidia;
sleep 0.5s;
echo -e "Creating xorg.conf file...\n";
xorg_status="$(setupXorg $XORG_MAIN_SOURCE $XORG_EGPU_SOURCE)";
if [ $xorg_status == "configured" ]; then
echo -e "Xorg configured successfully!\n";
LOGOUT_DEFAULT_ANS="yes"
read -p "A session refresh is required. Do you wish to logout now? (yes): " LOGOUT_ANS
LOGOUT_ANS=${LOGOUT_ANS:-$LOGOUT_DEFAULT_ANS}
echo ""
if [[ "$LOGOUT_ANS" =~ [Yesyes]$ ]]; then
echo -e "Logging current user out of session..."
sleep 2.0s;
USR=$USER;
pkill -KILL -u $USR
else
echo -e "Exiting...";
exit 0;
fi;
else
echo "There was an error configuring the xorg.conf file";
exit 0;
fi
else
echo "Exiting...";
exit 0;
fi;