You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.6 KiB
97 lines
1.6 KiB
5 years ago
|
#!/bin/sh
|
||
|
|
||
5 years ago
|
# Control the network interfaces
|
||
|
# Depends: iproute2, netctl
|
||
|
|
||
5 years ago
|
WIRELESS="wlan0"
|
||
|
ETHERNET="eth0"
|
||
|
PROFILE="eth0-dhcp"
|
||
|
|
||
|
help() {
|
||
|
B=$(tput bold)
|
||
|
U=$(tput smul)
|
||
|
N=$(tput sgr0)
|
||
|
|
||
|
cat << EOF
|
||
|
${B}NAME${N}
|
||
4 years ago
|
netictl - control the network interfaces
|
||
5 years ago
|
|
||
|
${B}SYNOPSIS${N}
|
||
4 years ago
|
${B}netictl${N} ${U}OPTION${N} [${U}ARG${N}]
|
||
5 years ago
|
|
||
|
${B}OPTIONS${N}
|
||
5 years ago
|
${B}-h${N} Display usage message and exit.
|
||
|
|
||
4 years ago
|
${B}-e${N} ${U}STATE${N}
|
||
|
Set ethernet ${U}STATE${N}, possible values: on/off, 1/0.
|
||
5 years ago
|
|
||
4 years ago
|
${B}-w${N} ${U}STATE${N}
|
||
|
Set wireless ${U}STATE${N}, possible values: on/off, 1/0.
|
||
5 years ago
|
EOF
|
||
|
}
|
||
|
|
||
|
# Exit if no option is provided
|
||
|
[ "$#" -eq 0 ] && help && exit 1
|
||
|
|
||
5 years ago
|
SCRIPT="$(basename "$0")"
|
||
5 years ago
|
|
||
|
# Option handling
|
||
5 years ago
|
while getopts ':h?e:w:' opt; do
|
||
|
case $opt in
|
||
|
h)
|
||
|
help
|
||
5 years ago
|
exit 0
|
||
5 years ago
|
;;
|
||
|
e)
|
||
4 years ago
|
DEV="ethernet"
|
||
|
ARG="$OPTARG"
|
||
5 years ago
|
;;
|
||
|
w)
|
||
4 years ago
|
DEV="wireless"
|
||
|
ARG="$OPTARG"
|
||
5 years ago
|
;;
|
||
|
:)
|
||
|
echo "$SCRIPT: option requires an argument '$OPTARG'"
|
||
|
echo "Try '$SCRIPT -h' for more information."
|
||
|
exit 1
|
||
|
;;
|
||
|
\?)
|
||
|
echo "$SCRIPT: invalid option '$OPTARG'"
|
||
|
echo "Try '$SCRIPT -h' for more information."
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
ethernet() {
|
||
|
sudo netctl stop $PROFILE
|
||
|
sudo ip link set $ETHERNET down
|
||
|
|
||
|
if [ "$1" -eq 1 ]; then
|
||
|
sudo netctl start $PROFILE
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
wireless() {
|
||
|
if [ "$1" -eq 1 ]; then
|
||
|
sudo ip link set $WIRELESS up
|
||
|
else
|
||
|
sudo ip link set $WIRELESS down
|
||
|
fi
|
||
|
}
|
||
|
|
||
4 years ago
|
# Arg handling
|
||
|
case "$ARG" in
|
||
5 years ago
|
1 | on)
|
||
4 years ago
|
[ "$DEV" = "ethernet" ] && ethernet 1 || wireless 1
|
||
5 years ago
|
;;
|
||
|
0 | off)
|
||
4 years ago
|
[ "$DEV" = "ethernet" ] && ethernet 0 || wireless 0
|
||
5 years ago
|
;;
|
||
|
*)
|
||
4 years ago
|
echo "$SCRIPT: invalid argument '$ARG'"
|
||
5 years ago
|
echo "Try '$SCRIPT -h' for more information."
|
||
5 years ago
|
exit 1
|
||
|
;;
|
||
|
esac
|