Advertisement
Rnery

New refactoring broadcom..

Oct 25th, 2023 (edited)
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # breaking the code with SOLID
  4.  
  5. function download_and_verify() {
  6.     local url="$1"
  7.     local filename="$2"
  8.    
  9.     wget -q "$url" -O "$filename"
  10.    
  11.     if [ -s "$filename" ]; then
  12.         echo "Download de $filename bem-sucedido."
  13.     else
  14.         echo "Falha ao fazer o download de $filename."
  15.         exit 1
  16.     fi
  17. }
  18.  
  19. function execute_with_sudo() {
  20.     local command="$1"
  21.     sudo $command
  22. }
  23.  
  24. function update_system() {
  25.     execute_with_sudo "apt update && apt upgrade"
  26. }
  27.  
  28. function install_prerequisites() {
  29.     execute_with_sudo "apt install linux-headers-$(uname -r) build-essential dkms"
  30. }
  31.  
  32. function remove_old_drivers() {
  33.     execute_with_sudo "apt purge bcmwl-kernel-source"
  34. }
  35.  
  36. function install_broadcom_firmware() {
  37.     local firmware_urls=("http://www.lwfinger.com/b43-firmware/broadcom-wl-5.100.138.tar.bz2"
  38.                          "http://downloads.openwrt.org/sources/broadcom-wl-5.10.56.27.3_mipsel.tar.bz2")
  39.     local firmware_files=("broadcom-wl-5.100.138.tar.bz2"
  40.                           "broadcom-wl-5.10.56.27.3_mipsel.tar.bz2")
  41.  
  42.     for i in ${!firmware_urls[@]}; do
  43.         download_and_verify "${firmware_urls[$i]}" "${firmware_files[$i]}"
  44.         tar -xf "${firmware_files[$i]}"
  45.     done
  46.  
  47.     if [ -e "${firmware_files[0]}" ] && [ -e "${firmware_files[1]}" ]; then
  48.         execute_with_sudo "b43-fwcutter -w /lib/firmware broadcom-wl-5.100.138/linux/wl_apsta.o"
  49.     else
  50.         echo "Falha ao encontrar os arquivos de firmware necessários."
  51.         exit 1
  52.     fi
  53. }
  54.  
  55. function load_b43_driver() {
  56.     execute_with_sudo "modprobe b43"
  57. }
  58.  
  59. function check_driver_status() {
  60.     dmesg | grep b43
  61. }
  62.  
  63. function main() {
  64.     clear
  65.     update_system
  66.     install_prerequisites
  67.     remove_old_drivers
  68.     install_broadcom_firmware
  69.     load_b43_driver
  70.     check_driver_status
  71. }
  72.  
  73. main
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement