Riyyi
5 years ago
2 changed files with 94 additions and 29 deletions
@ -0,0 +1,94 @@
|
||||
#!/bin/sh |
||||
|
||||
WIRELESS="wlan0" |
||||
ETHERNET="eth0" |
||||
PROFILE="eth0-dhcp" |
||||
|
||||
help() { |
||||
B=$(tput bold) |
||||
U=$(tput smul) |
||||
N=$(tput sgr0) |
||||
|
||||
cat << EOF |
||||
${B}NAME${N} |
||||
netctl.sh - network manager |
||||
|
||||
${B}SYNOPSIS${N} |
||||
${B}netctl.sh${N} [${U}OPTION${N}] [${U}ARG${N}] |
||||
|
||||
${B}OPTIONS${N} |
||||
${B}-e${N} [${U}ARG${N}] |
||||
Perform action on ethernet. |
||||
|
||||
${B}-w${N} [${U}ARG${N}] |
||||
Perform action on wireless. |
||||
|
||||
${B}ARGS${N} |
||||
1, on |
||||
Enable selected option. |
||||
|
||||
0, off |
||||
Disable selected option. |
||||
EOF |
||||
} |
||||
|
||||
# Exit if no option is provided |
||||
[ "$#" -eq 0 ] && help && exit 1 |
||||
|
||||
SCRIPT="$(basename "$0")" |
||||
# Option handling |
||||
while getopts ':h?e:w:' opt; do |
||||
case $opt in |
||||
h) |
||||
help |
||||
exit 1 |
||||
;; |
||||
e) |
||||
dev="ethernet" |
||||
;; |
||||
w) |
||||
dev="wireless" |
||||
;; |
||||
:) |
||||
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 |
||||
} |
||||
|
||||
[ $OPTIND -ge 2 ] && shift $((OPTIND - 2)) |
||||
case "$1" in |
||||
1 | on) |
||||
[ "$dev" = "ethernet" ] && ethernet 1 || wireless 1 |
||||
;; |
||||
0 | off) |
||||
[ "$dev" = "ethernet" ] && ethernet 0 || wireless 0 |
||||
;; |
||||
*) |
||||
help |
||||
exit 1 |
||||
;; |
||||
esac |
@ -1,29 +0,0 @@
|
||||
#!/bin/sh |
||||
|
||||
WIRELESS="wlan0" |
||||
WIRED="eth0" |
||||
PROFILE="eth0-dhcp" |
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then |
||||
exit; |
||||
fi |
||||
|
||||
# Enable/disable wireless |
||||
if [ "$1" = "w" ] || [ "$1" = "$WIRELESS" ]; then |
||||
if [ "$2" = "1" ]; then |
||||
sudo ip link set $WIRELESS up |
||||
else |
||||
sudo ip link set $WIRELESS down |
||||
fi |
||||
fi |
||||
|
||||
# Enable/disable wired |
||||
if [ "$1" = "e" ] || [ "$1" = "$WIRED" ]; then |
||||
|
||||
sudo netctl stop $PROFILE |
||||
sudo ip link set $WIRED down |
||||
|
||||
if [ "$2" = "1" ]; then |
||||
sudo netctl start $PROFILE |
||||
fi |
||||
fi |
Loading…
Reference in new issue