Today I had to update a set of installed packages from a folder, but in that folder there were some deb packages that were not installed and that I did not want to install, so I thought of doing a script that check if that package were installed and if so, update them with the deb file.
Of course, the main issue here is that the deb package name is not the name of the package once installed (the deb is , say samba_1.2.3..deb while the package name would be just samba), so parsing basenames (and taking out the version numbers which where preceded by a _) was the clue here:
#!/bin/bash # END for e in $(ls -F | grep -v [/,*]) do #we'll store in $filename the dpkg package name. filename=$(echo $e | cut -d_ -f1) dpkg -l | grep $filename > /dev/null if [ $? == 0 ] ; then sudo dpkg -i $e else echo $filename "is not installed, ignored" fi done