-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
740 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.o | ||
*.deb | ||
systemd/fan-control.service | ||
src/fan-control | ||
src/*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,58 @@ | ||
# MIT License | ||
|
||
.PHONY:all | ||
CFLAGS= -O2 -Wall | ||
# Copyright (c) 2022 Nick Peng | ||
|
||
all: fan-control | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
PKG_CONFIG := pkg-config | ||
DESTDIR := | ||
PREFIX := /usr | ||
SBINDIR := $(PREFIX)/sbin | ||
SYSCONFDIR := /etc | ||
RUNSTATEDIR := /var/run | ||
SYSTEMDSYSTEMUNITDIR := $(shell ${PKG_CONFIG} --variable=systemdsystemunitdir systemd) | ||
FAN_CONTROL_SYSTEMD = systemd/fan-control.service | ||
|
||
.PHONY: all clean install FAN_CONTROL_BIN package | ||
all: package | ||
|
||
FAN_CONTROL_BIN: $(FAN_CONTROL_SYSTEMD) | ||
$(MAKE) $(MFLAGS) -C src all | ||
|
||
$(FAN_CONTROL_SYSTEMD): systemd/fan-control.service.in | ||
cp $< $@ | ||
sed -i 's|@SBINDIR@|$(SBINDIR)|' $@ | ||
sed -i 's|@SYSCONFDIR@|$(SYSCONFDIR)|' $@ | ||
sed -i 's|@RUNSTATEDIR@|$(RUNSTATEDIR)|' $@ | ||
|
||
package: FAN_CONTROL_BIN | ||
cd package && ./make.sh -o $(shell pwd) | ||
|
||
clean: | ||
$(RM) fan-control *.o | ||
$(MAKE) $(MFLAGS) -C src clean | ||
$(RM) $(FAN_CONTROL_SYSTEMD) | ||
$(RM) fan-control*.deb | ||
|
||
fan-control: fan-control.o | ||
$(CC) $(CFLAGS) $^ -o $@ -lwiringPi | ||
install: FAN_CONTROL_BIN | ||
install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/default etc/default/fan-control | ||
install -v -m 0755 -D -t $(DESTDIR)$(SYSCONFDIR)/init.d etc/init.d/fan-control | ||
install -v -m 0640 -D -t $(DESTDIR)$(SYSCONFDIR)/fan-control etc/fan-control/fan-control.conf | ||
install -v -m 0755 -D -t $(DESTDIR)$(SBINDIR) src/fan-control | ||
install -v -m 0644 -D -t $(DESTDIR)$(SYSTEMDSYSTEMUNITDIR) systemd/fan-control.service | ||
|
||
%.o : %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/sh | ||
# | ||
# MIT License | ||
|
||
# Copyright (c) 2022 Nick Peng | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
### BEGIN INIT INFO | ||
# Provides: fan-control | ||
# Required-Start: $network | ||
# Required-Stop: $network | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: | ||
# Short-Description: Start fan-control service | ||
### END INIT INFO | ||
|
||
PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
|
||
FAN_CONTROL=/usr/sbin/fan-control | ||
PIDFILE=/run/fan-control.pid | ||
|
||
test -x $FAN_CONTROL || exit 5 | ||
|
||
case $1 in | ||
start) | ||
$FAN_CONTROL -d -p $PIDFILE | ||
while true; do | ||
if [ -e "$PIDFILE" ]; then | ||
break; | ||
fi | ||
sleep .5 | ||
done | ||
PID="$(cat $PIDFILE 2>/dev/null)" | ||
if [ -z "$PID" ]; then | ||
echo "start fan-control service failed." | ||
exit 1 | ||
fi | ||
if [ ! -e "/proc/$PID" ]; then | ||
echo "start fan-control service failed." | ||
exit 1 | ||
fi | ||
echo "start fan-control service success." | ||
;; | ||
stop) | ||
if [ ! -f "$PIDFILE" ]; then | ||
echo "fan-control service is stopped." | ||
exit 0 | ||
fi | ||
PID="$(cat $PIDFILE 2>/dev/null)" | ||
if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then | ||
echo "fan-control service is stopped" | ||
exit 0 | ||
fi | ||
|
||
kill -TERM "$PID" | ||
if [ $? -ne 0 ]; then | ||
echo "Stop fan-control service failed." | ||
exit 1; | ||
fi | ||
LOOP=1 | ||
while true; do | ||
if [ ! -d "/proc/$PID" ]; then | ||
break; | ||
fi | ||
|
||
if [ $LOOP -gt 12 ]; then | ||
kill -9 "$PID" | ||
break; | ||
fi | ||
LOOP=$((LOOP+1)) | ||
sleep .5 | ||
done | ||
echo "Stop fan-control service success." | ||
;; | ||
restart) | ||
"$0" stop && "$0" start | ||
;; | ||
status) | ||
PID="$(cat "$PIDFILE" 2>/dev/null)" | ||
if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then | ||
echo "fan-control service is not running." | ||
exit 1 | ||
fi | ||
echo "fan-control service is running." | ||
status=$? | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
exit 2 | ||
;; | ||
esac | ||
|
||
exit $status | ||
|
Oops, something went wrong.