-
Notifications
You must be signed in to change notification settings - Fork 4
/
switch_edimax.sh
executable file
·118 lines (111 loc) · 2.24 KB
/
switch_edimax.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
PF=0
# read config
. ./switch_edimax.cfg
PrintConfig () {
echo "Reading config...." >&2
echo "Using config:"
echo "URL: $URL" >&2
echo "HEADER: $HEADER" >&2
echo "ON_XML: $ON_XML" >&2
echo "OFF_XML: $OFF_XML" >&2
echo "STATUS_XML: $STATUS_XML" >&2
echo "----------------------------"
}
Usage () {
echo "Usage:"
echo "./switch_edimax.sh [-c][-pf][-10su]"
echo ""
echo "Switch Edimax on, off or request status"
echo ""
echo "Config:"
echo " -c or --config Print config"
echo ""
echo "Flag:"
echo " -pf or --post-file Send xml via wgets post-file - not available at older wget"
echo ""
echo "Options:"
echo " -1 or --on Send on.xml to Edimax Smartplug"
echo " -0 or --off Send off.xml to Edimax Smartplug"
echo " -s or --status Send status.xml to Edimax Smartplug"
echo " -h or --help Print this Usage"
echo " -u or --usage Print this Usage"
echo ""
}
if [ $# -lt 1 ]
then
echo "wrong"
Usage
exit 1
fi
while [ "$#" -gt "0" ]
do
case $1 in
-c|--config)
PrintConfig
exit 1
;;
*)
break
;;
esac
done
while [ "$#" -gt "0" ] && [ "$PF" -eq "0" ]
do
case $1 in
-pf|--post-file)
shift
PF=1
break
;;
*)
break
;;
esac
done
while [ "$#" -gt "0" ]
do
case $1 in
-1|--on)
shift
if [ "$PF" -eq "1" ]
then
wget -q -O- $URL --post-data="$(cat $ON_XML)" --header=$HEADER
else
wget -q -O- $URL --post-file=$ON_XML --header=$HEADER
fi
exit 0
;;
-0|--off)
shift
if [ "$PF" -eq "1" ]
then
wget -q -O- $URL --post-data="$(cat $OFF_XML)" --header=$HEADER
else
wget -q -O- $URL --post-file=$OFF_XML --header=$HEADER
fi
exit 0
;;
-s|--status)
shift
if [ "$PF" -eq "1" ]
then
wget -q -O- $URL --post-data="$(cat $STATUS_XML)" --header=$HEADER
else
wget -q -O- $URL --post-file=$STATUS_XML --header=$HEADER
fi
exit 0
;;
-u|-h|--help|--usage)
shift
Usage
exit 0
;;
*)
shift
echo "Syntax Error"
Usage
exit 1
;;
esac
done