<commit_before>#!/bin/bash
# Reboot an unstable consumer class router.
# Supports the following router models (pass as parameter):
#    fast: Sagemcom FAST3686 (DNA Valokuitu Plus)

routermodel=${1:-fast}

routerip=$(ip route | grep default | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}")

readpw() {
    if [ -e ~/.config/router_password ]
    then
        pw=$(cat ~/.config/router_password)
        return
    fi
    echo "Enter router password (won't be echoed)."
    stty_orig=`stty -g`
    stty -echo
    read pw
    stty $stty_orig
}

echo "Preparing to reboot router at $routerip. Press return to continue."
read

if [ "$routermodel" == "fast" ]
then
    # Check if login is needed. The router remembers logged in computers with some kind of logic.
    responsepage=$(wget http://$routerip/RgSetup.asp -q -O -)
    if [ "$(echo $responsepage | grep loginUsername)" != "" ]
    then
        username=admin
        readpw
        echo "Logging in..."
        skey=$(echo $responsepage | grep -o "SessionKey = [0-9]*;" | tr -dc "[:digit:]")
        wget -q -O /dev/null "http://$routerip/goform/login?sessionKey=$skey" \
            --post-data="loginUsername=$username&loginPassword=$pw"
    fi
    responsepage=$(wget http://$routerip/RgSetup.asp -q -O -)
    skey=$(echo $responsepage | grep -o "SessionKey = [0-9]*;" | tr -dc "[:digit:]")
    echo Sending reboot request...
    # The WanConnectionType is needed in data, otherwise the request will hang.
    wget -q -O /dev/null "http://$routerip/goform/RgSetup?sessionKey=$skey" \
        --header "Referer: http://$routerip/RgSetup.asp" \
        --post-data="WanConnectionType=0&RebootAction=1"
fi

echo Rebooting...
sleep 30
echo Pinging router...
while [ "$pingresponse" != "" ]
do
    pingresponse=$(ping -c 1 $routerip 2>/dev/null | grep " 0% packet loss")
done
echo Got ping response, router is up. Press return to exit.
read<commit_msg>Fix bug.<commit_after>#!/bin/bash
# Reboot an unstable consumer class router.
# Supports the following router models (pass as parameter):
#    fast: Sagemcom FAST3686 (DNA Valokuitu Plus)

routermodel=${1:-fast}

routerip=$(ip route | grep default | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}")

readpw() {
    if [ -e ~/.config/router_password ]
    then
        pw=$(cat ~/.config/router_password)
        return
    fi
    echo "Enter router password (won't be echoed)."
    stty_orig=`stty -g`
    stty -echo
    read pw
    stty $stty_orig
}

echo "Preparing to reboot router at $routerip. Press return to continue."
read

if [ "$routermodel" == "fast" ]
then
    # Check if login is needed. The router remembers logged in computers with some kind of logic.
    responsepage=$(wget http://$routerip/RgSetup.asp -q -O -)
    if [ "$(echo $responsepage | grep loginUsername)" != "" ]
    then
        username=admin
        readpw
        echo "Logging in..."
        skey=$(echo $responsepage | grep -o "SessionKey = [0-9]*;" | tr -dc "[:digit:]")
        wget -q -O /dev/null "http://$routerip/goform/login?sessionKey=$skey" \
            --post-data="loginUsername=$username&loginPassword=$pw"
    fi
    responsepage=$(wget http://$routerip/RgSetup.asp -q -O -)
    skey=$(echo $responsepage | grep -o "SessionKey = [0-9]*;" | tr -dc "[:digit:]")
    echo Sending reboot request...
    # The WanConnectionType is needed in data, otherwise the request will hang.
    wget -q -O /dev/null "http://$routerip/goform/RgSetup?sessionKey=$skey" \
        --header "Referer: http://$routerip/RgSetup.asp" \
        --post-data="WanConnectionType=0&RebootAction=1"
fi

echo Rebooting...
sleep 30
echo Pinging router...
while [ "$pingresponse" == "" ]
do
    pingresponse=$(ping -c 1 $routerip 2>/dev/null | grep " 0% packet loss")
done
echo Got ping response, router is up. Press return to exit.
read
{'fraction_non_alphanumeric': 0.16159250585480095, 'fraction_numerical': 0.016653655997918293, 'mean_word_length': 2.863316582914573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5360361', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1283, 'n_words': 372}