Skip to content

Commit

Permalink
Moving configuration file to /etc/fw-fanctrl (#34)
Browse files Browse the repository at this point in the history
* removing now useless "sleep" strategy and fixing a typo in the config.json file

* moving resources to /etc/fw-fanctrl as suggested in issue comment #11 (comment)

removing the use of envsubst, as there is no need for environment variable replacement in services anymore

* small addition in .gitignore

* removing now useless `requirements.txt`
  • Loading branch information
leopoldhub authored May 18, 2024
1 parent e97f4b3 commit 176d34b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ fabric.properties
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sudo ./install.sh
```

This bash script is going to create and enable a service that runs this repo's main script, `fanctrl.py`.
It will copy `fanctrl.py` (to an executable file `fw-fanctrl`) and `./bin/ectool` to `/usr/local/bin` and create a config file in `/home/<user>/.config/fw-fanctrl/config.json`
It will copy `fanctrl.py` (to an executable file `fw-fanctrl`) and `./bin/ectool` to `/usr/local/bin` and create a config file in `/etc/fw-fanctrl/config.json`

# Update

Expand All @@ -34,7 +34,7 @@ sudo ./install.sh remove

# Configuration

There is a single `config.json` file located at `/home/<user>/.config/fw-fanctrl/config.json`.
There is a single `config.json` file located at `/etc/fw-fanctrl/config.json`.

(You will need to reload the configuration with)
```
Expand Down
9 changes: 1 addition & 8 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
"defaultStrategy": "lazy",
"strategyOnDischarging" : "",
"strategies": {
"sleep": {
"fanSpeedUpdateFrequency": 5,
"movingAverageInterval": 40,
"speedCurve": [
{ "temp": 0, "speed": 0 }
]
},
"lazyest": {
"laziest": {
"fanSpeedUpdateFrequency": 5,
"movingAverageInterval": 40,
"speedCurve": [
Expand Down
7 changes: 4 additions & 3 deletions fanctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import threading
from time import sleep

SOCKETS_FOLDER_PATH = "/tmp/"
COMMANDS_SOCKET_FILE_PATH = os.path.join(SOCKETS_FOLDER_PATH, ".fw-fanctrl.commands.sock")
RESOURCE_FOLDER_PATH = "/etc/fw-fanctrl"
DEFAULT_CONFIGURATION_FILE_PATH = os.path.join(RESOURCE_FOLDER_PATH, "config.json")
COMMANDS_SOCKET_FILE_PATH = os.path.join(RESOURCE_FOLDER_PATH, ".fw-fanctrl.commands.sock")

parser = None

Expand Down Expand Up @@ -270,7 +271,7 @@ def main():

runGroup = parser.add_argument_group("run")
runGroup.add_argument("--run", help="run the service", action="store_true")
runGroup.add_argument("--config", type=str, help="Path to config file", default="config.json")
runGroup.add_argument("--config", type=str, help="Path to config file", default=DEFAULT_CONFIGURATION_FILE_PATH)
runGroup.add_argument(
"--no-log", help="Disable print speed/meanTemp to stdout", action="store_true"
)
Expand Down
28 changes: 19 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function sanitizePath() {
echo "$SANITIZED_PATH"
}

# remove remaining legacy files
function uninstall_legacy() {
rm -rf "$HOME/.config/fw-fanctrl"
}

function uninstall() {
# remove program services based on the services present in the './services' folder
echo "removing services"
Expand Down Expand Up @@ -54,22 +59,28 @@ function uninstall() {
rm "/usr/local/bin/fw-fanctrl"
ectool autofanctrl # restore default fan manager
rm "/usr/local/bin/ectool"
rm -rf "$HOME/.config/fw-fanctrl"
rm -rf "/etc/fw-fanctrl"

uninstall_legacy
}

# move remaining legacy files
function move_legacy() {
rm "/usr/local/bin/fanctrl.py" 2> "/dev/null" || true
(cp "$HOME/.config/fw-fanctrl"/* "/etc/fw-fanctrl/" && rm -rf "$HOME/.config/fw-fanctrl") 2> "/dev/null" || true
}

function install() {
if [ "$1" != "--no-requirements" ]; then
pip3 install -r requirements.txt || exit 1
fi
cp "./bin/ectool" "/usr/local/bin"
cp "./fanctrl.py" "/usr/local/bin/fw-fanctrl"
chmod +x "/usr/local/bin/fw-fanctrl"
chown "$LOGNAME:$LOGNAME" "/usr/local/bin/fw-fanctrl"
mkdir -p "$HOME/.config/fw-fanctrl"
cp -n "./config.json" "$HOME/.config/fw-fanctrl/" || true
mkdir -p "/etc/fw-fanctrl"

# cleaning legacy file
rm "/usr/local/bin/fanctrl.py" 2> "/dev/null" || true
cp -n "./config.json" "/etc/fw-fanctrl" 2> "/dev/null" || true

move_legacy

# create program services based on the services present in the './services' folder
echo "creating services"
Expand All @@ -80,8 +91,7 @@ function install() {
sudo systemctl stop "$SERVICE"
fi
echo "creating '/etc/systemd/system/$SERVICE$SERVICE_EXTENSION'"
# 'envsubst' replace environment variables in the service file
envsubst < "$SERVICES_DIR/$SERVICE$SERVICE_EXTENSION" | sudo tee "/etc/systemd/system/$SERVICE$SERVICE_EXTENSION" > "/dev/null"
sudo cp -f "$SERVICES_DIR/$SERVICE$SERVICE_EXTENSION" "/etc/systemd/system/$SERVICE$SERVICE_EXTENSION" > "/dev/null"
sudo systemctl daemon-reload
echo "enabling [$SERVICE]"
sudo systemctl enable "$SERVICE"
Expand Down
Empty file removed requirements.txt
Empty file.
2 changes: 1 addition & 1 deletion services/fw-fanctrl.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ After=multi-user.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /usr/local/bin/fw-fanctrl --run --config "$HOME/.config/fw-fanctrl/config.json" --no-log
ExecStart=/usr/bin/python3 /usr/local/bin/fw-fanctrl --run --no-log
ExecStopPost=/bin/sh -c "ectool autofanctrl"
[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions services/system-sleep/fw-fanctrl-suspend
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

case $1 in
pre) runuser -l "$LOGNAME" -c "fw-fanctrl --pause" ;;
post) runuser -l "$LOGNAME" -c "fw-fanctrl --resume" ;;
pre) /usr/bin/python3 /usr/local/bin/fw-fanctrl --pause ;;
post) /usr/bin/python3 /usr/local/bin/fw-fanctrl --resume ;;
esac

0 comments on commit 176d34b

Please sign in to comment.