public void Umount(string dir) { while (true) { if (MountHelper.IsAlreadyMounted(dir) != true) { return; } _bash.Execute($"umount {dir}"); } }
// /var/cache/libvirt // /var/log/libvirt // /var/lib/libvirt public static void PrepareDirectory() { var data = Directory.EnumerateFiles(virshEtcDirectory, "*.xml", SearchOption.TopDirectoryOnly); if (data.Any()) { if (MountHelper.IsAlreadyMounted(virshEtcDirectory) == false) { Mount.AutoMountDirectory(virshEtcDirectory); } } }
public static void WorkingDirectories() { foreach (var dir in DefaultWorkingDirectories) { var mntDir = MountHelper.SetDirsPath(dir); Directory.CreateDirectory(dir); Directory.CreateDirectory(mntDir); if (MountHelper.IsAlreadyMounted(dir)) { continue; } ConsoleLogger.Log($"mount {mntDir} -> {dir}"); SetBind(mntDir, dir); } foreach (var kvp in DefaultWorkingDirectoriesWithOptions) { if (MountHelper.IsAlreadyMounted(kvp.Key) == false) { Bash.Execute($"mount {kvp.Value} {kvp.Key}", false); } } }
public static void WorkingDirectories() { if (MountHelper.IsAlreadyMounted("/mnt/cdrom/Kernel/active-firmware", "/lib64/firmware") == false) { MountSimple("/mnt/cdrom/Kernel/active-firmware", "/lib64/firmware"); } var kernelRelease = Bash.Execute("uname -r").Trim(); var linkedRelease = Bash.Execute("file /mnt/cdrom/Kernel/active-modules").Trim(); if (MountHelper.IsAlreadyMounted("/mnt/cdrom/Kernel/active-modules") == false && linkedRelease.Contains(kernelRelease)) { var moduleDir = $"/lib64/modules/{kernelRelease}/"; Directory.CreateDirectory(moduleDir); MountSimple("/mnt/cdrom/Kernel/active-modules", moduleDir); } Bash.Execute("systemctl restart systemd-modules-load.service", false); foreach (var dir in DefaultWorkingDirectories) { var mntDir = MountHelper.ConvertDirectoryTargetPathToDirs(dir); Directory.CreateDirectory(dir); Directory.CreateDirectory(mntDir); if (MountHelper.IsAlreadyMounted(dir)) { continue; } ConsoleLogger.Log($"[mount] {mntDir} -> {dir}"); MountWithBind(mntDir, dir); } foreach (var kvp in DefaultWorkingDirectoriesWithOptions) { if (MountHelper.IsAlreadyMounted(kvp.Key) == false) { MountSimple(kvp.Value, kvp.Key); } } }
public static void AllDirectories() { var list = new List <MountModel>(); var directories = Directory.EnumerateDirectories(Parameter.RepoDirs, "DIR*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var directory in directories) { var mo = new MountModel { SystemPath = MountHelper.GetDirsPath(Path.GetFileName(directory)), RepoDirsPath = directory, Context = MountContext.External, Entity = MountEntity.Directory }; list.Add(mo); } var files = Directory.EnumerateFiles(Parameter.RepoDirs, "FILE*", SearchOption.TopDirectoryOnly).ToArray(); foreach (var file in files) { var mo = new MountModel { SystemPath = MountHelper.GetFilesPath(Path.GetFileName(file)), RepoDirsPath = file, Context = MountContext.External, Entity = MountEntity.File }; list.Add(mo); } ConsoleLogger.Log("directories and files enumerated"); var directoryMounts = list.Where(m => m.Entity == MountEntity.Directory).ToList(); foreach (var directoryMount in directoryMounts) { try { var dir = directoryMount.SystemPath.Replace("\\", ""); var mntDir = directoryMount.RepoDirsPath; if (MountHelper.IsAlreadyMounted(dir) == false) { Directory.CreateDirectory(dir); Directory.CreateDirectory(mntDir); SetBind(mntDir, dir); ConsoleLogger.Log($"mount {mntDir} -> {dir}"); } } catch (Exception ex) { ConsoleLogger.Warn(ex.Message); } } ConsoleLogger.Log("directories mounted"); var fileMounts = list.Where(m => m.Entity == MountEntity.File).ToList(); foreach (var fileMount in fileMounts) { var file = fileMount.SystemPath.Replace("\\", ""); var mntFile = fileMount.RepoDirsPath; if (System.IO.File.Exists(mntFile)) { var path = Path.GetDirectoryName(file); var mntPath = Path.GetDirectoryName(mntFile); if (MountHelper.IsAlreadyMounted(file) == false) { Bash.Execute($"mkdir -p {path}", false); Bash.Execute($"mkdir -p {mntPath}", false); if (!System.IO.File.Exists(file)) { Bash.Execute($"cp {mntFile} {file}", false); } SetBind(mntFile, file); ConsoleLogger.Log($"mount {mntFile} -> {file}"); } } } ConsoleLogger.Log("files mounted"); }
public void Setup(string appName) { ConsoleLogger.Log("========================================="); ConsoleLogger.Log($"Installing {appName}"); var apps = Detect(); var appInfo = apps.FirstOrDefault(_ => _.Name == appName); if (appInfo != null) { ConsoleLogger.Log($"{appName} info found"); var name = appInfo.Values.FirstOrDefault(_ => _.Key == "name").Value; var repoPath = appInfo.Repository; var timestamp = DateTime.Now.ToString("yyyyMMdd"); var squashName = $"DIR_framework_{name.ToLower().Replace("/", "-")}-aosApps-{timestamp}-std-x86_64.squashfs.xz"; ConsoleLogger.Log($"name => {name}"); ConsoleLogger.Log($"repoPath => {repoPath}"); ConsoleLogger.Log($"timestamp => {timestamp}"); ConsoleLogger.Log($"squashName => {squashName}"); if (File.Exists($"{repoPath}/{squashName}")) { File.Delete($"{repoPath}/{squashName}"); } ConsoleLogger.Log($">> mksquashfs {repoPath}/{name} {repoPath}/{squashName} -comp xz -Xbcj x86 -Xdict-size 75%"); _bash.Execute($"mksquashfs {repoPath}/{name} {repoPath}/{squashName} -comp xz -Xbcj x86 -Xdict-size 75%", false); ConsoleLogger.Log("compressed fs for application created"); var activeVersionPath = $"{repoPath}/active-version"; ConsoleLogger.Log($"activeVersionPath => {activeVersionPath}"); _bash.Execute($"ln -s {squashName} {activeVersionPath}", false); ConsoleLogger.Log("link created"); var frameworkDir = $"/framework/{name.ToLower().Replace("/", "-")}"; ConsoleLogger.Log($"frameworkDir => {frameworkDir}"); Directory.CreateDirectory("/framework"); Directory.CreateDirectory(frameworkDir); ConsoleLogger.Log("framework directories created"); if (MountHelper.IsAlreadyMounted(frameworkDir) == false) { ConsoleLogger.Log($">> mount {activeVersionPath} {frameworkDir}"); _bash.Execute($"mount {activeVersionPath} {frameworkDir}", false); ConsoleLogger.Log("application fs mounted"); } var prepareUnitName = _appsUnits.CreatePrepareUnit(name, frameworkDir); var mountUnitName = _appsUnits.CreateMountUnit(name, activeVersionPath, frameworkDir); ConsoleLogger.Log($"prepareUnitName => {prepareUnitName}"); ConsoleLogger.Log($"mountUnitName => {mountUnitName}"); ConsoleLogger.Log("units created"); var launcherUnitName = new List <string>(); var exes = appInfo.Values.Where(_ => _.Key == "app_exe").Select(_ => _.Value).ToList(); var frameworkDirContent = Directory.EnumerateFiles(frameworkDir, "*", SearchOption.AllDirectories).ToList(); foreach (var exe in exes) { ConsoleLogger.Log($"exe => {exe}"); var exePath = frameworkDirContent.FirstOrDefault(_ => _.EndsWith(exe)); ConsoleLogger.Log($"exePath? => {exePath}"); if (File.Exists(exePath)) { var lun = _appsUnits.CreateLauncherUnit(name, exe, exePath); ConsoleLogger.Log($"launcherUnitName => {lun}"); launcherUnitName.Add(lun); } } ConsoleLogger.Log("launcher units created"); var mounts = appInfo.Values.Where(_ => _.Key == "app_path").Select(_ => _.Value).ToList(); foreach (var mount in mounts) { ConsoleLogger.Log($"workingDir => {mount}"); _mount.Dir(mount); } ConsoleLogger.Log("working directories created and mounted"); var appsConfiguration = new AppsConfiguration(); var tryGet = appsConfiguration.Get().Apps.FirstOrDefault(_ => _.Name == name); if (tryGet != null) { return; } var model = new ApplicationModel { Name = name, RepositoryName = repoPath, Exes = exes, WorkingDirectories = mounts, UnitPrepare = prepareUnitName, UnitMount = mountUnitName, UnitLauncher = launcherUnitName }; appsConfiguration.AddApp(model); } }