diff --git a/danix/danixfs.py b/danix/danixfs.py index f266d3a..c903531 100644 --- a/danix/danixfs.py +++ b/danix/danixfs.py @@ -17,32 +17,53 @@ class Danix(): @staticmethod def rm(filesystem_name): - return os.system(f"rm -r {MAIN_REPO}{filesystem_name} >/dev/null 2>&1") + + os.system(f'fuser -km {MAIN_REPO}{filesystem_name}/danixfs/proc/') + os.system(f"umount {MAIN_REPO}{filesystem_name}/danixfs/proc/ ") + + os.system(f'fuser -km {MAIN_REPO}{filesystem_name}/danixfs/sys/') + os.system(f"umount {MAIN_REPO}{filesystem_name}/danixfs/sys/ >/dev/null 2>&1") + + os.system(f'fuser -km {MAIN_REPO}{filesystem_name}/danixfs/dev/') + os.system(f"umount {MAIN_REPO}{filesystem_name}/danixfs/dev/ >/dev/null 2>&1") + + #return os.system(f"rm -r {MAIN_REPO}{filesystem_name}") @staticmethod def get_size(environment_name, snapshot_name): try: + if snapshot_name is None: - return du(f'{MAIN_REPO}{environment_name}/','-ch').split('\n')[-2].split('\t')[0] + return du( + f'{MAIN_REPO}{environment_name}/',f'-ch', + f'--exclude={MAIN_REPO}{environment_name}/danixfs/proc/*', + f'--exclude={MAIN_REPO}{environment_name}/danixfs/dev/*', + f'--exclude={MAIN_REPO}{environment_name}/danixfs/sys/*' + ).split('\n')[-2].split('\t')[0] else: return du(f'{MAIN_REPO}.snapshots/{snapshot_name}/{environment_name}.tar.gz','-ch').split('\n')[-2].split('\t')[0] - except Exception: + except Exception as e: + print(e) return "00M" @staticmethod def make_snapshot(filesystem_name, snapshot_name): os.system(f"mkdir {MAIN_REPO}.snapshots/{snapshot_name} >/dev/null 2>&1") - resp = os.system(f"tar czf {MAIN_REPO}.snapshots/{snapshot_name}/{filesystem_name}.tar.gz {MAIN_REPO}{filesystem_name}/ >/dev/null 2>&1") + exclude_proc_dir = f"{MAIN_REPO}{filesystem_name}/danixfs/proc/*" + exclude_sys_dir = f"{MAIN_REPO}{filesystem_name}/danixfs/sys/*" + exclude_dev_dir = f"{MAIN_REPO}{filesystem_name}/danixfs/dev/*" + + resp = os.system(f"tar -czf {MAIN_REPO}.snapshots/{snapshot_name}/{filesystem_name}.tar.gz --exclude={exclude_proc_dir} --exclude={exclude_dev_dir} --exclude={exclude_sys_dir} {MAIN_REPO}{filesystem_name}/ >/dev/null 2>&1") return resp @staticmethod def back_snapshot(filesystem_name, snapshot_name): - os.system(f"rm -r {MAIN_REPO}{filesystem_name} > /dev/null") + Danix.rm(filesystem_name) resp1 = os.system(f"tar -xf {MAIN_REPO}.snapshots/{snapshot_name}/{filesystem_name}.tar.gz -C {MAIN_REPO} >/dev/null 2>&1") - resp2 = os.system(f"mv {MAIN_REPO}/opt/danix/{filesystem_name} {MAIN_REPO}") + resp2 = os.system(f"mv {MAIN_REPO}opt/danix/{filesystem_name} {MAIN_REPO}") resp3 = os.system(f"rm -r {MAIN_REPO}opt") return 0 if resp1+resp2+resp3 == 0 else 1 @@ -62,17 +83,20 @@ class Danix(): os.system(f"rm /tmp/{filesystem}/{settings.ROOT_FS}") os.system(f"mv /tmp/{filesystem} {MAIN_REPO}") + os.system(f"mount --bind /proc/ {MAIN_REPO}{filesystem_uuid}/danixfs/proc/") + os.system(f"mount --bind /sys/ {MAIN_REPO}{filesystem_uuid}/danixfs/sys/") + os.system(f"mount --bind /dev/ {MAIN_REPO}{filesystem_uuid}/danixfs/dev/") print("\nPlease! Wait a moment!!") print("Building container:") print(f"Installing {len(packages)} packages\n") - for package in packages: - os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add {package}") - 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") diff --git a/danix/db/models.py b/danix/db/models.py index a7d24b2..adb4a81 100644 --- a/danix/db/models.py +++ b/danix/db/models.py @@ -41,7 +41,7 @@ class Environment(models.Model): ) if check_equal_sentence(resp, 0): - get_message("🟢 Elements copyed successfuly!", True, 0) + get_message("🟢 Elements copied successfuly!", True, 0) else: get_message("🔴 Copy error!", True, 1) else: @@ -260,7 +260,12 @@ class Snapshot(models.Model): Snapshot.objects.get(snapshot_name=snapshot.snapshot_name).delete() - get_message(message=f"🟢 Snapshot removed successfully - {snapshot.snapshot_name}", is_finishprogram=False, finish_status_code=-1) + get_message( + message=f"🟢 Snapshot removed successfully - {snapshot.snapshot_name}", + is_finishprogram=False, + finish_status_code=-1 + ) + else: get_message(message="🔴 Error: Snapshot can not remove", is_finishprogram=True, finish_status_code=1) @@ -293,8 +298,7 @@ class Snapshot(models.Model): resp = Danix.back_snapshot(filesystem_name, snapshot.snapshot_name) if check_equal_sentence(resp, 0): - get_message(message="🟢 Snapshot roll back successfully!", is_finishprogram=True, finish_status_code=0) - + get_message(message="🟢 Environment roll back successfully!", is_finishprogram=True, finish_status_code=0) get_message(message="🔴 Error: Snapshot can not back", is_finishprogram=True, finish_status_code=1) get_message(message="🔴 Error: Environment was removed!", is_finishprogram=True, finish_status_code=1) diff --git a/danix/main.py b/danix/main.py index 13b3775..e9fb9d5 100755 --- a/danix/main.py +++ b/danix/main.py @@ -27,7 +27,7 @@ usages.add_argument("-sc", "--snapshotcreate", help="Create snapshot", requ usages.add_argument("-sb", "--snapshotback" , help="Back snapshot", required=False) usages.add_argument("-c", "--copy" , help="Copy files and directories", required=False) -usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby", "lua", "go", "ada"], required=False) +usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby", "lua", "go", "ada", "dotnet"], required=False) args = parser.parse_args() @@ -38,8 +38,10 @@ languanges_and_softwares = { "ruby" : Languanges.Ruby(), "lua" : Languanges.Lua(), "go" : Languanges.Go(), - "ada" : Languanges.Ada() + "ada" : Languanges.Ada(), + "dotnet" : Languanges.Dotnet() } + if check_system_configuration(): if args.option: diff --git a/danix/templates.py b/danix/templates.py index 6d1fb8b..0ad6494 100644 --- a/danix/templates.py +++ b/danix/templates.py @@ -127,7 +127,7 @@ class Languanges(): class Lua(): - packages = ["lua5.3", "lua5.2"] + packages = ["lua5.4", "lua5.3", "lua5.2"] config_commands = [] def install(self, environment_name, template): @@ -144,6 +144,19 @@ class Languanges(): Template.install(self.packages, environment_name, self.config_commands, template) + class Dotnet(): + + package = ["dotnet7-sdk", "dotnet6-sdk"] + config_commands = [ + "apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib", + "export HOME=/home/" + "export USERPROFILE=root", + ] + + def install(self, environment_name, template): + + Template.install(self.package, environment_name,self.config_commands, template) + class Go(): packages = ["go", "musl-dev go"]