extremely basic prototype
This commit is contained in:
parent
688da54ceb
commit
66418b57c0
@ -1,57 +1,128 @@
|
|||||||
public class Program {
|
public class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
var exitCommand = "nothing";
|
||||||
|
string backupLocation = "/home/rene/";
|
||||||
|
var pacmanWrapper = "yay";
|
||||||
|
var backupAmount = 2;
|
||||||
|
|
||||||
string beforeUpdate() {
|
if (args.Length == 0) {
|
||||||
|
beforeUpdate();
|
||||||
Update.copyEverthingBeforeUpdateToBackupLocation();
|
Console.WriteLine(pacmanWrapper);
|
||||||
Update.zipAllContentInBackupLocation("pre-backup.zip");
|
afterUpdate();
|
||||||
Update.zipPacmanDatabase();
|
return;
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
return "pre-backup complete";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string postUpdate() {
|
string arg = args[0].TrimStart('-');;
|
||||||
|
if (args[0].StartsWith("--")) {
|
||||||
Update.copyEverthingAfterUpdateToBackupLocation();
|
switch (arg) {
|
||||||
Update.zipAllContentInBackupLocation("post-backup.zip");
|
case "help":
|
||||||
Update.copyEverthingFromBackupLocationToFinalDestination(args[0]);
|
Console.WriteLine(help());
|
||||||
|
break;
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
case "preview":
|
||||||
return "post-backup complete";
|
// need to execute 'yay -Sy && yay -Qu'
|
||||||
}
|
break;
|
||||||
|
case "version":
|
||||||
string testPacmanDatabase() {
|
Console.WriteLine("version");
|
||||||
|
break;
|
||||||
Update.zipPacmanDatabase();
|
case "backup":
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
||||||
return "Test complete";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?redirectedfrom=MSDN&view=net-7.0
|
|
||||||
|
|
||||||
try {
|
|
||||||
switch(args[1]) {
|
|
||||||
case "pre-backup":
|
|
||||||
beforeUpdate();
|
beforeUpdate();
|
||||||
Console.ResetColor();
|
|
||||||
break;
|
|
||||||
case "post-backup":
|
|
||||||
postUpdate();
|
|
||||||
Console.ResetColor();
|
|
||||||
break;
|
|
||||||
case "testPacmanDatabase":
|
|
||||||
testPacmanDatabase();
|
|
||||||
Console.ResetColor();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Wait! How did you do that?");
|
return;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
return;
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
}
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
|
beforeUpdate();
|
||||||
|
|
||||||
|
foreach (var option in arg) {
|
||||||
|
switch (option) {
|
||||||
|
case 'f':
|
||||||
|
// flatpak update -u --noninteractive && flatpak list > "$TMP"/after-backup_"$DATE"/flatpak-after.txt
|
||||||
|
Console.WriteLine("flatpak update");
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
// "$PACMAN_WRAPPER" && pacman -Qq > "$TMP"/after-backup_"$DATE"/pacman-after.txt
|
||||||
|
Console.WriteLine(pacmanWrapper);
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
// 'p' && 'f'
|
||||||
|
Console.WriteLine("flatpak update && " + pacmanWrapper);
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
if (args[0].TrimStart('-') == "g") {
|
||||||
|
Console.WriteLine(pacmanWrapper);
|
||||||
|
}
|
||||||
|
exitCommand = "systemctl -i poweroff";
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
if (args[0].TrimStart('-') == "r") {
|
||||||
|
Console.WriteLine(pacmanWrapper);
|
||||||
|
}
|
||||||
|
exitCommand = "systemctl -i reboot";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
help();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
afterUpdate();
|
||||||
|
|
||||||
|
void readConfig() {
|
||||||
|
backupLocation = "/mnt/Hephaistos/update/";
|
||||||
|
pacmanWrapper = "yay";
|
||||||
|
backupAmount = 2;
|
||||||
|
|
||||||
|
if (!Directory.Exists(backupLocation)) {
|
||||||
|
Console.WriteLine("update-csharp: Backup location does not exist or cannot be reached");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//find the amount of backups in the backupLocation and delete the oldest
|
||||||
|
void deleteOldestBackup() {
|
||||||
|
Console.WriteLine(backupAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void beforeUpdate() {
|
||||||
|
readConfig();
|
||||||
|
deleteOldestBackup();
|
||||||
|
|
||||||
|
Update.backup("before");
|
||||||
|
Update.zipPacmanDatabase();
|
||||||
|
Update.copyToBackupLocation(backupLocation);
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("pre-backup complete");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void afterUpdate() {
|
||||||
|
Update.backup("after");
|
||||||
|
Update.copyToBackupLocation(backupLocation);
|
||||||
|
Directory.Delete("/tmp/update", true);
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("after-backup complete");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.WriteLine(exitCommand); // execute exitCommand
|
||||||
|
}
|
||||||
|
|
||||||
|
string help() {
|
||||||
|
string helpMessage = "Usage: update [OPTION]\n";
|
||||||
|
helpMessage += "\noptions:\n";
|
||||||
|
helpMessage += "no flag same as -p\n";
|
||||||
|
helpMessage += "-f updates using flatpak update only\n";
|
||||||
|
helpMessage += "-p updates using a pacman-wrapper only\n";
|
||||||
|
helpMessage += "-a updates using flatpak update and a pacman-wrapper\n";
|
||||||
|
helpMessage += "-g shutdowns the computer afterwards\n";
|
||||||
|
helpMessage += "-r reboots the computer afterwards\n";
|
||||||
|
helpMessage += "--help displays this message\n";
|
||||||
|
helpMessage += "--preview shows a preview of which pkg's can be updated\n";
|
||||||
|
helpMessage += "--version prints out the version number\n";
|
||||||
|
helpMessage += "--backup just does the pre-backup without updating";
|
||||||
|
return helpMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,12 +13,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Update-csharp.Tests\Update-csharp.Tests.csproj" />
|
||||||
<Reference Include="System.IO.Compression" />
|
<Reference Include="System.IO.Compression" />
|
||||||
<Reference Include="System.IO.Compression.ZipFile" />
|
<Reference Include="System.IO.Compression.ZipFile" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\Update-csharp.Tests\Update-csharp.Tests.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -2,236 +2,84 @@ using System.Diagnostics;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
|
||||||
public class Update {
|
public class Update {
|
||||||
public static string getHomePath() {
|
static string tmpDirectory = "/tmp/update/";
|
||||||
string homePath = string.Empty;
|
public static void backup(string mode) {
|
||||||
|
string backupDir;
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Unix) {
|
string pkgList;
|
||||||
homePath = Environment.GetEnvironmentVariable("HOME");
|
string flatpakList;
|
||||||
return homePath;
|
|
||||||
} else {
|
|
||||||
throw new ApplicationException("This script doesn't support your operating system.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static string copyEverthingBeforeUpdateToBackupLocation() {
|
|
||||||
string targetPath = "/tmp/backup/uncompressed/";
|
|
||||||
|
|
||||||
if (File.Exists(targetPath + "pacman-after.txt") && File.Exists(targetPath + "flatpak-after.txt")) {
|
|
||||||
File.Delete(targetPath + "pacman-after.txt");
|
|
||||||
File.Delete(targetPath + "flatpak-after.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] systemFilesToCopy = {"/etc/fstab", "/etc/makepkg.conf"};
|
|
||||||
List<string> filesToCopy = new List<string>(systemFilesToCopy);
|
|
||||||
|
|
||||||
string pacmanPackageListBeforeUpdate = targetPath + "pacman-pre.txt";
|
|
||||||
filesToCopy.Add(pacmanPackageListBeforeUpdate);
|
|
||||||
string flatpakListBeforeUpdate = targetPath+ "flatpak-pre.txt";
|
|
||||||
filesToCopy.Add(flatpakListBeforeUpdate);
|
|
||||||
|
|
||||||
if (!Directory.Exists(targetPath)) {
|
|
||||||
Directory.CreateDirectory(targetPath);
|
|
||||||
copyEverthingBeforeUpdateToBackupLocation();
|
|
||||||
} else {
|
|
||||||
foreach (string file in filesToCopy) {
|
|
||||||
FileInfo info = new FileInfo(file);
|
|
||||||
string destFile = Path.Combine(targetPath, info.Name);
|
|
||||||
File.Copy(info.FullName, destFile, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string copiedFiles = string.Join(", ", filesToCopy);
|
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
return $"Copied {copiedFiles} to {targetPath}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string copyEverthingAfterUpdateToBackupLocation() {
|
|
||||||
string targetPath = "/tmp/backup/uncompressed/"; // Use /tmp to zip and then move into /backup/compressed/
|
|
||||||
|
|
||||||
if (File.Exists(targetPath + "pacman-pre.txt") && File.Exists(targetPath + "flatpak-pre.txt")) {
|
|
||||||
File.Delete(targetPath + "pacman-pre.txt");
|
|
||||||
File.Delete(targetPath + "flatpak-pre.txt");
|
|
||||||
File.Delete(targetPath + "fstab");
|
|
||||||
File.Delete(targetPath + "makepkg.conf");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<string> filesToCopy = new List<string>();
|
List<string> filesToCopy = new List<string>();
|
||||||
string pacmanPackageListBeforeUpdate = targetPath + "pacman-after.txt";
|
string zipName;
|
||||||
filesToCopy.Add(pacmanPackageListBeforeUpdate);
|
|
||||||
string flatpakListBeforeUpdate = targetPath + "flatpak-after.txt";
|
|
||||||
filesToCopy.Add(flatpakListBeforeUpdate);
|
|
||||||
|
|
||||||
if (!Directory.Exists(targetPath)) {
|
switch (mode) {
|
||||||
Directory.CreateDirectory(targetPath);
|
case "before":
|
||||||
copyEverthingAfterUpdateToBackupLocation();
|
backupDir = tmpDirectory + "beforeBackup";
|
||||||
} else {
|
pkgList = backupDir + "pacman-pre.txt";
|
||||||
foreach (string file in filesToCopy) {
|
flatpakList = backupDir + "flatpak-pre.txt";
|
||||||
FileInfo info = new FileInfo(file);
|
filesToCopy.Add("/etc/fstab");
|
||||||
string destFile = Path.Combine(targetPath, info.Name);
|
filesToCopy.Add("/etc/makepkg.conf");
|
||||||
File.Copy(info.FullName, destFile, true);
|
zipName = tmpDirectory + "beforeBackup.zip";
|
||||||
}
|
break;
|
||||||
|
case "after":
|
||||||
|
backupDir = tmpDirectory + "afterBackup";
|
||||||
|
pkgList = backupDir + "pacman-after.txt";
|
||||||
|
flatpakList = backupDir + "flatpak-after.txt";
|
||||||
|
zipName = tmpDirectory + "afterBackup.zip";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("No valid mode was given. Valid modes are before and after");
|
||||||
}
|
}
|
||||||
|
|
||||||
string copiedFiles = string.Join(", ", filesToCopy);
|
if (Directory.Exists(tmpDirectory)) {
|
||||||
|
Directory.Delete(tmpDirectory, true);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory(backupDir);
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
foreach (var file in filesToCopy) {
|
||||||
return $"Copied {copiedFiles} to {targetPath}";
|
FileInfo info = new FileInfo(file);
|
||||||
|
string destFile = Path.Combine(backupDir, info.Name);
|
||||||
|
File.Copy(info.FullName, destFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipFile.CreateFromDirectory(backupDir, zipName);
|
||||||
|
Directory.Delete(backupDir, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static void copyToBackupLocation(string backupLocation) {
|
||||||
/// Method <c>copyEverthingFromBackupLocationToFinalDestination</c> copies everything to second Backup Location which should be a external drive or a network share. Offsite/Second Backup.
|
foreach (var zip in Directory.GetFiles(tmpDirectory)) {
|
||||||
/// </summary>
|
FileInfo info = new FileInfo(zip);
|
||||||
public static string copyEverthingFromBackupLocationToFinalDestination(string finalBackupLocation) {
|
string destFile = Path.Combine(backupLocation, info.Name);
|
||||||
string targetPath = finalBackupLocation;
|
File.Copy(info.FullName, destFile, true);
|
||||||
|
|
||||||
if (!Directory.Exists(targetPath)) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
return $"Backup location does not exist! Please specify one in the config.";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetPath is not null) {
|
|
||||||
string sourcePath = getHomePath() + "/backup/compressed/";
|
|
||||||
string[] intermediateBackupLocation = Directory.GetFiles(sourcePath);
|
|
||||||
|
|
||||||
if (!Directory.Exists(targetPath)) {
|
|
||||||
throw new DirectoryNotFoundException("Target directory not found");
|
|
||||||
} else {
|
|
||||||
foreach (string file in intermediateBackupLocation) {
|
|
||||||
FileInfo info = new FileInfo(file);
|
|
||||||
string destFile = Path.Combine(targetPath, info.Name);
|
|
||||||
File.Copy(info.FullName, destFile, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
return $"Copied everything successfully to {targetPath}";
|
|
||||||
} else {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
return "You have not configured a backup location!";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool zipAllContentInBackupLocation(string finalZipName) {
|
public static void zipPacmanDatabase() {
|
||||||
string targetPath = getHomePath() + "/backup/compressed/";
|
string pacmanDatabaseLocation = "/var/lib/pacman/local";
|
||||||
if (!Directory.Exists(targetPath)) {
|
string zipName = tmpDirectory + "pacmanDatabase.zip";
|
||||||
Directory.CreateDirectory(targetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
string sourcePath = "/tmp/backup/uncompressed/";
|
|
||||||
string targetZip = getHomePath() + "/backup/compressed/" + finalZipName;
|
|
||||||
|
|
||||||
if (!Directory.Exists("/tmp/backup/")) {
|
if(dbLockExists()) {
|
||||||
Directory.CreateDirectory("/tmp/backup/");
|
throw new ApplicationException("db.lck exists. Please try again later.");
|
||||||
}
|
}
|
||||||
string newFinalZip = "/tmp/backup/" + finalZipName;
|
|
||||||
File.Delete(newFinalZip); // Delete residual zip's in tmp
|
|
||||||
ZipFile.CreateFromDirectory(sourcePath, newFinalZip);
|
|
||||||
|
|
||||||
if (File.Exists(targetZip)) {
|
|
||||||
if (!checkForIdenticalFile(targetZip, newFinalZip)) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.WriteLine($"{finalZipName} is outdated");
|
|
||||||
File.Delete(targetZip);
|
|
||||||
if (File.Exists(newFinalZip)) {
|
|
||||||
File.Delete(newFinalZip);
|
|
||||||
zipAllContentInBackupLocation(finalZipName);
|
|
||||||
} else {
|
|
||||||
File.Move(newFinalZip, targetZip);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Console.WriteLine($"{finalZipName} is up to date");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ZipFile.CreateFromDirectory(sourcePath, targetZip);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File.Exists(targetZip)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool zipPacmanDatabase() {
|
|
||||||
string pacmanDatabaseLocation = "/var/lib/pacman/local/";
|
|
||||||
string oldPacmanDatabaseZip = getHomePath() + "/backup/compressed/pacman-database.zip";
|
|
||||||
string newPacmanDatabaseZip = "/tmp/backup/compressed/pacman-database.zip";
|
|
||||||
|
|
||||||
if (!Directory.Exists("/tmp/backup/compressed/")) {
|
|
||||||
Directory.CreateDirectory("/tmp/backup/compressed/");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(checkForLckFile("/var/lib/pacman/") == false) { // Only creates the zip if the db.lck doesn't exist
|
lockDatabase();
|
||||||
|
|
||||||
makeDatabaseLock();
|
ZipFile.CreateFromDirectory(pacmanDatabaseLocation, zipName);
|
||||||
|
|
||||||
if (File.Exists(newPacmanDatabaseZip)) { // Delete residual pacman database in tmp
|
|
||||||
File.Delete(newPacmanDatabaseZip);
|
|
||||||
deleteDatabaseLock(); // Delete previous created database lock
|
|
||||||
} else {
|
|
||||||
ZipFile.CreateFromDirectory(pacmanDatabaseLocation, newPacmanDatabaseZip); // If no zip exists create one
|
|
||||||
}
|
|
||||||
|
|
||||||
if (File.Exists(oldPacmanDatabaseZip)) {
|
|
||||||
if (!checkForIdenticalFile(oldPacmanDatabaseZip, newPacmanDatabaseZip)) {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
|
||||||
Console.WriteLine("Pacman Database is outdated");
|
|
||||||
File.Delete(oldPacmanDatabaseZip);
|
|
||||||
File.Move(newPacmanDatabaseZip, oldPacmanDatabaseZip);
|
|
||||||
} else {
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Console.WriteLine("Pacman Database is up to date");
|
|
||||||
File.Delete(newPacmanDatabaseZip);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!File.Exists(newPacmanDatabaseZip)) {
|
|
||||||
ZipFile.CreateFromDirectory(pacmanDatabaseLocation, newPacmanDatabaseZip); // Create the zip in tmp
|
|
||||||
}
|
|
||||||
File.Move(newPacmanDatabaseZip, oldPacmanDatabaseZip);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new ApplicationException("db.lck exists. Please try again later.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//deleteDatabaseLock(); // Bad practice. Only for debug purpose!
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(e.Message);
|
Console.WriteLine(e.Message);
|
||||||
|
} finally {
|
||||||
|
unlockDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists(oldPacmanDatabaseZip)) {
|
|
||||||
deleteDatabaseLock();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool checkForIdenticalFile(string existingFilePath, string newFilePath) {
|
private static bool dbLockExists() {
|
||||||
byte[] existingFile = File.ReadAllBytes(existingFilePath);
|
if (File.Exists("/var/lib/pacman/db.lck")) {
|
||||||
byte[] newFile = File.ReadAllBytes(newFilePath);
|
|
||||||
|
|
||||||
if (existingFile.Length == newFile.Length) {
|
|
||||||
for (int i=0; i < existingFile.Length; i++) {
|
|
||||||
if (existingFile[i] != newFile[i]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool checkForLckFile(string folderToCheck) {
|
private static void lockDatabase() {
|
||||||
if (Directory.GetFiles(folderToCheck, "*.lck").Length == 1) {
|
|
||||||
return true; // lck file exists
|
|
||||||
} else {
|
|
||||||
return false; // lck file doesn't exists
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void makeDatabaseLock() {
|
|
||||||
var psi = new ProcessStartInfo
|
var psi = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "/bin/bash",
|
FileName = "/bin/bash",
|
||||||
@ -250,19 +98,15 @@ public class Update {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteDatabaseLock() {
|
private static void unlockDatabase() {
|
||||||
var psi = new ProcessStartInfo
|
var psi = new ProcessStartInfo {
|
||||||
{
|
FileName = "/bin/bash",
|
||||||
FileName = "/bin/bash",
|
UseShellExecute = false,
|
||||||
UseShellExecute = false,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardOutput = true,
|
Arguments = string.Format("-c \"cd /var/lib/pacman/ && sudo rm -f db.lck\"")
|
||||||
Arguments = string.Format("-c \"cd /var/lib/pacman/ && sudo rm -f db.lck\"")
|
};
|
||||||
};
|
using (var p = Process.Start(psi)) {
|
||||||
|
if (p != null) {
|
||||||
using (var p = Process.Start(psi))
|
|
||||||
{
|
|
||||||
if (p != null)
|
|
||||||
{
|
|
||||||
var strOutput = p.StandardOutput.ReadToEnd();
|
var strOutput = p.StandardOutput.ReadToEnd();
|
||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user