Skip to content

Instantly share code, notes, and snippets.

@cameronism
Created November 14, 2015 04:05
Show Gist options
  • Save cameronism/3c7879b63f5c0fa43f50 to your computer and use it in GitHub Desktop.
Save cameronism/3c7879b63f5c0fa43f50 to your computer and use it in GitHub Desktop.
rfkill-toggle.sh
#!/bin/sh
# Usage ./rfkill-toggle.sh [IDENTIFIER]
# where IDENTIFIER is the index no. of an rfkill switch or one of:
# wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm nfc
ID=`rfkill list "$1" | head -c 1 | cut -f 1`
SOFT="/sys/class/rfkill/rfkill$ID/soft"
if [ ! -f "$SOFT" ]; then
echo "no such identifier"
exit 1
fi
ACTION="block"
if [ $(cat "$SOFT") -eq 1 ]; then
ACTION="unblock"
fi
sudo rfkill "$ACTION" "$ID"
@combro2k
Copy link

Little addition:

#!/bin/sh

# Usage ./rfkill-toggle.sh [IDENTIFIER]
# where IDENTIFIER is the index no. of an rfkill switch or one of:
#   wifi wlan bluetooth uwb ultrawideband wimax wwan gps fm nfc

if [ -z $1 ]; then
    echo -n "enter a valid identifier; possible identifier: "
    rfkill list --output type -n | paste -s -d, -
    exit 1
fi

ID=`rfkill list "$1" 2>/dev/null | head -c 1 | cut -f 1`
SOFT="/sys/class/rfkill/rfkill$ID/soft"

if [ ! -f "$SOFT" ]; then
    echo -n "no such identifier; possible identifier: "
    rfkill list --output type -n | paste -s -d, -
    exit 1
fi

ACTION="block"
if [ $(cat "$SOFT") -eq 1 ]; then
    ACTION="unblock"
fi

rfkill "$ACTION" "$ID"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment