Skip to content

Commit

Permalink
create folder structure for config files using relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bkbilly committed Oct 30, 2022
1 parent fbe5ce7 commit 69298dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ It is inspired by [IOT Link](https://iotlink.gitlab.io/).
Install or update:
```shell
pip3 install -U lnxlink
lnxlink /absolute/path/to/config.yaml
lnxlink /path/to/config.yaml
```
You can manually update the configuration file `config.yaml` and restart the service with the use of systemctl:
```shell
Expand Down
12 changes: 7 additions & 5 deletions lnxlink/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env python3

import os
import yaml
import paho.mqtt.client as mqtt
import time
import signal
import threading
import json
from . import modules
import traceback
import importlib.metadata
import platform
import argparse
import paho.mqtt.client as mqtt
from . import modules
from . import config

version = importlib.metadata.version(__package__ or __name__)
Expand Down Expand Up @@ -225,9 +226,10 @@ def main():
required=True)
args = parser.parse_args()

config.setup_config(args.config)
config.setup_systemd(args.config)
lnxlink = LNXlink(args.config)
config_file = os.path.abspath(args.config)
config.setup_config(config_file)
config.setup_systemd(config_file)
lnxlink = LNXlink(config_file)
lnxlink.monitor_run_thread()

killer = GracefulKiller()
Expand Down
3 changes: 3 additions & 0 deletions lnxlink/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import subprocess
import shutil
from pathlib import Path


github_repository = "bkbilly/lnxlink/master"
Expand All @@ -17,6 +18,7 @@ def setup_config(config_path):
url = f"https://raw.githubusercontent.com/{github_repository}/config_temp.yaml"
r = requests.get(url)
try:
Path(config_path).parent.mkdir(parents=True, exist_ok=True)
with open(config_path, 'wb') as config:
config.write(r.content)
print(f"Created new template: {config_path}")
Expand Down Expand Up @@ -135,6 +137,7 @@ def setup_systemd(config_path):
sudo, cmd_user, service_url, service_location = get_service_vars(user_service)

# Install on SystemD
Path(service_location).mkdir(parents=True, exist_ok=True)
r = requests.get(service_url)
with open(f"{service_location}/lnxlink.service", 'wb') as config:
exec_cmd = f"{shutil.which('lnxlink')} -c {config_path}"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "lnxlink"
version = "2022.10.2"
version = "2022.10.3"
description = "Internet Of Things (IOT) integration with Linux using MQTT"
readme = "README.md"
keywords = ["lnxlink"]
Expand Down

0 comments on commit 69298dc

Please sign in to comment.