Removed update functionality && Rewrote/simplified file handling && Expanded README
With this commit I will change the scope of this project. The new goal for this project is to rewrite the file handling of the original update script in C#. Because of this a lot changed with this commit. I removed all update functionality from the code. I completely rewrote the file handling with help of the FileInfo class. I also added a couple of things to the Roadmap. While doing that I also added sources that I frequently use.
This commit is contained in:
parent
ed5286435a
commit
21b61759d6
@ -1,8 +1,9 @@
|
|||||||
public class Program {
|
public class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
string result = Update.copyEverthingToBackup();
|
string result = Update.copyEverthingBeforeUpdateToBackupLocation();
|
||||||
Console.WriteLine(result);
|
Console.WriteLine(result);
|
||||||
|
|
||||||
Update.startUpdate();
|
string result2 = Update.copyEverthingFromBackupLocationToFinalDestination();
|
||||||
|
Console.WriteLine(result2);
|
||||||
}
|
}
|
||||||
}
|
}
|
17
README.md
17
README.md
@ -1,6 +1,8 @@
|
|||||||
# update-c#
|
# update-c#
|
||||||
|
|
||||||
A rewrite of the legendary update script in C#
|
A rewrite of the legendary update script in C#
|
||||||
|
|
||||||
|
This time with file handling entirely in C# while keeping all scripting parts in bash.
|
||||||
## Authors
|
## Authors
|
||||||
|
|
||||||
- [@ProfessionalUwU](http://192.168.0.69:3000/ProfessionalUwU)
|
- [@ProfessionalUwU](http://192.168.0.69:3000/ProfessionalUwU)
|
||||||
@ -46,11 +48,20 @@ Run executable
|
|||||||
```bash
|
```bash
|
||||||
./update
|
./update
|
||||||
```
|
```
|
||||||
## Roadmap
|
## Roadmap/ToDo
|
||||||
|
|
||||||
- Figure out how to do options/arguments
|
- Figure out how to do options/arguments
|
||||||
- Backup important files
|
- Backup all necessary files
|
||||||
- Figure out how to make a single executable
|
- Shrink size of the executable
|
||||||
|
- Potentially speed up file handling
|
||||||
|
- Color output according to state (success = green, failure = red, info = yellow)
|
||||||
|
- Backup pacman database
|
||||||
|
- Compress all files to single archive
|
||||||
|
|
||||||
|
## Sites I used to help make this project
|
||||||
|
- [dotnetperls](https://dotnetperls.com)
|
||||||
|
- [stackoverflow](https://stackoverflow.com/questions/tagged/c%23)
|
||||||
|
- [c-sharpcorner](https://www.c-sharpcorner.com)
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions are always welcome!
|
Contributions are always welcome!
|
||||||
|
79
Update.cs
79
Update.cs
@ -11,33 +11,53 @@ public class Update {
|
|||||||
throw new ApplicationException("This script doesn't support your operating system.");
|
throw new ApplicationException("This script doesn't support your operating system.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static string copyEverthingBeforeUpdateToBackupLocation() {
|
||||||
|
string targetPath = getHomePath() + "/backup/";
|
||||||
|
|
||||||
|
string[] systemFilesToCopy = {"/etc/fstab", "/etc/makepkg.conf"};
|
||||||
|
List<string> filesToCopy = new List<string>(systemFilesToCopy);
|
||||||
|
|
||||||
public static void startUpdate() {
|
string pacmanPackageListBeforeUpdate = getHomePath() + "/pacman-pre.txt";
|
||||||
Process process = new Process();
|
filesToCopy.Add(pacmanPackageListBeforeUpdate);
|
||||||
|
string flatpakListBeforeUpdate = getHomePath() + "/flatpak-pre.txt";
|
||||||
|
filesToCopy.Add(flatpakListBeforeUpdate);
|
||||||
|
|
||||||
ProcessStartInfo processStartInfo = new ProcessStartInfo();
|
if (!Directory.Exists(targetPath)) {
|
||||||
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
Directory.CreateDirectory(targetPath);
|
||||||
processStartInfo.FileName = @"yay";
|
} else {
|
||||||
processStartInfo.WorkingDirectory = getHomePath();
|
foreach (string file in filesToCopy) {
|
||||||
//processStartInfo.Arguments = "--color";
|
FileInfo info = new FileInfo(file);
|
||||||
processStartInfo.RedirectStandardOutput = true;
|
string destFile = Path.Combine(targetPath, info.Name);
|
||||||
processStartInfo.RedirectStandardError = true;
|
File.Copy(info.FullName, destFile, true);
|
||||||
processStartInfo.UseShellExecute = false;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process.StartInfo = processStartInfo;
|
string copiedFiles = string.Join(", ", filesToCopy);
|
||||||
process.Start();
|
|
||||||
|
|
||||||
// Read the output of the "yay" command
|
|
||||||
string output = process.StandardOutput.ReadLine();
|
|
||||||
string error = process.StandardError.ReadToEnd();
|
|
||||||
process.WaitForExit();
|
|
||||||
|
|
||||||
Console.WriteLine(output);
|
|
||||||
Console.WriteLine(error);
|
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
return $"Copied {copiedFiles} to {targetPath}";
|
||||||
}
|
}
|
||||||
|
|
||||||
// using System;
|
public static string copyEverthingFromBackupLocationToFinalDestination() {
|
||||||
|
string targetPath = "/artemis/test/";
|
||||||
|
string sourcePath = getHomePath() + "/backup/";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $"Copied everything successfully to {targetPath}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commented code below was written by ChatGPT
|
||||||
|
|
||||||
|
// using System;
|
||||||
// using System.Diagnostics;
|
// using System.Diagnostics;
|
||||||
|
|
||||||
// namespace UpdateLinux
|
// namespace UpdateLinux
|
||||||
@ -73,21 +93,4 @@ public class Update {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static string copyEverthingToBackup() {
|
|
||||||
string fileName = "fstab";
|
|
||||||
string sourcePath = @"/etc/";
|
|
||||||
string targetPath = getHomePath();
|
|
||||||
|
|
||||||
string backupPath = targetPath + "/backup/";
|
|
||||||
|
|
||||||
string sourceFile = Path.Combine(sourcePath, fileName);
|
|
||||||
string destFile = Path.Combine(backupPath, fileName);
|
|
||||||
|
|
||||||
Directory.CreateDirectory(backupPath);
|
|
||||||
|
|
||||||
File.Copy(sourceFile, destFile, true);
|
|
||||||
|
|
||||||
return $"Copied {fileName} to {backupPath}";
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user