pma-updatescript
pma-updatescript copied to clipboard
Check checksum
I don't know if this is worth the work, but maybe it is. What you're thinking about the idea, to integrate a checksum check if the phpMyAdmin archive file was downloaded correctly?
Sadly I don't know how to easily check the hash of the archive with bash, because I only found the hash on the following page http://www.phpmyadmin.net/home_page/downloads.php and it's quite difficult to parse the hash from there.
I don't know how to get the checksum, too :/ But somebody else?
I invested some time to find out how to get the checksum of the phpMyAdmin archive files and I tried to find a way to solve this with any built-in functionalities of bash. So finally I found a working solution!
The code looks like:
$ file="phpMyAdmin-4.3.2-all-languages.7z"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
We already know the filename in the script before it does download the archive, so it should not be a big deal to implement that. Here are some example executions:
$ file="phpMyAdmin-4.3.2-all-languages.7z"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
1b52f5e620a191056e1c04d7ddd2c691
$ file="phpMyAdmin-4.3.2-all-languages.zip"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
a698f1c48fa3c21fd5bee4ff11fec96e
$ file="phpMyAdmin-4.3.2-all-languages.tar.gz"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
2c309c249bf17f4796f4de707b6ce25d
$ file="phpMyAdmin-4.1.14.8-all-languages.7z"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
3cb85189c0897f817ad59a556a427cfa
$ file="phpMyAdmin-4.1.14.8-all-languages.zip"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
088c80e663c6e15146ccc0dd2f13c521
$ file="phpMyAdmin-4.0.10.7-english.zip"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
21f7c0785ec3cbdb12f1a8e94dc25b4f
$ file="phpMyAdmin-does-not-exist-all-languages.zip"; downloads=$(curl -s http://www.phpmyadmin.net/home_page/downloads.php); regex="${file}/download#\!md5\!([a-zA-Z0-9_-]+)"; if [[ $downloads =~ $regex ]]; then echo ${BASH_REMATCH[1]}; fi
It works fine so far. If does not find any checksum, it just returns nothing. My thoughts about verifying the checksum: (variable name is just an example)
- If it is valid, just proceed.
- If it is invalid and CHECKSUM_VALIDATION is 1, the scripts aborts and logs this validation error.
- If it is invalid and the CHECKSUM_VALIDATION is 0, the script may proceed and just make a warning log output.
nice one! i will check it in the next dev ... :+1: