<commit_before>#!/bin/sh

test -f /usr/share/acpi-support/state-funcs || exit 0

# Find and toggle wireless of bluetooth devices on ThinkPads

. /usr/share/acpi-support/state-funcs
. /etc/LocalSys/init.d/functions-laptop
LOGFILE=/tmp/wifi-acpi.log


toggleBluetooth()
{
    [ -e /tmp/Fn-F5.ctrl-bluetooth ] || return 0

    echo "Checking Bluetooth..." >>$LOGFILE

    rfkill list |\
        sed -n -e'/tpacpi_bluetooth_sw/,/^[0-9]/p' |\
        grep -q 'Soft blocked: yes'
    bluetooth_state=$?

    # Sequence is Both on, Both off, Wireless only, Bluetooth only
    if ! isAnyWirelessPoweredOn; then
        # Wireless was turned off
        if [ "$bluetooth_state" = 0 ]; then
            echo "Bluetooth currently turned off; reenabling..." >>$LOGFILE
            rfkill unblock bluetooth >>$LOGFILE 2>&1
        else
            echo "Disabling Bluetooth..." >>$LOGFILE
            rfkill block bluetooth >>$LOGFILE 2>&1
            #killBluetooth
        fi
    fi
}


echo "" >>$LOGFILE
echo "#################### `date` ####################" \
    >>$LOGFILE
echo "" >>$LOGFILE

# FIXME::[jpw;2010-11-13]
# Something else is running when Fn-F5 is hit, in addition to this script.
# Soooo... we'll let it run, then we'll ... um ... Wait.  If we then run this
# script after waiting, we'll _reverse_ the change.  So that won't work.
#
# The upshot is:  we have a race-condition between this script and whatever
# else is running.

if isAnyWirelessPoweredOn; then
    echo "Found active WiFi; disabling..." >>$LOGFILE
    iwconfig eth1 txpower off >>$LOGFILE 2>&1
    #killWifi >>$LOGFILE 2>&1
else
    echo "Enabling WiFi..." >>$LOGFILE
    loadWifiModules >>$LOGFILE 2>&1

    iwconfig eth1 txpower on >>$LOGFILE 2>&1
    #local d
    #for d in /sys/class/net/*; do
    #    if [ -w $d/device/rf_kill ]; then
    #        # '1' means "turn it on," not kill the rf.
    #        echo 1 >>$d/device/rf_kill
    #    fi
    #done
fi
toggleBluetooth

echo "Done." >>$LOGFILE


######
# End
#<commit_msg>Will now attempt to use "iwconfig txpower" first, then fall back on the kernel parameters if the former fails to work.<commit_after>#!/bin/sh

test -f /usr/share/acpi-support/state-funcs || exit 0

# Find and toggle wireless of bluetooth devices on ThinkPads

. /usr/share/acpi-support/state-funcs
. /etc/LocalSys/init.d/functions-laptop
LOGFILE=/tmp/wifi-acpi.log


toggleBluetooth()
{
    [ -e /tmp/Fn-F5.ctrl-bluetooth ] || return 0

    echo "Checking Bluetooth..." >>$LOGFILE

    rfkill list |\
        sed -n -e'/tpacpi_bluetooth_sw/,/^[0-9]/p' |\
        grep -q 'Soft blocked: yes'
    bluetooth_state=$?

    # Sequence is Both on, Both off, Wireless only, Bluetooth only
    if ! isAnyWirelessPoweredOn; then
        # Wireless was turned off
        if [ "$bluetooth_state" = 0 ]; then
            echo "Bluetooth currently turned off; reenabling..." >>$LOGFILE
            rfkill unblock bluetooth >>$LOGFILE 2>&1
        else
            echo "Disabling Bluetooth..." >>$LOGFILE
            rfkill block bluetooth >>$LOGFILE 2>&1
            #killBluetooth
        fi
    fi
}


echo "" >>$LOGFILE
echo "#################### `date` ####################" \
    >>$LOGFILE
echo "" >>$LOGFILE

# FIXME::[jpw;2010-11-13]
# Something else is running when Fn-F5 is hit, in addition to this script.
# Soooo... we'll let it run, then we'll ... um ... Wait.  If we then run this
# script after waiting, we'll _reverse_ the change.  So that won't work.
#
# The upshot is:  we have a race-condition between this script and whatever
# else is running.

local iwconfig_failed
iwconfig_failed='n'
if isAnyWirelessPoweredOn; then
    echo "Found active WiFi; disabling..." >>$LOGFILE
    iwconfig eth1 txpower off >>$LOGFILE 2>&1 || iwconfig_failed='y'
    isAnyWirelessPoweredOn && iwconfig_failed='y'

    if [ "$iwconfig_failed" = 'y' ]; then
        echo "    'iwconfig' failed to disable TX power!" >>$LOGFILE 2>&1
        echo "    Attempting direct kernel param manipulation" \
            >>$LOGFILE 2>&1

        killWifi >>$LOGFILE 2>&1
    fi
else
    echo "Enabling WiFi..." >>$LOGFILE
    loadWifiModules >>$LOGFILE 2>&1

    iwconfig eth1 txpower on >>$LOGFILE 2>&1 || iwconfig_failed='y'
    isAnyWirelessPoweredOn || iwconfig_failed='y'

    if [ "$iwconfig_failed" = 'y' ]; then
        echo "    'iwconfig' failed to reenable TX power!" >>$LOGFILE 2>&1
        echo "    Attempting direct kernel param manipulation" \
            >>$LOGFILE 2>&1

        local d rfk
        for d in /sys/class/net/*; do
            rfk=$d/device/rf_kill
            if [ -w $rfk ]; then
                # '1' means "turn it off"
                if [ "`cat $rfk`" = "1" ]; then
                    echo "    Disabling rf_kill..." >>$LOGFILE 2>&1
                    echo 0 >>$rfk
                fi
            fi
        done
    fi
fi
toggleBluetooth

echo "Done." >>$LOGFILE


######
# End
#
{'fraction_non_alphanumeric': 0.14320685434516525, 'fraction_numerical': 0.014891880864953081, 'mean_word_length': 2.4072272411396805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 94, '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': '1871810', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1612, 'n_words': 498}