Create Makefile installation; update copyright core command. TODO replace installation.py script.

This commit is contained in:
adator
2025-10-28 01:02:27 +01:00
parent 05b15f2f18
commit 99f8949681
4 changed files with 132 additions and 1 deletions

55
Makefile Normal file
View File

@@ -0,0 +1,55 @@
OS := $(shell uname -s)
CURRENT_USER := $(shell whoami)
PYTHON_VERSION := $(shell python3 -V)
HOME_DIR := $(shell echo $$HOME)
SHELL := /bin/bash
install:
ifeq ($(wildcard config/configuration.yaml),)
$(error You must provide the Configuration file: config/configuration.yaml)
endif
ifeq ($(OS), Linux)
$(info Installation for os : $(OS))
$(info Python version: $(PYTHON_VERSION))
$(info Home directory: $(HOME_DIR))
@python3 core/install.py --check-version
@if [ $$? -eq 0 ]; then \
echo "Python Version OK! Well done :)"; \
else \
echo "Error: Script failed with exit code $$?"; \
exit 1; \
fi
$(info Creating the systemd user folder...)
mkdir -p $(HOME_DIR)/.config/systemd/user
$(info Creating Python Virtual Environment...)
python3 -m venv .pyenv
@. .pyenv/bin/activate && \
python -m pip install --upgrade pip && \
pip cache purge && \
pip install -r requirements.txt
@. .pyenv/bin/activate && python core/install.py --install
loginctl enable-linger $(CURRENT_USER)
@sleep 2
@export echo $DBUS_SESSION_BUS_ADDRESS && \
systemctl --user daemon-reload && \
systemctl --user start defender
endif
clean:
ifeq ($(OS), Linux)
@if [ -e .pyenv ]; then \
rm -rf .pyenv; \
echo "Virtual Env has been removed!"; \
fi
@if [ -e $(HOME_DIR)/.config/systemd/user/defender.service ]; then \
rm $(HOME_DIR)/.config/systemd/user/defender.service; \
echo "Systemd file has been removed!"; \
fi
@export echo $DBUS_SESSION_BUS_ADDRESS && systemctl --user daemon-reload && echo "Systemd Daemon reloaded!"
endif

70
core/install.py Normal file
View File

@@ -0,0 +1,70 @@
import argparse
import os
import sys
from pathlib import Path
from platform import python_version_tuple
parser = argparse.ArgumentParser(description="Python Installation Code")
parser.add_argument('--check-version', action='store_true', help='Check if the python version is ok!')
parser.add_argument('--install', action='store_true', help='Run the installation')
args = parser.parse_args()
PYTHON_REQUIRED_VERSION = (3, 10, 0)
PYTHON_SYSTEM_VERSION = tuple(map(int, python_version_tuple()))
ROOT_PATH = os.getcwd()
PYENV = Path(f'{ROOT_PATH}/.pyenv/bin/python')
USER_HOME_DIRECTORY = Path.home()
SYSTEMD_PATH = Path(USER_HOME_DIRECTORY).joinpath('.config', 'systemd', 'user')
PY_EXEC = 'defender.py'
SERVICE_FILE_NAME = 'defender.service'
def check_python_requirement():
if PYTHON_SYSTEM_VERSION < PYTHON_REQUIRED_VERSION:
raise RuntimeError(f"Your Python Version is not meeting the requirement, System Version: {PYTHON_SYSTEM_VERSION} < Required Version {PYTHON_REQUIRED_VERSION}")
def create_service_file():
pyenv = PYENV
systemd_path = SYSTEMD_PATH
py_exec = PY_EXEC
service_file_name = SERVICE_FILE_NAME
if not Path(systemd_path).exists():
print("[!] Folder not available")
sys.exit(1)
contain = f'''[Unit]
Description=Defender IRC Service
[Service]
ExecStart={pyenv} {py_exec}
WorkingDirectory={ROOT_PATH}
SyslogIdentifier=Defender
Restart=on-failure
[Install]
WantedBy=default.target
'''
with open(Path(systemd_path).joinpath(service_file_name), "w") as file:
file.write(contain)
print('Service file generated with current configuration')
print('Running IRC Service ...')
print(f"#"*24)
print("Installation complete ...")
print("If the configuration is correct, then you must see your service connected to your irc server")
print(f"If any issue, you can see the log file for debug {ROOT_PATH}{os.sep}logs{os.sep}defender.log")
print(f"#"*24)
def main():
if args.check_version:
check_python_requirement()
sys.exit(0)
if args.install:
create_service_file()
sys.exit(0)
if __name__ == "__main__":
main()

View File

@@ -1220,7 +1220,7 @@ class Irc:
self.Protocol.send_notice(
nick_from=dnickname,
nick_to=fromuser,
msg=f">> Defender V.{self.Config.CURRENT_VERSION} Developped by adator®."
msg=f">> Defender V{self.Config.CURRENT_VERSION} Developped by adator®."
)
return None

6
requirements.txt Normal file
View File

@@ -0,0 +1,6 @@
Faker==33.1.2
psutil==6.1.1
PyYAML==6.0.2
requests==2.32.3
SQLAlchemy==2.0.36
unrealircd_rpc_py==3.0.2