1

I'm working on a new system to automate drivers installation in Windows 10/11. Some time ago, I downloaded a drivers collection from driverpack (the drivers collection is fine, but the software to manage the installations, I think may have viruses...) So I can install pretty much any Windows driver but it lasts a long time. I have the drivers collection in a SAMBA share in my server (FREEBNT from now on. It is Ubuntu 22.04.1). So when I want to install any drivers it has to search for the correct .inf file in the collection, and it can be like 20 minutes or more. Then I have recently come up with the idea of doing a drivers database (MySQL) with hardware IDs and file paths (for the .inf files), and doing a PowerShell script to automate the installation of drivers using the database and downloading the drivers through SAMBA. I asked the ChatGPT to do the code for me, and it has helped me a lot, but there are some errors in its proposed solution. The project is comprised of 2 main parts:

  1. generating a MySQL database with a table which in turn has two columns: hwid and path, containing entries for every .inf file and its hardware IDs.
  2. generating the different necessaries powershell scripts to install the drivers using the previous database.

Right now I'm in the first step - generating the database. But the script provided by ChatGPT is not perfect. here is the script. Note: FREEBNT is a server which has lots of storage. It acts as SAMBA server and other functions as well, but for this matter, the important thing is that it acts as the MySQL server and SAMBA server as well, and also it will run the bash shell script which will generate the MySQL database including all the .inf files and their Hardware IDs. Here is the script.

#!/bin/bash

# Set up MySQL database connection parameters
db_user="mymysqluser"
db_pass="mymysqlpass"
db_name="drivers"
db_host="127.0.0.1"

# Set up the path to your drivers collection
drivers_path="/free/fr/drivers/"

# Loop through all INF files in the drivers collection
for inf_file in $(find "$drivers_path" -type f -name "*.inf"); do

  # Extract hardware IDs from INF file
  hwids=$(grep -iE "^driverver|^pci|usb\\\\" "$inf_file" | awk -F ",|=" '{print $2}' | tr -d ' ' | sort -u)
  
  #convert the inf file path to a path readable by Windows systems through SAMBA (added by borhacker)
  inf_file2=$(echo $inf_file | sed 's/\/free\/fr\/drivers\//\\\\192.168.1.2\\Fr-drivers\\/')
  inf_file3=$(echo $inf_file2 | sed 's/\//\\/g')

  # Loop through all hardware IDs and insert them into the database
  for hwid in $hwids; do
    echo "Inserting $hwid for $inf_file3 into database..."
    mysql -u $db_user -p$db_pass -h $db_host $db_name -e "INSERT INTO drivers (hwid, path) VALUES ('$hwid', '$inf_file3');"
  done

done

The section labeled as 'added by borhacker' is made by me, because the file paths are not the same from FREEBNT or from Windows 10 accessing the SAMBA share. So when the variable inf_file contains, for example:

/free/fr/drivers/bluetooth/DP_Bluetooth_22094/MediaTek/FORCED/10x64/7921_1.3.14.133_tequila/mtkbtfilter.inf

the variable inf_file3 contains:

\\192.168.1.2\Fr-drivers\bluetooth\DP_Bluetooth_22094\MediaTek\FORCED\10x64\7921_1.3.14.133_tequila\mtkbtfilter.inf

The rest of the script, I understand everything(not everyting!). I have studied it to understand its behavior. The only thing I don't understand is this part:

  # Extract hardware IDs from INF file
  hwids=$(grep -iE "^driverver|^pci|usb\\\\" "$inf_file" | awk -F ",|=" '{print $2}' | tr -d ' ' | sort -u)

And I guess the problem is there. I understand that this, supposedly, extracts the Hardware IDs from each .inf file. But when I'm running the script it is not extracting the Hardware IDs. And this is why I have studied the script. It extracts, generally, dates, like, for example (output of running the script for some time):

root@freebnt:/home/borhacker# ./indexdrivers-edit.sh
Inserting 07/10/2016 for \\192.168.1.2\Fr-drivers\video\DP_Video_nVIDIA-XP_22080\nVidia\FORCED\5x86\368.81\nvmmi.inf into database...
mysql: [Warning] Using a password on the command line interface can be insecure.
Inserting 07/10/2016 for \\192.168.1.2\Fr-drivers\video\DP_Video_nVIDIA-XP_22080\nVidia\FORCED\5x86\368.81\nvbli.inf into database...
mysql: [Warning] Using a password on the command line interface can be insecure.
Inserting 07/10/2016 for \\192.168.1.2\Fr-drivers\video\DP_Video_nVIDIA-XP_22080\nVidia\FORCED\5x86\368.81\nvlei.inf into database...
mysql: [Warning] Using a password on the command line interface can be insecure.
Inserting 07/10/2016 for \\192.168.1.2\Fr-drivers\video\DP_Video_nVIDIA-XP_22080\nVidia\FORCED\5x86\368.81\nvami.inf into database...
mysql: [Warning] Using a password on the command line interface can be insecure.


Now, I'd like if someone could point me in the right direction to create the correct script which would generate the MySQL database. I don't know very well this Linux tools to process text and neither the content of Windows' inf. files.

5
  • 2
    Side note: for inf_file in $(find …) is the bash pitfall number one. Commented Mar 30, 2023 at 20:39
  • 3
    Your going to need to generate the script yourself or at least attempt to create it. Start by determining which columns you need. You are aware you are literally duplicating the Windows Update catalog website?
    – Ramhound
    Commented Mar 30, 2023 at 21:37
  • @Ramhound, I have studied the script provided by ChatGPT and, apart from the point I described, when it takes the HardwareID out of 'each' .inf file, which is erroneous, all the other code is perfect. I don't know - why should I write another script? Also, I don't know what you mean about the Windows Update catalog. When I need a driver in Windows 10, usually I have to search for it myself. Windows update (from my experience) doesn't have many drivers.
    – Free
    Commented Mar 31, 2023 at 20:39
  • @Ramhound, FYI, the drivers collection I have occupies 278GB, and there are 383660 files / 34702 folders
    – Free
    Commented Mar 31, 2023 at 21:01
  • I forgot to mention that I also have to correct the part that reads - for inf_file in $(find ...). Apart from this part and the part which takes out the HardwareID out of each .inf file, are there other problems? should I just correct these two points, @Ramhound, or you mean that I should start again?
    – Free
    Commented Apr 3, 2023 at 20:31

0

You must log in to answer this question.

Browse other questions tagged .