Create sha256 checksum verification
This commit is contained in:
parent
eefbb55f2c
commit
9f96be7af8
|
|
@ -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,6 +71,18 @@ class Danix():
|
|||
|
||||
os.system(f"mkdir /tmp/{filesystem}")
|
||||
os.system(f"curl --silent -LO --output-dir /tmp/{filesystem} {settings.REPO_NAME}/{settings.ROOT_FS}")
|
||||
|
||||
resp_downloaded_checksum = download_checksum()
|
||||
resp_generateed_checksum = generate_checksum(f"/tmp/{filesystem}/{settings.ROOT_FS}")
|
||||
|
||||
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}")
|
||||
|
|
@ -95,3 +109,5 @@ class Danix():
|
|||
print("0 erros reported!")
|
||||
|
||||
Danix.navigate(filesystem)
|
||||
else:
|
||||
get_message("🔴 Failed integrity base image verification!", True, 1)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue