How to always get the latest version of Bleachbit with wget in bash?

To get latest version of BleachBit (for Ubuntu 20.04) we can use the following commands:

wget -c https://download.bleachbit.org/bleachbit_4.4.0-0_all_ubuntu2004.deb -O bleachbit.deb
dpkg -i bleachbit.deb

If we install it from the official Ubuntu repository (with apt-get bleachbit), an older version is installed, which contains installation errors. And according to the creators of this tool:

Ubuntu has a "no rolling release" policy, so the Ubuntu repository will not update with the recent versions

Since this tool is regularly updated, I would like to always download the latest version. So I did this bash, but it doesn't work:

lastbleachbit=$(wget -O - https://www.bleachbit.org/download/ | grep -Po '/download/file/([^"]+)' | grep ubuntu2004 | sort -u)
wget -c https://www.bleachbit.org"$lastbleachbit" -O bleachbit.deb
dpkg -i bleachbit.deb

Output variable:

lastmintstick=$(wget -O - http://packages.linuxmint.com/pool/main/m/mintstick/ | grep -Po 'href=".*?"' | sed -r 's:href\="(.*)":\1:' | grep ".deb" | sort | tail -1)
--2021-11-10 10:24:50--  http://packages.linuxmint.com/pool/main/m/mintstick/
Resolviendo packages.linuxmint.com (packages.linuxmint.com)... 208.77.20.11, 68.235.39.11
Conectando con packages.linuxmint.com (packages.linuxmint.com)[208.77.20.11]:80... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 10112 (9,9K) [text/html]
Guardando como: “STDOUT”

-                   100%[===================>]   9,88K  --.-KB/s    en 0s      
2021-11-10 10:24:51 (191 MB/s) - escritos a stdout [10112/10112]

Output command:

wget -c https://www.bleachbit.org"$lastbleachbit"
--2021-11-10 10:26:39--  https://www.bleachbit.org/
Resolviendo www.bleachbit.org (www.bleachbit.org)... 172.67.129.101, 104.21.1.137, 2606:4700:3030::ac43:8165, ...
Conectando con www.bleachbit.org (www.bleachbit.org)[172.67.129.101]:443... conectado.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: no especificado [text/html]
Guardando como: “index.html”

index.html              [ <=>                ]  10,93K  --.-KB/s    en 0,002s  

2021-11-10 10:26:40 (4,38 MB/s) - “index.html” guardado [11193]

What did I do wrong?


Solution 1:

You're missing /linux.

$ lastbleachbit=$(wget --quiet -O - https://www.bleachbit.org/download/linux | grep -Po '/download/file/([^"]+)' | grep ubuntu2004 | sort -u)
$ echo $lastbleachbit 
/download/file/t?file=bleachbit_4.4.0-0_all_ubuntu2004.deb

With my limited grep knowledge, I managed to get it working.

$ lastbleachbit=$(wget --quiet -O - https://www.bleachbit.org/download/linux | grep -Po '(?<=file=).*(?=">)' | grep ubuntu2004 | sort -u)
$ echo $lastbleachbit 
bleachbit_4.4.0-0_all_ubuntu2004.deb

When you download it.

$ wget "https://download.bleachbit.org/${lastbleachbit}"
--2021-11-10 16:01:10--  https://download.bleachbit.org/bleachbit_4.4.0-0_all_ubuntu2004.deb
Resolving download.bleachbit.org (download.bleachbit.org)... 172.67.129.101, 104.21.1.137, 2606:4700:3035::6815:189, ...
Connecting to download.bleachbit.org (download.bleachbit.org)|172.67.129.101|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 441432 (431K) [application/x-deb]
Saving to: ‘bleachbit_4.4.0-0_all_ubuntu2004.deb’

bleachbit_4.4.0-0_all_ubuntu2004. 100%[===========================================================>] 431.09K  2.02MB/s    in 0.2s    

2021-11-10 16:01:11 (2.02 MB/s) - ‘bleachbit_4.4.0-0_all_ubuntu2004.deb’ saved [441432/441432]

I think this should work as long the download page keep embedding link containing .deb file, though I don't know for how long as I never use bleachbit.