Compare commits
10 Commits
cd6100548c
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48f4093906 | ||
|
|
0edbc24003 | ||
|
|
ecb1f7be3e | ||
|
|
66e4247199 | ||
|
|
1661e3e060 | ||
|
|
c086bcc2e6 | ||
|
|
68d7520e26 | ||
|
|
2c076c4c95 | ||
|
|
4d6e8b975f | ||
|
|
baab63f846 |
14
.gitignore
vendored
14
.gitignore
vendored
@@ -22,3 +22,17 @@
|
|||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
|
target/
|
||||||
|
*.class
|
||||||
|
.mtj.tmp/
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.ear
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
# VS Code specific
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
.vscode/
|
||||||
@@ -7,7 +7,7 @@ Small and lightweight image and iso flasher build on `dd`.
|
|||||||
[](https://en.wikipedia.org/wiki/Software_release_life_cycle#Beta)
|
[](https://en.wikipedia.org/wiki/Software_release_life_cycle#Beta)
|
||||||
|
|
||||||
# About
|
# About
|
||||||
Java program using `dd` to make flashing iso and image files easier on the terminal. This program allows anyone to flash iso and image files without having to search for extra GUI tools and by keeping it simple and resource-friendly.
|
Java program using `dd` to make flashing iso and image files easier on the terminal. This program allows anyone to flash iso and image files without having to search for extra GUI tools by keeping it simple and resource-friendly.
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
- `Java`: 21 (Download [here](https://www.oracle.com/java/technologies/downloads/#java21)
|
- `Java`: 21 (Download [here](https://www.oracle.com/java/technologies/downloads/#java21)
|
||||||
|
|||||||
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>
|
||||||
39
src/main/java/org/cametendo/BlockSize.java
Normal file
39
src/main/java/org/cametendo/BlockSize.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class BlockSize {
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
switch (blockSizeInput) {
|
||||||
|
case "1":
|
||||||
|
blockSizeString = "512KB";
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
blockSizeString = "1M";
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
blockSizeString = "2M";
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
blockSizeString = "4M";
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
|
blockSizeString = "8M";
|
||||||
|
break;
|
||||||
|
case "6":
|
||||||
|
blockSizeString = "16M";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
blockSizeString = "4M";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
System.out.println("Using blocksize of: " + blockSizeString);
|
||||||
|
return blockSizeString;
|
||||||
|
}
|
||||||
|
}
|
||||||
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)");
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/main/java/org/cametendo/Flasher.java
Normal file
24
src/main/java/org/cametendo/Flasher.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Flasher {
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/main/java/org/cametendo/Greeting.java
Normal file
7
src/main/java/org/cametendo/Greeting.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
public class Greeting {
|
||||||
|
public static void greeting() {
|
||||||
|
System.out.println("Welcome to cflash!");
|
||||||
|
System.out.println("Would you like to flash an image (Y/n)");
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/java/org/cametendo/Main.java
Normal file
25
src/main/java/org/cametendo/Main.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
Scanner UserInput = new Scanner(System.in);
|
||||||
|
|
||||||
|
Greeting.greeting();
|
||||||
|
String input = UserInput.nextLine();
|
||||||
|
|
||||||
|
if (YesNo.check(input)) {
|
||||||
|
System.out.println("Please choose the to be flashed device (f. e. sda)");
|
||||||
|
} else {
|
||||||
|
System.out.println("Canceling...");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
StorageDeviceLister.deviceCheck(UserInput);
|
||||||
|
FilePathAdd.filePath(UserInput);
|
||||||
|
BlockSize.blockSize(UserInput);
|
||||||
|
OflagHandler.handleOflag(UserInput);
|
||||||
|
Flasher.flasher(UserInput);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/main/java/org/cametendo/OflagHandler.java
Normal file
33
src/main/java/org/cametendo/OflagHandler.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class OflagHandler {
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
switch (oflagHandleInput) {
|
||||||
|
case "1":
|
||||||
|
oflagHandleString = "direct";
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
oflagHandleString = "dsync";
|
||||||
|
break;
|
||||||
|
case "3":
|
||||||
|
oflagHandleString = "sync";
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
oflagHandleString = "nocache";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
oflagHandleString = "direct";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
System.out.println("Using oflag: " + oflagHandleString);
|
||||||
|
return oflagHandleString;
|
||||||
|
}
|
||||||
|
}
|
||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/main/java/org/cametendo/YesNo.java
Normal file
17
src/main/java/org/cametendo/YesNo.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package org.cametendo;
|
||||||
|
public class YesNo {
|
||||||
|
public static boolean check(String input) {
|
||||||
|
switch (input) {
|
||||||
|
case "Y":
|
||||||
|
return true;
|
||||||
|
case "y":
|
||||||
|
return true;
|
||||||
|
case "":
|
||||||
|
return true;
|
||||||
|
case "n":
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user