Advertisement
Rnery

[New] Realtek checking all stages of the process

Oct 25th, 2023 (edited)
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. function execute_with_sudo() {
  4.   if [ "$EUID" -ne 0 ]; then
  5.     sudo "$@"
  6.   else
  7.     "$@"
  8.   fi
  9. }
  10.  
  11. function check_online_git() {
  12.   if ! command -v git &>/dev/null; then
  13.     echo "Git is not installed. Please install Git before proceeding."
  14.     return 1
  15.   fi
  16.  
  17.   if ! curl --head --silent https://github.com/lwfinger/rtw88.git &>/dev/null; then
  18.     echo "Git repository is not available online. Please check your internet connection or the repository URL."
  19.     return 1
  20.   fi
  21.  
  22.   return 0
  23. }
  24.  
  25. function check_device() {
  26.   if ! lsusb | grep -q "0bda:885c"; then
  27.     echo "Realtek device 0bda:885c not found. Make sure the device is connected."
  28.     return 1
  29.   fi
  30.  
  31.   return 0
  32. }
  33.  
  34. function check_existing_folder() {
  35.   if [ -d "rtw88" ]; then
  36.     echo "'rtw88' folder already exists. No need to clone again."
  37.     return 1
  38.   fi
  39.  
  40.   return 0
  41. }
  42.  
  43. function install_dependencies() {
  44.   echo "Installing dependencies..."
  45.   execute_with_sudo apt update
  46.   execute_with_sudo apt install -y git build-essential dkms
  47. }
  48.  
  49. function download_driver() {
  50.   check_device || return
  51.   check_online_git || return
  52.   check_existing_folder || return
  53.  
  54.   echo "Downloading the driver..."
  55.   git clone https://github.com/lwfinger/rtw88.git
  56. }
  57.  
  58. function install_driver() {
  59.   echo "Installing the driver..."
  60.   cd rtw88
  61.   make
  62.   execute_with_sudo make install
  63. }
  64.  
  65. function load_kernel_module() {
  66.   echo "Loading the kernel module..."
  67.   execute_with_sudo modprobe rtw_8822b
  68. }
  69.  
  70. function update_udev_rules() {
  71.   echo "Updating udev rules..."
  72.   execute_with_sudo update-initramfs -u
  73. }
  74.  
  75. function main() {
  76.   clear
  77.   echo "Starting the installation of the Realtek 0bda:885c driver..."
  78.  
  79.   check_device || return
  80.   install_dependencies
  81.   download_driver
  82.   install_driver
  83.   load_kernel_module
  84.   update_udev_rules
  85.  
  86.   echo "Driver installed successfully."
  87. }
  88.  
  89. main
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement