forked from pavolelsig/L-G_helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlg.sh
108 lines (85 loc) · 3.23 KB
/
lg.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
#!/bin/bash
#This is based on Looking Glass quickstart guide:
#https://looking-glass.hostfission.com/wiki/Installation
#Fedora selinux issues resolved thanks to:
#https://forum.level1techs.com/t/vfio-in-2019-fedora-workstation-general-guide-though-branch-draft/145106/41
#Making sure that the looking glass folder is present
if ! [ -d looking*/client ]
then
echo "Please copy the Looking Glass folder into this folder"
exit
fi
#Making sure this script runs with elevated privileges
if [ $(id -u) -ne 0 ]
then
echo "Please run this as root!"
exit 1
fi
#Installing required packages for each distro
DISTRO=`cat /etc/*release | grep DISTRIB_ID | cut -d '=' -f 2`
FEDORA=`cat /etc/*release | head -n 1 | cut -d ' ' -f 1`
if [ "$DISTRO" == "Ubuntu" ] || [ "$DISTRO" == "Pop" ] || [ "$DISTRO" == "LinuxMint" ]
then
apt-get install binutils-dev cmake fonts-freefont-ttf libsdl2-dev libsdl2-ttf-dev libspice-protocol-dev libfontconfig1-dev libx11-dev nettle-dev wayland-protocols -y
elif [ "$DISTRO" == "ManjaroLinux" ]
then
pacman -Syu binutils sdl2 sdl2_ttf libx11 nettle fontconfig cmake spice-protocol make pkg-config gcc gnu-free-fonts
elif [ "$FEDORA" == "Fedora" ]
then
dnf install make cmake binutils-devel SDL2-devel SDL2_ttf-devel nettle-devel spice-protocol fontconfig-devel libX11-devel egl-wayland-devel wayland-devel mesa-libGLU-devel mesa-libGLES-devel mesa-libGL-devel mesa-libEGL-devel libXfixes-devel libXi-devel
else
echo "This script does not support your current distribution. Only Fedora, Manjaro, PopOS and Ubuntu are supported!"
echo "You can still install Looking Glass manually!"
exit
fi
VIRT_USER=`logname`
#Identifying user to set permissions
echo
echo "User: $VIRT_USER will be using Looking Glass on this PC. "
echo "If that's correct, press (y) otherwise press (n) and you will be able to specify the user."
echo
echo "y/n?"
read USER_YN
#Allowing the user to manually edit the Looking Glass user
if [ $USER_YN = 'n' ] || [ $USER_YN = 'N' ]
then
USER_YN='n'
while [ '$USER_YN' = "n" ]; do
echo "Enter the new username: "
read VIRT_USER
echo "Is $VIRT_USER correct (y/n)?"
read USER_YN
done
fi
echo User $VIRT_USER selected. Press any key to continue:
read ANY_KEY
# Looking Glass requirements: /dev/shm/looking_glass needs to be created on startup
echo "touch /dev/shm/looking-glass && chown $VIRT_USER:kvm /dev/shm/looking-glass && chmod 660 /dev/shm/looking-glass" > lg_start.sh
#Create a systemd service to initialize the GPU on startup
cp lg_start.service /etc/systemd/system/lg_start.service
chmod 644 /etc/systemd/system/lg_start.service
mv lg_start.sh /usr/bin/lg_start.sh
chmod +x /usr/bin/lg_start.sh
systemctl enable lg_start.service
systemctl start lg_start.service
if [ -a looking*.tar.gz ]
then
mv looking*.tar.gz tar_lg.tar.gz
fi
#Compiling Looking Glass
cd looking*
mkdir client/build
cd client/build
cmake ../
make
chown $VIRT_USER looking-glass-client
#SELinux on Fedora prevents it from working
if [ "$FEDORA" == "Fedora" ]
then
echo "Please be patient"
sudo ausearch -c 'qemu-system-x86' --raw | audit2allow -M my-qemusystemx86
sudo semodule -X 300 -i my-qemusystemx86.pp
sudo setsebool -P domain_can_mmap_files 1
else
echo " /dev/shm/looking-glass rw," >> /etc/apparmor.d/abstractions/libvirt-qemu
fi