diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b55526..1719788 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,4 @@ jobs: sudo apt update -y sudo apt install make -y cd danix - sudo make install - sudo make aliases - sudo danix + diff --git a/README.md b/README.md index 5b165da..15f107d 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ * Author: Vinicius F. da Silva -* Version 0.1 +* Version 0.1.4 * Released: 2023 A very simple subsystem builder! The Danixfs is a root filesystem management! Build a Alpine subsystem and pre install -essentials packages and compiers from languanges choice by user: +essentials packages and compilers from languages choice by user: # Image: #### Building a clike environment @@ -31,13 +31,19 @@ essentials packages and compiers from languanges choice by user: * tar 1.34 or higher * python3 or higher * pip3 or higher -# Run Danix + * python-is-python3 +# Install Danix -```shell -$ sudo make config +```shell +$ cd danixfs ``` -To clean configuracion run: + +```shell +$ sudo make install +``` + +To clean configuration run: ```shell $ sudo make clean @@ -49,12 +55,17 @@ $ danix -h ![](./img/img_vi.png) +# Remove Danix +To remove danix run: +```shell +$ sudo danixclean +``` # Common erros ![](./img/img_vii.png) -To fix this erro open file *registry.py* located in /usr/local/lib/python3.10/dist-packages/django/apps/ +To fix this problem open file *registry.py* Search for @@ -62,10 +73,30 @@ Search for raise RuntimeError("populate() isn't reentrant")" ``` -line. And replace for following code: +line. And replace by following code: ```python self.app_configs = {} ``` -Save file and try again +Save file and run + + +```shell +$ sudo make clean +``` + + +```shell +$ sudo make install +``` + +```shell +$ sudo make aliases +``` + +Close terminal, open again and run + +```shell +$ danix --help +``` diff --git a/danix/danixfs.py b/danix/danixfs.py index 47df02c..dd1a5a5 100644 --- a/danix/danixfs.py +++ b/danix/danixfs.py @@ -1,6 +1,8 @@ import os, settings, app from sh import du from settings import MAIN_REPO +from utils import download_checksum, validate_checksum +from utils import get_message, check_equal_sentence as equals, generate_checksum, remove_checksum_files class Danix(): @staticmethod @@ -69,29 +71,43 @@ class Danix(): os.system(f"mkdir /tmp/{filesystem}") os.system(f"curl --silent -LO --output-dir /tmp/{filesystem} {settings.REPO_NAME}/{settings.ROOT_FS}") - os.system(f"tar -xf /tmp/{filesystem}/{settings.ROOT_FS} -C /tmp/{filesystem}") - os.system(f"rm /tmp/{filesystem}/{settings.ROOT_FS}") - os.system(f"mv /tmp/{filesystem} {MAIN_REPO}") - - print("\nPlease! Wait a moment!!") - print("Building container:") - print(f"Installing {len(packages)} packages\n") - - for command in config_comands: - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs {command}") - - for package in packages: - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add {package}") - - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add fish") - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add ruby") - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs gem install lolcat") - os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/dev >/dev/null 2>&1") - os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/proc >/dev/null 2>&1") - os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/sys >/dev/null 2>&1") - - print(f"Environment builded succesfully!") - print("0 erros reported!") + resp_downloaded_checksum = download_checksum() + resp_generateed_checksum = generate_checksum(f"/tmp/{filesystem}/{settings.ROOT_FS}") - Danix.navigate(filesystem) + is_downloaded_and_generate = equals(resp_downloaded_checksum, 0) and equals(resp_generateed_checksum, 0) + + is_valid_checksum = validate_checksum(filesystem) + + remove_checksum_files() + + if is_downloaded_and_generate and is_valid_checksum: + + os.system(f"tar -xf /tmp/{filesystem}/{settings.ROOT_FS} -C /tmp/{filesystem}") + os.system(f"rm /tmp/{filesystem}/{settings.ROOT_FS}") + os.system(f"mv /tmp/{filesystem} {MAIN_REPO}") + + print("\nPlease! Wait a moment!!") + print("Building container:") + print(f"Installing {len(packages)} packages\n") + + for command in config_comands: + os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs {command}") + + for package in packages: + os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add {package}") + + os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add fish") + os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add ruby") + os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs gem install lolcat") + + os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/dev >/dev/null 2>&1") + os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/proc >/dev/null 2>&1") + os.system(f"rm -r {MAIN_REPO}{filesystem}/danixfs/sys >/dev/null 2>&1") + + print(f"Environment builded succesfully!") + print("0 erros reported!") + + Danix.navigate(filesystem) + else: + get_message("🔴 Failed integrity base image verification!", True, 1) diff --git a/danix/makefile b/danix/makefile index 65f6d78..44a7ee8 100644 --- a/danix/makefile +++ b/danix/makefile @@ -50,7 +50,7 @@ else @$(PYTHON) $(DANIX_PATH)/manage.py migrate - @echo "Installation successfully!!! Please 'make aliases without sudo'" + @echo "Installation successfully!!! Please 'make aliases without' sudo" endif diff --git a/danix/utils.py b/danix/utils.py index 659b8d1..0220878 100644 --- a/danix/utils.py +++ b/danix/utils.py @@ -1,5 +1,33 @@ import os -from settings import MAIN_REPO, MAIN_DIR, BASE_DIR +import sh +from settings import MAIN_REPO, MAIN_DIR, BASE_DIR, REPO_NAME + + +def download_checksum(): + + return os.system(f"curl --silent -LO --output-dir /tmp/ {REPO_NAME}danixfs.checksum") + + +def generate_checksum(package_path): + os.system("touch /tmp/local_danixfs.checksum") + return os.system(f"sha256sum {package_path} >> /tmp/local_danixfs.checksum") + + +def remove_checksum_files(): + os.system("rm /tmp/danixfs.checksum >/dev/null 2>&1") + os.system("rm /tmp/local_danixfs.checksum >/dev/null 2>&1") + +def read_line(file_path): + file = open(file_path, 'r') + checksum = file.readlines() + return checksum + +def validate_checksum(filesystem): + + remote_checksum = ''.join(read_line(f"/tmp/danixfs.checksum")).replace(f"/tmp/{filesystem}/", "") + local_checksum = ''.join(read_line(f"/tmp/local_danixfs.checksum")).replace(f"/tmp/{filesystem}/", "") + + return True if local_checksum == remote_checksum else False def separate(path): list_path = path.split(" ") @@ -91,6 +119,7 @@ def print_environment_list_header(): @staticmethod def check_equal_sentence(left_expression, right_expression): + return left_expression == right_expression @staticmethod diff --git a/danixfs.tar.gz b/danixfs.tar.gz deleted file mode 100644 index e4650d6..0000000 Binary files a/danixfs.tar.gz and /dev/null differ