コード例 #1
0
ファイル: UpdateAntdsh.cs プロジェクト: tarik1603/Antd
        private static void UpdateAntd()
        {
            Directory.CreateDirectory(Parameter.RepoTemp);
            Directory.CreateDirectory(TmpDirectory);
            _countAntd++;
            if (_countAntd > 5)
            {
                AntdshLogger.WriteLine("antd update failed");
                return;
            }
            var currentVersion = Terminal.Terminal.Execute($"file {AntdActive}").Split(' ').Last();
            var date           = GetVersionDate(currentVersion);
            var requestUrl     = $"{PublicRepositoryUrl}/update/info/antd/{date}";
            var info           = GetResponseFromUrl <List <KeyValuePair <string, string> > >(requestUrl).Result;

            if (info.Where(_ => _.Key == "update").Select(_ => _.Value).First() == "false")
            {
                AntdshLogger.WriteLine("antd is already up to date");
            }
            AntdshLogger.WriteLine("updating antd");
            var downloadUrlInfo = info.Where(_ => _.Key == "url").Select(_ => _.Value).First();
            var downloadUrl     = $"{PublicRepositoryUrl}{downloadUrlInfo}";
            var filename        = downloadUrl.Split('/').Last();

            AntdshLogger.WriteLine($"downloading file from {downloadUrl}");

            var downloadedFile = $"{TmpDirectory}/{filename}";

            AntdshLogger.WriteLine(downloadedFile);
            if (File.Exists(downloadedFile))
            {
                File.Delete(downloadedFile);
            }
            Terminal.Terminal.Execute($"wget {downloadUrl} -O {downloadedFile}");
            AntdshLogger.WriteLine("check downloaded file");
            var shasum     = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();
            var currentSha = GetShaSum(downloadedFile);

            if (shasum != currentSha)
            {
                AntdshLogger.WriteLine($"{filename} downloaded file is not valid");
                UpdateAntd();
            }
            AntdshLogger.WriteLine($"{filename} download complete");
            var newVersion = $"{AntdDirectory}/{filename}";

            File.Copy(downloadedFile, newVersion, true);
            AntdshLogger.WriteLine("restart antd");
            File.Delete(AntdActive);
            Terminal.Terminal.Execute($"ln -s {newVersion} {AntdActive}");
            Terminal.Terminal.Execute("systemctl stop app-antd-03-launcher");
            Terminal.Terminal.Execute("systemctl stop framework-antd.mount");
            Terminal.Terminal.Execute("systemctl restart app-antd-02-mount");
            Terminal.Terminal.Execute("systemctl restart app-antd-03-launcher");
            Directory.Delete(TmpDirectory, true);
        }
コード例 #2
0
ファイル: UpdateAntdsh.cs プロジェクト: tarik1603/Antd
        private static void HelpDownloadFile(string url, string destination, string shasum)
        {
            Terminal.Terminal.Execute($"wget {url} -O {destination}");
            AntdshLogger.WriteLine("check downloaded file");
            var currentSha = GetShaSum(destination);

            if (shasum != currentSha)
            {
                AntdshLogger.WriteLine($"{destination} downloaded file is not valid");
                UpdateKernel();
            }
            AntdshLogger.WriteLine($"{destination} download complete");
        }
コード例 #3
0
ファイル: UpdateAntdsh.cs プロジェクト: tarik1603/Antd
        private static void UpdateKernel()
        {
            Directory.CreateDirectory(Parameter.RepoTemp);
            Directory.CreateDirectory(TmpDirectory);
            _countKernel++;
            if (_countKernel > 5)
            {
                AntdshLogger.WriteLine("kernel update failed");
                return;
            }
            var currentVersion = Terminal.Terminal.Execute($"file {ModulesActive}").Split(' ').Last();
            var date           = GetVersionDate(currentVersion);
            var requestUrl     = $"{PublicRepositoryUrl}update/info/kernel/{date}";
            var info           = GetResponseFromUrl <List <KeyValuePair <string, string> > >(requestUrl).Result;

            if (info.Where(_ => _.Key == "update").Select(_ => _.Value).First() == "false")
            {
                AntdshLogger.WriteLine("kernel is already up to date");
                return;
            }
            Directory.CreateDirectory(Parameter.RepoTemp);
            Directory.CreateDirectory(TmpDirectory);

            AntdshLogger.WriteLine("updating firmware");
            var firmwareDownloadUrl    = info.Where(_ => _.Key == "firmware-url").Select(_ => _.Value).First();
            var firmwareFilename       = firmwareDownloadUrl.Split('/').Last();
            var firmwareDownloadedFile = $"{TmpDirectory}/{firmwareFilename}";
            var firmwareShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(firmwareDownloadUrl, firmwareDownloadedFile, firmwareShasum);
            var firmwareNewVersion = $"{KernelDirectory}/{firmwareFilename}";

            File.Copy(firmwareDownloadedFile, firmwareNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {firmwareNewVersion} {FirmwareActive}");

            AntdshLogger.WriteLine("updating modules");
            var modulesDownloadUrl    = info.Where(_ => _.Key == "modules-url").Select(_ => _.Value).First();
            var modulesFilename       = modulesDownloadUrl.Split('/').Last();
            var modulesDownloadedFile = $"{TmpDirectory}/{modulesFilename}";
            var modulesShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(modulesDownloadUrl, modulesDownloadedFile, modulesShasum);
            var modulesNewVersion = $"{KernelDirectory}/{modulesFilename}";

            File.Copy(modulesDownloadedFile, modulesNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {modulesNewVersion} {ModulesActive}");

            AntdshLogger.WriteLine("updating sysmapFile");
            var sysmapFileDownloadUrl    = info.Where(_ => _.Key == "sysmapFile-url").Select(_ => _.Value).First();
            var sysmapFileFilename       = sysmapFileDownloadUrl.Split('/').Last();
            var sysmapFileDownloadedFile = $"{TmpDirectory}/{sysmapFileFilename}";
            var sysmapFileShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(sysmapFileDownloadUrl, sysmapFileDownloadedFile, sysmapFileShasum);
            var sysmapFileNewVersion = $"{KernelDirectory}/{sysmapFileFilename}";

            File.Copy(sysmapFileDownloadedFile, sysmapFileNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {sysmapFileNewVersion} {SystemMapActive}");

            AntdshLogger.WriteLine("updating initramfs");
            var initramfsDownloadUrl    = info.Where(_ => _.Key == "initramfs-url").Select(_ => _.Value).First();
            var initramfsFilename       = initramfsDownloadUrl.Split('/').Last();
            var initramfsDownloadedFile = $"{TmpDirectory}/{initramfsFilename}";
            var initramfsShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(initramfsDownloadUrl, initramfsDownloadedFile, initramfsShasum);
            var initramfsNewVersion = $"{KernelDirectory}/{initramfsFilename}";

            File.Copy(initramfsDownloadedFile, initramfsNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {initramfsNewVersion} {InitrdActive}");

            AntdshLogger.WriteLine("updating kernel");
            var kernelDownloadUrl    = info.Where(_ => _.Key == "kernel-url").Select(_ => _.Value).First();
            var kernelFilename       = kernelDownloadUrl.Split('/').Last();
            var kernelDownloadedFile = $"{TmpDirectory}/{kernelFilename}";
            var kernelShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(kernelDownloadUrl, kernelDownloadedFile, kernelShasum);
            var kernelNewVersion = $"{KernelDirectory}/{kernelFilename}";

            File.Copy(kernelDownloadedFile, kernelNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {kernelNewVersion} {KernelActive}");

            AntdshLogger.WriteLine("updating xen");
            var xenDownloadUrl    = info.Where(_ => _.Key == "xen-url").Select(_ => _.Value).First();
            var xenFilename       = xenDownloadUrl.Split('/').Last();
            var xenDownloadedFile = $"{TmpDirectory}/{xenFilename}";
            var xenShasum         = info.Where(_ => _.Key == "hash").Select(_ => _.Value).First();

            HelpDownloadFile(xenDownloadUrl, xenDownloadedFile, xenShasum);
            var xenNewVersion = $"{KernelDirectory}/{xenFilename}";

            File.Copy(xenDownloadedFile, xenNewVersion, true);
            Terminal.Terminal.Execute($"ln -s {xenNewVersion} {XenActive}");

            Directory.Delete(TmpDirectory, true);
        }