Advertisement
Guest User

Untitled

a guest
May 14th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3.  
  4. if [ $(id -u) -ne 0 ]; then
  5. echo "This script requires sudo privileges to run."
  6. exit 1
  7. fi
  8.  
  9. function show_menu {
  10. echo "Choose an option:"
  11. echo "1. Build Vulkan"
  12. echo "2. Build Libdrm"
  13. echo "3. Build Mesa"
  14. echo "4. Build Virglrenderer"
  15. echo "5. Build QEMU"
  16. echo "6. Build DXVK"
  17. echo "7. Build Vkd3d-proton"
  18. echo "8. Build Proton"
  19. echo "9. Build or Install Linux Kernel (newest)"
  20. echo "10. Reboot"
  21. echo "0. Exit"
  22. read -p "Enter your choice: " choice
  23. }
  24.  
  25. function show_mesa_menu {
  26. echo "Choose an option for Mesa:"
  27. echo "1. Build from source"
  28. echo "2. Install from PPA"
  29. echo "0. Back to main menu"
  30. read -p "Enter your choice: " mesa_choice
  31. }
  32.  
  33. function run_command {
  34. if ! "$@"; then
  35. echo "Command failed. Returning to menu."
  36. sleep 3
  37. else
  38. echo "Command completed. Returning to menu."
  39. sleep 3
  40. fi
  41. }
  42.  
  43. function build_vulkan {
  44. echo "Building Vulkan..."
  45. ###################################################################################################################
  46. if [ ! -d "vulkan-loader" ]; then
  47. git clone --recurse-submodules --depth=1 https://github.com/KhronosGroup/Vulkan-Loader.git vulkan-loader
  48. fi
  49. if [ ! -d "vulkan-headers" ]; then
  50. git clone --recurse-submodules --depth=1 https://github.com/KhronosGroup/Vulkan-Headers.git vulkan-headers
  51. fi
  52. cd vulkan-headers
  53. git config --global --add safe.directory /tools/virtualization/venus/vulkan-headers
  54. git rebase
  55. git pull --recurse-submodules
  56. cd ..
  57. cd vulkan-loader
  58. git config --global --add safe.directory /tools/virtualization/venus/vulkan-loader
  59. git rebase
  60. git pull --recurse-submodules
  61. cd ..
  62. ###################################################################################################################
  63. cd vulkan-headers
  64. rm -rf build
  65. mkdir build
  66. cd build
  67. cmake -D CMAKE_INSTALL_PREFIX=/usr ..
  68. cmake --build . --target install
  69. cd ../..
  70. ###################################################################################################################
  71. cd vulkan-loader
  72. rm -rf build
  73. mkdir build
  74. cd build
  75. cmake -D CMAKE_INSTALL_PREFIX=/usr \
  76. -D CMAKE_BUILD_TYPE=Release \
  77. -D CMAKE_SKIP_INSTALL_RPATH=ON \
  78. -G Ninja ..
  79. sudo ninja
  80. sudo ninja install
  81. cd ../..
  82. ###################################################################################################################
  83. sudo rm -rf vulkan-loader
  84. sudo rm -rf vulkan-headers
  85. }
  86.  
  87. function build_libdrm {
  88. echo "Building libdrm..."
  89. if [ ! -d "libdrm" ]; then
  90. git clone --recurse-submodules --depth=1 https://gitlab.freedesktop.org/mesa/drm.git libdrm
  91. fi
  92. cd libdrm
  93. rm -rf build
  94. git config --global --add safe.directory /tools/virtualization/venus/libdrm
  95. git rebase
  96. git pull --recurse-submodules
  97. mkdir build
  98. cd build
  99. ninja -C build uninstall
  100. meson setup --wipe \
  101. --buildtype=release \
  102. -Dudev=true \
  103. -Dvalgrind=disabled \
  104. -Dintel=enabled \
  105. -Dradeon=enabled \
  106. -Damdgpu=enabled \
  107. -Dnouveau=enabled \
  108. -Dvmwgfx=enabled \
  109. -Domap=enabled \
  110. -Dexynos=enabled \
  111. -Dfreedreno=enabled \
  112. -Dtegra=enabled \
  113. -Dvc4=enabled \
  114. -Detnaviv=enabled \
  115. ..
  116. ninja
  117. ninja install
  118. cd ../..
  119. rm -rf libdrm
  120. }
  121.  
  122. function build_mesa {
  123. show_mesa_menu
  124. case $mesa_choice in
  125. 1)
  126. echo "Building Mesa from source..."
  127. export RUSTFLAGS=""
  128. export CLANG_PATH=`which clang-19`
  129. export LLVM_CONFIG=/usr/bin/llvm-config
  130. export CC=clang
  131. export CXX=clang++
  132. export PATH=/lib/llvm-19/bin:$PATH
  133. if [ ! -d "mesa" ]; then
  134. git clone --recurse-submodules --depth=1 https://gitlab.freedesktop.org/mesa/mesa.git mesa
  135. fi
  136. cd mesa
  137. git config --global --add safe.directory /tools/virtualization/venus/mesa
  138. git rebase
  139. git pull --recurse-submodules
  140. mkdir build
  141. cd build
  142. apt install rustc-1.80 rust-1.80-all rustup -y
  143. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y
  144. . "$HOME/.cargo/env"
  145. rustup update stable
  146. meson setup --wipe .. \
  147. -Dsplit-debug=disabled \
  148. -Dplatforms=auto \
  149. -Degl-native-platform=auto \
  150. -Dandroid-stub=false \
  151. -Dandroid-strict=true \
  152. -Dexpat=auto \
  153. -Dgallium-drivers=all \
  154. -Dgallium-extra-hud=false \
  155. -Dgallium-d3d10umd=false \
  156. -Dgallium-rusticl=false \
  157. -Dlibunwind=disabled \
  158. -Dlmsensors=disabled \
  159. -Dlmsensors=disabled \
  160. -Dvulkan-drivers=all \
  161. -Dshader-cache=enabled \
  162. -Dshader-cache-default=true \
  163. -Dgles1=disabled \
  164. -Damdgpu-virtio=true \
  165. -Dgles2=enabled \
  166. -Dopengl=true \
  167. -Dgbm=enabled \
  168. -Dglx=auto \
  169. -Degl=enabled \
  170. -Dglvnd=enabled \
  171. -Dllvm=enabled \
  172. -Dshared-llvm=enabled \
  173. -Dvalgrind=disabled \
  174. -Dgallium-vdpau=disabled \
  175. -Dgallium-va=disabled \
  176. -Dgallium-extra-hud=false \
  177. -Dgallium-vdpau=disabled \
  178. -Dtools=all \
  179. -Dvulkan-layers=device-select,intel-nullhw,overlay,screenshot,vram-report-limit \
  180. -Dxmlconfig=auto
  181. ninja install
  182. cd ../..
  183. rm -rf mesa
  184. ;;
  185. 2)
  186. echo "Installing Mesa from PPA..."
  187. sudo add-apt-repository ppa:oibaf/graphics-drivers -y
  188. sudo apt update
  189. sudo apt upgrade -y
  190. sudo apt full-upgrade -y
  191. ;;
  192. 0)
  193. return
  194. ;;
  195. *)
  196. echo "Invalid choice. Returning to main menu."
  197. sleep 3
  198. ;;
  199. esac
  200. }
  201.  
  202. function build_virglrenderer {
  203. echo "Building virglrenderer..."
  204. if [ ! -d "virglrenderer" ]; then
  205. git clone --recurse-submodules --depth=1 https://gitlab.freedesktop.org/virgl/virglrenderer.git virglrenderer
  206. fi
  207. cd virglrenderer
  208. git config --global --add safe.directory /tools/virtualization/venus/virglrenderer
  209. git rebase
  210. git pull --recurse-submodules
  211. ninja -C build uninstall
  212. meson setup build --wipe \
  213. -Dplatforms=auto \
  214. -Dminigbm_allocation=false \
  215. -Dvenus=true \
  216. -Dvenus-validate=true \
  217. -Dcheck-gl-errors=true \
  218. -Ddrm-renderers=amdgpu-experimental \
  219. -Drender-server=true \
  220. -Drender-server-worker=process \
  221. -Dvideo=true \
  222. -Dtests=false \
  223. -Dfuzzer=false \
  224. -Dvalgrind=false \
  225. -Dtracing=none \
  226. -Dunstable-apis=false \
  227. -Dbuildtype=release
  228. ninja -C build install
  229. cd ..
  230. rm -rf virglrenderer
  231. }
  232.  
  233. function build_qemu {
  234. echo "Building QEMU..."
  235. if [ ! -d "qemu" ]; then
  236. git clone --recurse-submodules --depth=1 https://github.com/qemu/qemu.git qemu
  237. fi
  238. cd qemu
  239. PATCH_DIR="/tools/virtualization/venus/patch/qemu"
  240. for i in {1,2,3,4,5,6,7,8,9,10}; do
  241. PATCH_FILE="$PATCH_DIR/$i.patch"
  242. if [ -f "$PATCH_FILE" ]; then
  243. echo "Applying patch: $PATCH_FILE"
  244. patch -p1 < "$PATCH_FILE"
  245. if [ $? -ne 0 ]; then
  246. echo "Failed to apply patch: $PATCH_FILE"
  247. exit 1
  248. fi
  249. else
  250. echo "Patch file not found: $PATCH_FILE"
  251. fi
  252. done
  253. git config --global --add safe.directory /tools/virtualization/venus/qemu
  254. git stash -u
  255. git rebase
  256. git pull --recurse-submodules
  257. git stash pop
  258. rm -rf build
  259. mkdir build
  260. cd build
  261. ninja uninstall
  262. ../configure \
  263. --cpu=x86_64 \
  264. --audio-drv-list=alsa,default,oss,pa,sdl,sndio,pipewire \
  265. --disable-werror \
  266. --enable-vnc \
  267. --enable-opengl \
  268. --enable-xen \
  269. --enable-xen-pci-passthrough \
  270. --enable-vdi \
  271. --enable-vde \
  272. --enable-tpm \
  273. --enable-spice \
  274. --enable-qcow1 \
  275. --enable-libusb \
  276. --enable-virglrenderer \
  277. --enable-system \
  278. --enable-modules \
  279. --enable-gtk \
  280. --enable-usb-redir \
  281. --enable-kvm \
  282. --enable-sdl \
  283. --enable-vte \
  284. --enable-bzip2 \
  285. --enable-linux-user \
  286. --enable-docs \
  287. --enable-gnutls \
  288. --enable-nettle \
  289. --enable-curses \
  290. --enable-virtfs \
  291. --enable-curl \
  292. --enable-fdt \
  293. --enable-rdma \
  294. --enable-vde \
  295. --enable-linux-aio \
  296. --enable-cap-ng \
  297. --enable-attr \
  298. --enable-vhost-net \
  299. --enable-rbd \
  300. --enable-libiscsi \
  301. --enable-libnfs \
  302. --enable-smartcard \
  303. --enable-lzo \
  304. --enable-snappy \
  305. --enable-seccomp \
  306. --enable-coroutine-pool \
  307. --enable-glusterfs \
  308. --enable-tpm \
  309. --enable-numa \
  310. --enable-slirp
  311. ninja install
  312. cd ../..
  313. rm -rf qemu
  314. }
  315.  
  316. function build_dxvk {
  317. echo "Building DXVK..."
  318. if [ ! -d "dxvk" ]; then
  319. git clone --recurse-submodules --depth=1 https://github.com/doitsujin/dxvk.git dxvk
  320. fi
  321. cd dxvk
  322. git config --global --add safe.directory /tools/virtualization/venus/dxvk
  323. git rebase
  324. git pull --recurse-submodules
  325. ninja -C build uninstall
  326. rm -rf build
  327. mkdir build
  328. ./package-release.sh master /tools/virtualization/venus/dxvk/build --no-package
  329. ninja -C build/dxvk-master/build.64/ install
  330. ninja -C build/dxvk-master/build.32/ install
  331. cd ..
  332. rm -rf dxvk
  333. }
  334.  
  335. function build_vkd3d_proton {
  336. echo "Building vkd3d-proton..."
  337. if [ ! -d "vkd3d-proton" ]; then
  338. git clone --recurse-submodules --depth=1 https://github.com/HansKristian-Work/vkd3d-proton.git vkd3d-proton
  339. fi
  340. cd vkd3d-proton
  341. git config --global --add safe.directory /tools/virtualization/venus/vkd3d-proton
  342. git rebase
  343. git pull --recurse-submodules
  344. rm -rf build
  345. mkdir build
  346. ./package-release.sh master /tools/virtualization/venus/vkd3d-proton/build --no-package
  347. cd build/vkd3d-proton-master/
  348. sudo -u "#$SUDO_UID" ./setup_vkd3d_proton.sh install
  349. cd ../../..
  350. rm -rf vkd3d-proton
  351. }
  352.  
  353. function build_proton {
  354. echo "Building Proton..."
  355. if [ ! -d "proton" ]; then
  356. git clone --recurse-submodules --depth=1 https://github.com/ValveSoftware/Proton.git proton
  357. fi
  358. cd proton
  359. git config --global --add safe.directory /tools/virtualization/venus/proton
  360. git rebase
  361. git pull --recurse-submodules
  362. make clean
  363. make
  364. make dxvk
  365. make vkd3d-proton
  366. make install
  367. cd ..
  368. rm -rf proton
  369. }
  370.  
  371. function build_kernel_new {
  372. echo "Building or Installing Linux Kernel (newest)..."
  373. read -p "The kernel is already built. Rebuild or just install linux kernel? (build/install): " response
  374. if [ "$response" = "build" ]; then
  375. read -p "Are you sure you want to rebuild the kernel? It will take a long time to rebuild. (yes/no): " confirm
  376. if [ "$confirm" = "yes" ]; then
  377. echo "Building linux kernel. This will take a long time!"
  378. echo "Speeds will vary depending on your CPU."
  379. export CC="ccache clang"
  380. export CXX="ccache clang++"
  381. export CFLAGS="-O2 -pipe"
  382. export CXXFLAGS="-O2 -pipe"
  383. rm -rf linux-kernel
  384. KERNEL_DIR="linux-kernel"
  385. if [ -d "$KERNEL_DIR" ]; then
  386. cd "$KERNEL_DIR" && git pull
  387. else
  388. git clone --recurse-submodules --depth=1 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git "$KERNEL_DIR"
  389. cd "$KERNEL_DIR"
  390. fi
  391. git fetch --tags
  392. LATEST_STABLE_TAG=$(git tag -l | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort --version-sort | tail -n1)
  393. git checkout "$LATEST_STABLE_TAG"
  394. patch -p1 < /tools/virtualization/venus/patch/kernel/1.patch
  395. rm -rf .config
  396. make menuconfig
  397. scripts/config --enable CONFIG_KERNEL_XZ
  398. scripts/config --enable CONFIG_PREEMPT_RT
  399. scripts/config --enable CONFIG_DRM_VIRTIO_GPU
  400. scripts/config --disable CONFIG_TRANSPARENT_HUGEPAGE
  401. scripts/config --disable SYSTEM_TRUSTED_KEYS
  402. scripts/config --disable SYSTEM_REVOCATION_KEYS
  403. ccache -C
  404. ccache -M 100G
  405. make -j$(($(nproc)*2))
  406. make modules_install
  407. make install
  408. sudo update-grub
  409. sudo update-grub2
  410. cd ..
  411. else
  412. echo "Kernel rebuild aborted."
  413. fi
  414. read -p "Do you wanna remove the kernel? It could take just as long to build again. (yes/no): " remove
  415. if [ "$remove" = "yes" ]; then
  416. rm -rf linux-kernel
  417. fi
  418. elif [ "$response" = "install" ]; then
  419. cd linux
  420. make install
  421. update-grub
  422. update-grub2
  423. cd ..
  424. fi
  425. }
  426.  
  427. function reboot_system {
  428. read -p "Reboot now? (yes/no): " response
  429. if [ "$response" = "yes" ]; then
  430. reboot
  431. fi
  432. }
  433.  
  434. while true; do
  435. show_menu
  436. case $choice in
  437. 1)
  438. run_command build_vulkan
  439. ;;
  440. 2)
  441. run_command build_libdrm
  442. ;;
  443. 3)
  444. build_mesa
  445. ;;
  446. 4)
  447. run_command build_virglrenderer
  448. ;;
  449. 5)
  450. run_command build_qemu
  451. ;;
  452. 6)
  453. run_command build_dxvk
  454. ;;
  455. 7)
  456. run_command build_vkd3d_proton
  457. ;;
  458. 8)
  459. run_command build_proton
  460. ;;
  461. 9)
  462. run_command build_kernel_new
  463. ;;
  464. 10)
  465. reboot_system
  466. ;;
  467. 0)
  468. echo "Exiting..."
  469. exit 0
  470. ;;
  471. *)
  472. echo "Invalid choice. Please try again."
  473. sleep 3
  474. ;;
  475. esac
  476. done
  477.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement