Ok, first of all I want to apologize for my fantastic bash scripting arts. There must be people laughing there ass off.
I was searching the internet for an update program or script for Linbpq. I could not find these, so I started using my bash scripting skills.
Maybe someone has better ideas.
The problem is that John GM8BPQ does not work with version numbers in his program names. This makes it difficult to quickly see if you need to update. Now I always look at the dates, this gave me an idea.
Why not look at the Last_Modified date with a shell script. Now of course you first have to check on your own system which date you have with your most recent Linbpq program file.
pd9q@packet:~ $ date -d "$( stat /home/pd9q/linbpq/linbpq | awk '/Modify/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d" 2019-09-26
Okay now we have to take a look at John’s date on his web server.
pd9q@packet:~ $ date -d "$( curl -sI http://www.cantab.net/users/john.wiseman/Downloads/Beta/pilinbpq | awk '/Last-Modified/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d" 2019-10-05
Now you have two dates, lets compare.
local=$(date -d "$( stat /home/pd9q/linbpq/check/linbpq | awk '/Modify/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d") remote=$(date -d "$( curl -sI http://www.cantab.net/users/john.wiseman/Downloads/Beta/pilinbpq | awk '/Last-Modified/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d") # Compare the Modified date`s if (( ${local//-/} < ${remote//-/} )); then
It should beĀ “if (( ${local//-/} < ${remote//-/} ));”
The local file is from 2019-09-26 and de remote file is from 2019-10-05
Let get the new Linbpq version from 2019-10-05 and downloading it with a timestamp. I want the timestamp to remain the same, otherwise nothing later can be compared.
wget -N http://www.cantab.net/users/john.wiseman/Downloads/Beta/pilinbpq -P /home/pd9q/linbpq
The -N oprions by the wget command stands for –Timestammping
Now I want to name the file linbpq with the date of the download and copy it to the directory /home/pd9q/linbpq. If you use the -p option with cp the timestamp stays the same. And I also have the file in the /home/pd9q/linbpq/check directory. This is because I need it to compare the dates.
now=$(date "+%Y-%m-%d") cp -p /home/pd9q/linbpq/pilinbpq /home/pd9q/linbpq/linbpq-$now yes | cp -rfp /home/pd9q/linbpq/pilinbpq /home/pd9q/linbpq/check/linbpq
Let`s remove pilinbpq, we no longer need him. And chmod the linbpq file so we can execute it.
rm -f /home/pd9q/linbpq/pilinbpq chmod +x /home/pd9q/linbpq/linbpq-$now
I’m using the sed command to alter the linbpq start file.
sed -i "s,sudo -u pd9q ./.*$,sudo -u pd9q ./linbpq-"$now"," /home/pd9q/linbpq/linbpq.start
pd9q@packet:~ $ grep linbpq- /home/pd9q/linbpq/linbpq.start sudo -u pd9q ./linbpq-2019-10-31
That works very well.
Now let’s restart Linbpq with the new version of Linbpq
sudo systemctl restart linbpq
If you now run up2bpq again you will get the following message if the two dates match.
pd9q@packet:~ $ ./up2bpq Your version has the same timestamp so your version is up2date The local linbpq in the /home/pd9q/linbpq/check directory has 2019-10-05 as timestamp. The remote pilinbpq has 2019-10-05 as timestamp.
Here is the entire script.
#!/bin/bash # # Fist make a directory called check in your linbpq directory and made a copy of the linbpq program file to it. # # Lets get the Modify date from linbpq local en pilinbpq remote local=$(date -d "$( stat /home/pd9q/linbpq/check/linbpq | awk '/Modify/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d") remote=$(date -d "$( curl -sI http://www.cantab.net/users/john.wiseman/Downloads/Beta/pilinbpq | awk '/Last-Modified/{gsub( /^[^:]+: +/,"",$0); print}' )" "+%Y-%m-%d") # Compare the Modified date`s if (( ${local//-/} < ${remote//-/} )); then # echo The local file is from $local and de remote file is from $remote echo Let get the new Linbpq version from $remote and downloading it with a timestamp. # wget -N http://www.cantab.net/users/john.wiseman/Downloads/Beta/pilinbpq -P /home/pd9q/linbpq # echo Let give the file a date. echo We are going to copy the file with the same Last_Modified as on the webserver of GM8BPQ. echo And we give it the timestamp of downloading. Dont forget to copy it with the -p option. # now=$(date "+%Y-%m-%d") cp -p /home/pd9q/linbpq/pilinbpq /home/pd9q/linbpq/linbpq-$now yes | cp -rfp /home/pd9q/linbpq/pilinbpq /home/pd9q/linbpq/check/linbpq # Remove pilinbpq rm -f /home/pd9q/linbpq/pilinbpq chmod +x /home/pd9q/linbpq/linbpq-$now # We are going to use the sed command to alter the linbpq start file. sed -i "s,sudo -u pd9q ./.*$,sudo -u pd9q ./linbpq-"$now"," /home/pd9q/linbpq/linbpq.start echo Lets check "if" its was okay. # grep linbpq- /home/pd9q/linbpq/linbpq.start # echo Now lets start Linbpq with the new version. # sudo systemctl restart linbpq else echo "Your version has the same timestamp so your version is up2date" echo The local linbpq in the /home/pd9q/linbpq/check directory has $local as timestamp. echo The remote pilinbpq has $remote as timestamp fi