-
Notifications
You must be signed in to change notification settings - Fork 15
/
dockctl
executable file
·60 lines (55 loc) · 1.5 KB
/
dockctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
# This is a shell script to automate "docking" and "undocking" Linux laptop
# Written and tested on Fedora 28
# Assign help text to variable for user later
HELP="Usage: dockctl [ dock | undock ]"
# Ensure that only a single parameter was passed
# Display help text if more than 1 parameter was supplied
if [ "$#" -ne 1 ]; then
echo "Error: Incorrect number of parameters; please supply only a single subcommand"
echo $HELP
exit 1
fi
# Check for existence of and get path for wifictl if present
if hash wifictl 2>/dev/null; then
WIFICMD="$(command -v wifictl)"
else
echo "wifictl is required but not found, aborting"
exit 1
fi
# Check for existence of and get path for synclient if present
if hash synclient 2>/dev/null; then
SYNCMD="$(command -v synclient)"
else
echo "synclient is required but not found, aborting"
exit 1
fi
# Take action based on subcommand provided by the user
case "$1" in
dock)
# Turn Wi-Fi interface off using wifictl
$WIFICMD off
# Start Synergy client
$SYNCMD start > /dev/null 2>&1
;;
undock)
# Turn Wi-Fi interface off
$WIFICMD on
# Stop Synergy client
$SYNCMD stop > /dev/null 2>&1
;;
help)
echo $HELP
exit 0
;;
--help)
echo $HELP
exit 0
;;
*)
# Present an error about an unsupported subcommand
echo "Unknown subcommand provided"
echo $HELP
exit 1
;;
esac