unixabg / cryptmypi

Project to assist users in building an encrypted raspberry pi
GNU General Public License v3.0
63 stars 21 forks source link

Improvement on the sys-ssh-jump service #45

Open iTosun opened 3 years ago

iTosun commented 3 years ago

I got some improvements on the sys-ssh-jump service, I like to share this for improvement of the repo. The improvement will make sleeps obsolete and it will just wait for internet connection. Also added an extra function that seemed handy in my case because i used a USB LTE modem that sometimes lost it's connectivity and needed a power cycle. The following project is used for that https://github.com/mvp/uhubctl (Also installable with apt-get)

function is_online() {
    echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        echo "Redpi has internet"
        result=1
    else
        result=0
    fi
}

function wait_for_internet() {
    is_online
    while [ $result -eq 0 ]; do
        is_online
    done
}

function reset_usb_lte() {
    is_online
    if [ $result -eq 0 ];then
        # Power cycle the usb ports on the pi
        uhubctl -a 2 -l 2
        # Loop till we got internet
        wait_for_internet
    fi
}
unixabg commented 3 years ago

Greetings, First thank you for the submission. Second could you checkout the next-4.x branch and make a pull request (pr) so I can see exactly how you applied these. The pr will allow for easy integration, testing, and will clearly give you credit for your work.