openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
818 stars 251 forks source link

Ethernet probe in first-boot.bash fails due to TLS upgrade #1771

Closed sindrebilden closed 1 year ago

sindrebilden commented 1 year ago

Issue information:

The ethernet probe curl --silent --head http://www.openhab.org/docs |& grep -qs 'HTTP/1.1 200 OK' seems to fail since the docs now upgrades to TLS (Redirects to https://www.openhab.org/docs/).

I have tried to solve it in this branch (forked) where the url is updated and is now adjustable by config, in addition I updated the grep condition to be agnostic to HTTP/1.1 or HTTP/2. I also introduced the option for allow redirects and disabled it by default, but it might be redundant.

Debug information:

When probing the ethernet the logs outputs:

+ tryUntil 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\''' 5 1
+ local cmd
+ local attempts
+ local interval
+ cmd='ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
+ attempts=5
+ interval=1
+ [[ 5 -le 0 ]]
+ cond_echo '\nexecuting ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'' \c'
+ [[ -z 1 ]]
+ eval 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
++ ping -c1 8.8.8.8
++ curl --silent --head http://www.openhab.org/docs
++ grep -qs 'HTTP/1.1 200 OK'
+ out=1
+ [[ 1 -eq 0 ]]
+ sleep 1
+ [[ -z 1 ]]
+ (( attempts-=1 ))
+ [[ 4 -le 0 ]]
+ cond_echo '\nexecuting ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'' \c'
+ [[ -z 1 ]]
+ eval 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
++ ping -c1 8.8.8.8
++ curl --silent --head http://www.openhab.org/docs
++ grep -qs 'HTTP/1.1 200 OK'
+ out=1
+ [[ 1 -eq 0 ]]
+ sleep 1
+ [[ -z 1 ]]
+ (( attempts-=1 ))
+ [[ 3 -le 0 ]]
+ cond_echo '\nexecuting ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'' \c'
+ [[ -z 1 ]]
+ eval 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
++ ping -c1 8.8.8.8
++ curl --silent --head http://www.openhab.org/docs
++ grep -qs 'HTTP/1.1 200 OK'
+ out=1
+ [[ 1 -eq 0 ]]
+ sleep 1
+ [[ -z 1 ]]
+ (( attempts-=1 ))
+ [[ 2 -le 0 ]]
+ cond_echo '\nexecuting ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'' \c'
+ [[ -z 1 ]]
+ eval 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
++ ping -c1 8.8.8.8
++ curl --silent --head http://www.openhab.org/docs
++ grep -qs 'HTTP/1.1 200 OK'
+ out=1
+ [[ 1 -eq 0 ]]
+ sleep 1
+ [[ -z 1 ]]
+ (( attempts-=1 ))
+ [[ 1 -le 0 ]]
+ cond_echo '\nexecuting ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'' \c'
+ [[ -z 1 ]]
+ eval 'ping -c1 8.8.8.8 &> /dev/null || curl --silent --head http://www.openhab.org/docs |& grep -qs '\''HTTP/1.1 200 OK'\'''
++ ping -c1 8.8.8.8
++ curl --silent --head http://www.openhab.org/docs
++ grep -qs 'HTTP/1.1 200 OK'
+ out=1
+ [[ 1 -eq 0 ]]
+ sleep 1
+ [[ -z 1 ]]
+ (( attempts-=1 ))
+ [[ 0 -le 0 ]]
+ [[ -z 1 ]]

A manual curl that allows redirect shows a upgrade to TLS:

% curl --silent --head -L http://www.openhab.org/docs                             
HTTP/1.1 301 Moved Permanently
Location: https://www.openhab.org/docs

HTTP/2 301 
location: /docs/

HTTP/2 200 

A probe directly to https://www.openhab.org/docs/ shows (notice HTTP/2 not HTTP/1.1)

 % curl --silent --head https://www.openhab.org/docs/
HTTP/2 200 

System information:

I used Raspberry Pi Imager with openHABian 32 bit v1.7.5 on a RPi3B+

mstormi commented 1 year ago

Thanks

Fixed-by: b5a54881fdb2035e84cf9601b2d34f6b45557538