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 {
|
||||
static void Main(string[] args) {
|
||||
string result = Update.copyEverthingToBackup();
|
||||
string result = Update.copyEverthingBeforeUpdateToBackupLocation();
|
||||
Console.WriteLine(result);
|
||||
|
||||
Update.startUpdate();
|
||||
string result2 = Update.copyEverthingFromBackupLocationToFinalDestination();
|
||||
Console.WriteLine(result2);
|
||||
}
|
||||
}
|
17
README.md
17
README.md
@ -1,6 +1,8 @@
|
||||
# update-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
|
||||
|
||||
- [@ProfessionalUwU](http://192.168.0.69:3000/ProfessionalUwU)
|
||||
@ -46,11 +48,20 @@ Run executable
|
||||
```bash
|
||||
./update
|
||||
```
|
||||
## Roadmap
|
||||
## Roadmap/ToDo
|
||||
|
||||
- Figure out how to do options/arguments
|
||||
- Backup important files
|
||||
- Figure out how to make a single executable
|
||||
- Backup all necessary files
|
||||
- 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
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
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() {
|
||||
Process process = new Process();
|
||||
string pacmanPackageListBeforeUpdate = getHomePath() + "/pacman-pre.txt";
|
||||
filesToCopy.Add(pacmanPackageListBeforeUpdate);
|
||||
string flatpakListBeforeUpdate = getHomePath() + "/flatpak-pre.txt";
|
||||
filesToCopy.Add(flatpakListBeforeUpdate);
|
||||
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo();
|
||||
//processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
processStartInfo.FileName = @"yay";
|
||||
processStartInfo.WorkingDirectory = getHomePath();
|
||||
//processStartInfo.Arguments = "--color";
|
||||
processStartInfo.RedirectStandardOutput = true;
|
||||
processStartInfo.RedirectStandardError = true;
|
||||
processStartInfo.UseShellExecute = false;
|
||||
if (!Directory.Exists(targetPath)) {
|
||||
Directory.CreateDirectory(targetPath);
|
||||
} else {
|
||||
foreach (string file in filesToCopy) {
|
||||
FileInfo info = new FileInfo(file);
|
||||
string destFile = Path.Combine(targetPath, info.Name);
|
||||
File.Copy(info.FullName, destFile, true);
|
||||
}
|
||||
}
|
||||
|
||||
process.StartInfo = processStartInfo;
|
||||
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);
|
||||
string copiedFiles = string.Join(", ", filesToCopy);
|
||||
|
||||
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;
|
||||
|
||||
// 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…
Reference in New Issue
Block a user