Skip to content

Commit e023050

Browse files
committed
Merge branch 'druck13-issue#36'
2 parents 5841386 + f06ac17 commit e023050

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

examples/install-service.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ NOLED="no"
99
NOBUTTON="no"
1010
BRIGHTNESS=255
1111

12+
ON_THRESHOLD_SET=false
13+
OFF_THRESHOLD_SET=false
14+
1215
OLD_THRESHOLD=""
1316
OLD_HYSTERESIS=""
1417

1518
SERVICE_PATH=/etc/systemd/system/pimoroni-fanshim.service
1619

20+
USAGE="sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> (--preempt) (--noled) (--nobutton)"
21+
1722
if ! [ -f "/usr/bin/python3" ]; then
1823
printf "Fan SHIM controller requires Python 3\n"
1924
printf "You should run: 'sudo apt install python3'\n"
@@ -56,13 +61,15 @@ while [[ $# -gt 0 ]]; do
5661
fi
5762
shift
5863
;;
59-
--on-threshold)
64+
-o|--on-threshold)
6065
ON_THRESHOLD="$2"
66+
ON_THRESHOLD_SET=true
6167
shift
6268
shift
6369
;;
64-
--off-threshold)
70+
-f|--off-threshold)
6571
OFF_THRESHOLD="$2"
72+
OFF_THRESHOLD_SET=true
6673
shift
6774
shift
6875
;;
@@ -81,12 +88,17 @@ while [[ $# -gt 0 ]]; do
8188
shift
8289
shift
8390
;;
84-
--brightness)
91+
-r|--brightness)
8592
BRIGHTNESS="$2"
8693
shift
8794
shift
8895
;;
8996
*)
97+
if [[ $1 == -* ]]; then
98+
printf "Unrecognised option: $1\n";
99+
printf "Usage: $USAGE\n";
100+
exit 1
101+
fi
90102
POSITIONAL_ARGS+=("$1")
91103
shift
92104
esac
@@ -115,10 +127,20 @@ if [ "$NOBUTTON" == "yes" ]; then
115127
fi
116128

117129
if ! [ "$1" == "" ]; then
130+
if [ $ON_THRESHOLD_SET ]; then
131+
printf "Refusing to overwrite explicitly set On Threshold ($ON_THRESHOLD) with positional argument!\n"
132+
printf "Please double-check your arguments and use one or the other!\n"
133+
exit 1
134+
fi
118135
ON_THRESHOLD=$1
119136
fi
120137

121138
if ! [ "$2" == "" ]; then
139+
if [ $OFF_THRESHOLD_SET ]; then
140+
printf "Refusing to overwrite explicitly set Off Threshold ($OFF_THRESHOLD) with positional argument!\n"
141+
printf "Please double-check your arguments and use one or the other!\n"
142+
exit 1
143+
fi
122144
(( OFF_THRESHOLD = ON_THRESHOLD - $2 ))
123145
fi
124146

@@ -134,7 +156,7 @@ Disable Button: $NOBUTTON
134156
Brightness: $BRIGHTNESS
135157
136158
To change these options, run:
137-
sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> (--preempt) (--noled) (--nobutton)
159+
$USAGE
138160
139161
Or edit: $SERVICE_PATH
140162

0 commit comments

Comments
 (0)