-
Notifications
You must be signed in to change notification settings - Fork 1
/
deepin_nvidia_install_2.sh
156 lines (130 loc) · 5.54 KB
/
deepin_nvidia_install_2.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# 请将这个文件的文件名字命名为 deepin_nvidia_install_2.sh
# 安装说明
# 重要!!!!首先需要通过tty非图形界面执行代码,而非在平常的图形界面运行代码
# 进入非图形界面快捷键是 ctrl + shift + f3, 需要你重新登陆以下你的用户
# 然后让terminal进入当前有这个script的文件夹
# 如果是laptop双显卡(intel和nvidia), 则在terminal输入 bash ./deepin_nvidia_install_2.sh laptop
# 如果是电脑(单显卡nvidia,且nvidia 显卡为10,20或30系),则直接 bash ./deepin_nvidia_install_2.sh
# 查看是不是在tty下面跑的
TTY=`tty`
case $TTY in
"/dev/tty2" | "/dev/tty3" | "/dev/tty4" | "/dev/tty5" | "/dev/tty6") echo 'running in TTY'
;;
*) echo -e "请重新进入TTY非图形化的界面,自动退出脚本\n"; exit
;;
esac
# -------------------------------------------------------------------------------------------------------------
# SIGINT is when you press ctrl+C, trap it and exit
# trap single quote, only analyse the command when triggered
trap 'catch INT signal\n"; exit' SIGINT SIGTERM
# kill 0 will send SIGINT signal to all group process, but kill 0 is dangerous!
trap 'echo "catch EXIT signal\n"; kill $beatpid ' EXIT
# ----------------------------------- sudo beat ---------------------------------------
# get sudo and || means only if sudo -v fails, it will run the second command, $? means get the signal from the previous command
sudo -v || exit $?
# just wait for a while so that the credential is saved in cache
sleep 1
# while loop
{
# save child pid
echo "child process is $BASHPID"
echo "$BASHPID" >"/tmp/tempsudobeat-$(date +%Y-%m-%d)-$$.txt"
while true; do
echo "sudo beat! BOOM!"
# -n means if require password then directly exit, -v means extend sudo timeout
sudo -n -v
sleep 30
done
} &
# let sudo beat child process to warm up
sleep 3
read beatpid <"/tmp/tempsudobeat-$(date +%Y-%m-%d)-$$.txt"
# --------------------------------------------- sudobeat ---------------------------------------------
# 以上是为了保持在安装过程中一直有sudo权限,以下才是 nvidia 显卡驱动安装代码的主体
# 检测 是否是laptop 模式
if [[ -n "$1" && "$1" == "laptop" ]]; then
echo "runing laptop mode"
else
echo "what mode you want to run?"
echo "1:laptop,intel and nvidia gpu card"
echo "2:normal, just one nvidia card"
echo "(1/2)"
read input
if [[ "$input" == "1" ]]; then
# set will change all $1 - $n
set "laptop"
echo laptop mode
sleep 2
else
echo normal mode
sleep 2
fi
fi
# 定义黑名单的文件地址
blacklistfile=/etc/modprobe.d/blacklist.conf
# blacklistfile=test.txt
# 把不兼容的开源nvidia驱动设置黑名单
echo blacklist nouveau | sudo tee $blacklistfile
echo options nouveau modeset=0 | sudo tee -a $blacklistfile
# 把debian nvidia驱动的非稳定源写入apt源
# 定义apt source文件地址
sourcelist=/etc/apt/sources.list
# sourcelist=source.list
# deb_source="deb http://deb.debian.org/debian buster-backports main contrib non-free"
deb_source="deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free"
# not laptop mode, then add this
if [[ -z "$1" ]]; then
grep -Fxq "$deb_source" $sourcelist || echo $deb_source | sudo tee -a $sourcelist
fi
# 更新黑名单
sudo update-initramfs -u
# 关闭lightdm 先
sudo service lightdm stop
sudo apt update
# 删除原本的各种驱动
sudo apt remove nvidia* -y
# 安装nvidia-detect
sudo apt install nvidia-detect -y
sudo apt install curl -y
if [[ "$1" == "laptop" ]]; then
sudo apt install nvidia-driver firmware-misc-nonfree nvidia-cuda-dev nvidia-cuda-toolkit nvidia-smi nvidia-settings nvidia-cuda-mps vulkan-utils -y
# --------------------- only for Optimus two GPU laptop -------------------------
# https://github.com/zty199/dde-dock-switch_graphics_card
# 提前下载好这个
if [ ! -f ./dde-dock-graphics-plugin_1.8.1_amd64.deb ]; then
echo download dde dock graphics plugin
curl -L https://github.com/zty199/dde-dock-switch_graphics_card/releases/download/1.8.1/dde-dock-graphics-plugin_1.8.1_amd64.deb --output ./dde-dock-graphics-plugin_1.8.1_amd64.deb
fi
if [ ! -f ./prime-run.desktop ]; then
echo write prime-run desktop file
cat >./prime-run.desktop <<EOL
[Desktop Entry]
Type=Application
Exec=/usr/bin/prime-run %u
GenericName=Run with prime-run
Name=Run with prime-run
MimeType=application/x-shellscript;application/x-sharedlib;application/x-executable;application/x-desktop;
GenericName[en]=Run with prime-run
GenericName[zh_CN]=使用 prime-run 运行
Name[en]=Run with prime-run
Name[zh_CN]=使用 prime-run 运行
X-DFM-MenuTypes=SingleFile
X-DFM-SupportSchemes=file
X-Deepin-Vendor=user-custom
EOL
fi
chmod +x ./dde-dock-graphics-plugin_1.8.1_amd64.deb
chmod +x ./prime-run.desktop
sudo dpkg -i ./dde-dock-graphics-plugin_1.8.1_amd64.deb
sudo apt --fix-broken install -y
# 装两遍因为第一遍可能因为缺少dependency装不上
sudo dpkg -i ./dde-dock-graphics-plugin_1.8.1_amd64.deb
sudo rsync -auvPh ./prime-run.desktop /usr/share/deepin/dde-file-manager/oem-menuextensions/
# -------------------- only for Optimus two GPU laptop END -----------------------
else
sudo apt install -t buster-backports nvidia-driver firmware-misc-nonfree nvidia-cuda-dev nvidia-cuda-toolkit nvidia-smi nvidia-settings nvidia-cuda-mps vulkan-utils -y
fi
sudo apt install mesa-utils -y
sleep 5
reboot