6 Commits

Author SHA1 Message Date
Cametendo
0edbc24003 Added file and device verification 2026-04-21 20:54:54 +02:00
Cametendo
ecb1f7be3e Merge branch 'dev' 2026-04-04 19:54:57 +02:00
Cametendo
66e4247199 Added dd 2026-04-04 19:54:18 +02:00
Cametendo
1661e3e060 Merge branch 'working-flasher' into dev 2026-04-03 15:14:23 +02:00
Cametendo
c086bcc2e6 Made flasher show user configuration 2026-04-03 15:12:45 +02:00
Cametendo
cd6100548c Update README.md 2026-02-09 07:38:06 +01:00
8 changed files with 127 additions and 29 deletions

View File

@@ -1,12 +1,14 @@
import java.util.Scanner;
public class BlockSize {
public static void blockSize(Scanner UserInput) {
public static String blockSizeString = "";
static String blockSize(Scanner UserInput) {
System.out.println("Choose a block size (Default: 4M)");
System.out.println("512KB (1), 1M (2), 2M (3), 4M (4), 8M (5), 16M (6)");
String blockSizeInput = UserInput.nextLine();
String blockSizeString;
switch (blockSizeInput) {
case "1":
blockSizeString = "512KB";
@@ -30,5 +32,7 @@ public class BlockSize {
blockSizeString = "4M";
break;
}
System.out.println("Using blocksize of: " + blockSizeString);
return blockSizeString;
}
}

26
Dd.java Normal file
View File

@@ -0,0 +1,26 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Dd {
public static void dd() {
try {
ProcessBuilder pb = new ProcessBuilder("sudo", "dd", "if=" + FilePathAdd.ImagePath, "of=" + StorageDeviceLister.fullPath, "bs=" + BlockSize.blockSizeString, "status=progress", "oflag=" + OflagHandler.oflagHandleString);
pb.redirectErrorStream(true);
Process process = pb.start();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream())
);
int character;
while ((character = reader.read()) != -1) {
char c = (char) character;
System.out.print(c);
System.out.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,9 +1,32 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Scanner;
public class FilePathAdd {
public static void filePath(Scanner UserInput) {
System.out.println("Please enter the FULL Path of your ISO / Image. ()");
String ImagePath = UserInput.nextLine();
public static String ImagePath = "";
protected static String filePath(Scanner UserInput) {
fileQuestion();
while (true) {
ImagePath = UserInput.nextLine();
if (ImagePath.isBlank()) {
System.out.println("Oops.. You didn't specify a file, did you missclick?");
continue;
}
Path path = Path.of(ImagePath);
try {
Files.readAttributes(path, "basic:size");
System.out.println("Using File: " + ImagePath);
return ImagePath;
} catch (IOException e) {
System.out.println("Failed to access file, invalid path or no access to file! Please try again.");
}
}
}
protected static void fileQuestion() {
System.out.println("Please enter the FULL Path of your ISO / Image. (No tab-complete)");
}
}

View File

@@ -1,11 +1,23 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Flasher {
publicstatic voic flasher(Scanner UserInput) {
System.out.println("The programm wil use the following configuration, do you want to flash with this? (y/n)");
System.out.println(" - To be flashed device: " + device);
public static void flasher(Scanner UserInput) {
String input = "";
System.out.println("The programm wil use the following configuration, do you want to flash with this? (Y/n)");
System.out.println(" - To be flashed device: " + StorageDeviceLister.fullPath);
System.out.println(" - To be used path: " + FilePathAdd.ImagePath);
System.out.println(" - To bed used blocksize: " + BlockSize.blockSizeString);
System.out.println(" - To be used oflag: " + OflagHandler.oflagHandleString);
input = UserInput.nextLine();
if (YesNo.check(input)) {
System.out.println("Starting to flash...");
} else {
System.out.println("Canceling...");
System.exit(0);
}
Dd.dd();
System.out.println("Flash completed.");
}
}

View File

@@ -13,11 +13,11 @@ public class Main {
System.out.println("Canceling...");
System.exit(0);
}
StorageDeviceLister.deviceList(UserInput);
StorageDeviceLister.deviceCheck(UserInput);
FilePathAdd.filePath(UserInput);
BlockSize.blockSize(UserInput);
OflagHandler.handleOflag(UserInput);
Flasher.flasher(UserInput);
}

View File

@@ -1,12 +1,14 @@
import java.util.Scanner;
public class OflagHandler {
public static void handleOflag(Scanner UserInput) {
System.out.println("Okay, next up please define your oflag. If you have the block-size default, you can choose default here aswell");
System.out.println("Available flags: direct (default), dsync, sync, nocache");
public static String oflagHandleString = "";
static String handleOflag(Scanner UserInput) {
System.out.println("Okay, next up please define your oflag (Default: direct)");
System.out.println("Available flags: direct (1), dsync (2), sync (3), nocache (4)");
String oflagHandleInput = UserInput.nextLine();
String oflagHandleString;
switch (oflagHandleInput) {
case "1":
oflagHandleString = "direct";
@@ -24,5 +26,7 @@ public class OflagHandler {
oflagHandleString = "direct";
break;
}
System.out.println("Using oflag: " + oflagHandleString);
return oflagHandleString;
}
}

View File

@@ -21,7 +21,7 @@ Java program using `dd` to make flashing iso and image files easier on the termi
3. You will be prompted to choose a byte size (default: 4M)
4. You will be prompted to enter your oflag (default: direct)
5. You will be asked if you are absolutely sure that you want to continue (flashing will wipe all data)
- Alternative: using `cflash [device] [iso-path] [block-size] [oflag]` will skip the first question and instantly ask you, if you're absolutely sure you want to continue.
- Alternative: using `cflash [device] [iso-path] [block-size] [oflag]` will skip the questions and instantly ask you, if you're absolutely sure you want to continue.
- Once confirmed, the flash will start and a small progress bar will appear showing the flashing progress.
- After completion, the program will detect the OS from the iso and wish you a great time with your new OS. (Example: "Done! Have fun with your new Linux installation!)
- **IMPORTANT**: Since dd needs sudo rights, ensure you have root priviliges.

View File

@@ -1,27 +1,56 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.Scanner;
public class StorageDeviceLister {
static void deviceList(Scanner UserInput) {
public static String device = "";
public static String fullPath = "";
protected static String deviceCheck(Scanner UserInput) {
// 1. lsblk wird genau EINMAL aufgerufen
deviceList();
// 2. Die Abfrage-Schleife
while (true) {
device = UserInput.nextLine();
if (device.isBlank()) {
System.out.println("Oops... Device name is empty. Did you missclick?");
continue;
}
Path path = Path.of("/dev/" + device);
try {
// Versuche, den echten Pfad zu finden
fullPath = path.toRealPath().toString();
// Wenn wir hier ankommen, war der Pfad gültig
System.out.println("Using device: " + fullPath);
return fullPath;
} catch (IOException e) {
// Fehler-Output, danach springt die Schleife wieder nach oben
System.out.println("Failed to access device! Invalid path or no access. Please try again.");
}
}
}
private static void deviceList() {
try {
ProcessBuilder pb = new ProcessBuilder("lsblk");
Process process = pb.start();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream())
);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
process.waitFor();
System.out.println("Please enter the name of your device (without /dev/):");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
String device = UserInput.nextLine();
System.out.println("Using device: " + device);
}
}