Compare commits
5 Commits
1661e3e060
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48f4093906 | ||
|
|
0edbc24003 | ||
|
|
ecb1f7be3e | ||
|
|
66e4247199 | ||
|
|
cd6100548c |
16
.gitignore
vendored
16
.gitignore
vendored
@@ -23,8 +23,16 @@
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
# IDE Stuff
|
target/
|
||||||
.vscode/*
|
*.class
|
||||||
|
.mtj.tmp/
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
# VS Code specific
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
.vscode/
|
.vscode/
|
||||||
*.vscode
|
|
||||||
.vscode
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class FilePathAdd {
|
|
||||||
|
|
||||||
public static String ImagePath = "";
|
|
||||||
|
|
||||||
protected static String filePath(Scanner UserInput) {
|
|
||||||
System.out.println("Please enter the FULL Path of your ISO / Image. ()");
|
|
||||||
ImagePath = UserInput.nextLine();
|
|
||||||
System.out.println("Using File: " + ImagePath);
|
|
||||||
return ImagePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)
|
3. You will be prompted to choose a byte size (default: 4M)
|
||||||
4. You will be prompted to enter your oflag (default: direct)
|
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)
|
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.
|
- 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!)
|
- 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.
|
- **IMPORTANT**: Since dd needs sudo rights, ensure you have root priviliges.
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class StorageDeviceLister {
|
|
||||||
|
|
||||||
public static String device = "";
|
|
||||||
public static String fullPath = "";
|
|
||||||
|
|
||||||
protected static String deviceList(Scanner UserInput) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ProcessBuilder pb = new ProcessBuilder("lsblk");
|
|
||||||
Process process = pb.start();
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(
|
|
||||||
new InputStreamReader(process.getInputStream())
|
|
||||||
);
|
|
||||||
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
System.out.println(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
String device = UserInput.nextLine();
|
|
||||||
System.out.println("Using device: " + "/dev/" + device);
|
|
||||||
fullPath = "/dev/" + device;
|
|
||||||
return fullPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
pom.xml
Normal file
25
pom.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.cametendo</groupId>
|
||||||
|
<artifactId>cflash</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline</artifactId>
|
||||||
|
<version>3.25.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class BlockSize {
|
public class BlockSize {
|
||||||
27
src/main/java/org/cametendo/Dd.java
Normal file
27
src/main/java/org/cametendo/Dd.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/java/org/cametendo/FilePathAdd.java
Normal file
33
src/main/java/org/cametendo/FilePathAdd.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class FilePathAdd {
|
||||||
|
|
||||||
|
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)");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Flasher {
|
public class Flasher {
|
||||||
@@ -5,17 +6,19 @@ public class Flasher {
|
|||||||
|
|
||||||
String input = "";
|
String input = "";
|
||||||
|
|
||||||
System.out.println("The programm wil use the following configuration, do you want to flash with this? (y/n)");
|
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 flashed device: " + StorageDeviceLister.fullPath);
|
||||||
System.out.println(" - To be used path: " + FilePathAdd.ImagePath);
|
System.out.println(" - To be used path: " + FilePathAdd.ImagePath);
|
||||||
System.out.println(" - To bed used blocksize: " + BlockSize.blockSizeString);
|
System.out.println(" - To bed used blocksize: " + BlockSize.blockSizeString);
|
||||||
System.out.println(" - To be used oflag: " + OflagHandler.oflagHandleString);
|
System.out.println(" - To be used oflag: " + OflagHandler.oflagHandleString);
|
||||||
input = UserInput.nextLine();
|
input = UserInput.nextLine();
|
||||||
if (YesNo.check(input)) {
|
if (YesNo.check(input)) {
|
||||||
System.out.println("Flashing...");
|
System.out.println("Starting to flash...");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Canceling...");
|
System.out.println("Canceling...");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
Dd.dd();
|
||||||
|
System.out.println("Flash completed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
public class Greeting {
|
public class Greeting {
|
||||||
public static void greeting() {
|
public static void greeting() {
|
||||||
System.out.println("Welcome to cflash!");
|
System.out.println("Welcome to cflash!");
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -13,7 +14,7 @@ public class Main {
|
|||||||
System.out.println("Canceling...");
|
System.out.println("Canceling...");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
StorageDeviceLister.deviceList(UserInput);
|
StorageDeviceLister.deviceCheck(UserInput);
|
||||||
FilePathAdd.filePath(UserInput);
|
FilePathAdd.filePath(UserInput);
|
||||||
BlockSize.blockSize(UserInput);
|
BlockSize.blockSize(UserInput);
|
||||||
OflagHandler.handleOflag(UserInput);
|
OflagHandler.handleOflag(UserInput);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class OflagHandler {
|
public class OflagHandler {
|
||||||
57
src/main/java/org/cametendo/StorageDeviceLister.java
Normal file
57
src/main/java/org/cametendo/StorageDeviceLister.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StorageDeviceLister {
|
||||||
|
|
||||||
|
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()));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
System.out.println(line);
|
||||||
|
}
|
||||||
|
process.waitFor();
|
||||||
|
System.out.println("Please enter the name of your device (without /dev/):");
|
||||||
|
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package org.cametendo;
|
||||||
public class YesNo {
|
public class YesNo {
|
||||||
public static boolean check(String input) {
|
public static boolean check(String input) {
|
||||||
switch (input) {
|
switch (input) {
|
||||||
Reference in New Issue
Block a user