From baab63f84646d3b734c2c099265248a45c69d068 Mon Sep 17 00:00:00 2001 From: Cametendo Date: Mon, 9 Feb 2026 08:26:01 +0100 Subject: [PATCH 1/6] create base --- Greeting.java | 6 ++++++ Main.java | 19 +++++++++++++++++++ YesNo.java | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 Greeting.java create mode 100644 Main.java create mode 100644 YesNo.java diff --git a/Greeting.java b/Greeting.java new file mode 100644 index 0000000..3c8be62 --- /dev/null +++ b/Greeting.java @@ -0,0 +1,6 @@ +public class Greeting { + public void greeting() { + System.out.println("Welcome to cflash!"); + System.out.println("Would you like to flash an image (Y/n)"); + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..5c64a51 --- /dev/null +++ b/Main.java @@ -0,0 +1,19 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner UserInput = new Scanner(System.in); + + greeting(); + String input = UserInput.nextLine(); + + if (YesNo.check(input)) { + System.out.println("Please choose a device"); + } else { + System.out.println("Canceling..."); + System.exit(0); + } + + + } +} diff --git a/YesNo.java b/YesNo.java new file mode 100644 index 0000000..5280bc9 --- /dev/null +++ b/YesNo.java @@ -0,0 +1,16 @@ +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; + } + } +} From 4d6e8b975fe655c070ebb5e9f8154936070c62e9 Mon Sep 17 00:00:00 2001 From: Cametendo Date: Mon, 9 Feb 2026 11:58:37 +0100 Subject: [PATCH 2/6] create devicecheck, filepathcheck and blocksize --- .gitignore | 6 ++++++ BlockSize.java | 34 ++++++++++++++++++++++++++++++++++ FilePathAdd.java | 9 +++++++++ Greeting.java | 2 +- Main.java | 9 ++++++--- StorageDeviceLister.java | 27 +++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 BlockSize.java create mode 100644 FilePathAdd.java create mode 100644 StorageDeviceLister.java diff --git a/.gitignore b/.gitignore index 524f096..2d00de4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,9 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* + +# IDE Stuff +.vscode/* +.vscode/ +*.vscode +.vscode \ No newline at end of file diff --git a/BlockSize.java b/BlockSize.java new file mode 100644 index 0000000..df320e3 --- /dev/null +++ b/BlockSize.java @@ -0,0 +1,34 @@ +import java.util.Scanner; + +public class BlockSize { + public static void 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"; + 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; + } + } +} diff --git a/FilePathAdd.java b/FilePathAdd.java new file mode 100644 index 0000000..fc8d79c --- /dev/null +++ b/FilePathAdd.java @@ -0,0 +1,9 @@ +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 Path = UserInput.nextLine(); + System.out.println("Using File: " + Path); + } +} diff --git a/Greeting.java b/Greeting.java index 3c8be62..5c286c2 100644 --- a/Greeting.java +++ b/Greeting.java @@ -1,5 +1,5 @@ public class Greeting { - public void greeting() { + public static void greeting() { System.out.println("Welcome to cflash!"); System.out.println("Would you like to flash an image (Y/n)"); } diff --git a/Main.java b/Main.java index 5c64a51..18a79c7 100644 --- a/Main.java +++ b/Main.java @@ -1,18 +1,21 @@ import java.util.Scanner; public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws InterruptedException { Scanner UserInput = new Scanner(System.in); - greeting(); + Greeting.greeting(); String input = UserInput.nextLine(); if (YesNo.check(input)) { - System.out.println("Please choose a device"); + System.out.println("Please choose the to be flashed device (f. e. sda)"); } else { System.out.println("Canceling..."); System.exit(0); } + StorageDeviceLister.deviceList(UserInput); + FilePathAdd.filePath(UserInput); + } diff --git a/StorageDeviceLister.java b/StorageDeviceLister.java new file mode 100644 index 0000000..26c7b20 --- /dev/null +++ b/StorageDeviceLister.java @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class StorageDeviceLister { + static void 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: " + device); + } +} From 2c076c4c95a8d9f5b67145966c1a7d35d17ccdc1 Mon Sep 17 00:00:00 2001 From: Cametendo Date: Wed, 18 Mar 2026 23:03:35 +0100 Subject: [PATCH 3/6] Added oflag --- FilePathAdd.java | 4 ++-- Flasher.java | 11 +++++++++++ Main.java | 2 ++ OflagHandler.java | 28 ++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Flasher.java create mode 100644 OflagHandler.java diff --git a/FilePathAdd.java b/FilePathAdd.java index fc8d79c..a39679e 100644 --- a/FilePathAdd.java +++ b/FilePathAdd.java @@ -3,7 +3,7 @@ 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 Path = UserInput.nextLine(); - System.out.println("Using File: " + Path); + String ImagePath = UserInput.nextLine(); + System.out.println("Using File: " + ImagePath); } } diff --git a/Flasher.java b/Flasher.java new file mode 100644 index 0000000..352ba71 --- /dev/null +++ b/Flasher.java @@ -0,0 +1,11 @@ +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); + } +} diff --git a/Main.java b/Main.java index 18a79c7..4196f85 100644 --- a/Main.java +++ b/Main.java @@ -15,6 +15,8 @@ public class Main { } StorageDeviceLister.deviceList(UserInput); FilePathAdd.filePath(UserInput); + BlockSize.blockSize(UserInput); + OflagHandler.handleOflag(UserInput); diff --git a/OflagHandler.java b/OflagHandler.java new file mode 100644 index 0000000..8edb483 --- /dev/null +++ b/OflagHandler.java @@ -0,0 +1,28 @@ +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"); + String oflagHandleInput = UserInput.nextLine(); + + String oflagHandleString; + 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; + } + } +} From 68d7520e26afc8f189d5ea15bc5ce9ddcaa4ab9c Mon Sep 17 00:00:00 2001 From: Cametendo Date: Fri, 20 Mar 2026 12:14:57 +0100 Subject: [PATCH 4/6] Clarify description in README.md Removed redundant wording for clarity. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6802b33..bdb736d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Small and lightweight image and iso flasher build on `dd`. [![Status](https://img.shields.io/badge/Status-Beta-red.svg)](https://en.wikipedia.org/wiki/Software_release_life_cycle#Beta) # 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 - `Java`: 21 (Download [here](https://www.oracle.com/java/technologies/downloads/#java21) From c086bcc2e641368be0980367a305af0a2577e712 Mon Sep 17 00:00:00 2001 From: Cametendo Date: Fri, 3 Apr 2026 15:12:45 +0200 Subject: [PATCH 5/6] Made flasher show user configuration --- BlockSize.java | 8 ++++++-- FilePathAdd.java | 8 ++++++-- Flasher.java | 20 +++++++++++++++----- Main.java | 2 +- OflagHandler.java | 12 ++++++++---- StorageDeviceLister.java | 10 ++++++++-- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/BlockSize.java b/BlockSize.java index df320e3..02bab44 100644 --- a/BlockSize.java +++ b/BlockSize.java @@ -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; } } diff --git a/FilePathAdd.java b/FilePathAdd.java index a39679e..9176d3b 100644 --- a/FilePathAdd.java +++ b/FilePathAdd.java @@ -1,9 +1,13 @@ import java.util.Scanner; public class FilePathAdd { - public static void filePath(Scanner UserInput) { + + public static String ImagePath = ""; + + protected static String filePath(Scanner UserInput) { System.out.println("Please enter the FULL Path of your ISO / Image. ()"); - String ImagePath = UserInput.nextLine(); + ImagePath = UserInput.nextLine(); System.out.println("Using File: " + ImagePath); + return ImagePath; } } diff --git a/Flasher.java b/Flasher.java index 352ba71..997e549 100644 --- a/Flasher.java +++ b/Flasher.java @@ -1,11 +1,21 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; import java.util.Scanner; public class Flasher { - publicstatic voic flasher(Scanner UserInput) { + 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: " + device); + 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("Flashing..."); + } else { + System.out.println("Canceling..."); + System.exit(0); + } } } diff --git a/Main.java b/Main.java index 4196f85..58e37b8 100644 --- a/Main.java +++ b/Main.java @@ -17,7 +17,7 @@ public class Main { FilePathAdd.filePath(UserInput); BlockSize.blockSize(UserInput); OflagHandler.handleOflag(UserInput); - + Flasher.flasher(UserInput); } diff --git a/OflagHandler.java b/OflagHandler.java index 8edb483..2fa4016 100644 --- a/OflagHandler.java +++ b/OflagHandler.java @@ -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; } } diff --git a/StorageDeviceLister.java b/StorageDeviceLister.java index 26c7b20..196a92f 100644 --- a/StorageDeviceLister.java +++ b/StorageDeviceLister.java @@ -4,7 +4,11 @@ import java.io.InputStreamReader; import java.util.Scanner; public class StorageDeviceLister { - static void deviceList(Scanner UserInput) { + + public static String device = ""; + public static String fullPath = ""; + + protected static String deviceList(Scanner UserInput) { try { ProcessBuilder pb = new ProcessBuilder("lsblk"); @@ -22,6 +26,8 @@ public class StorageDeviceLister { e.printStackTrace(); } String device = UserInput.nextLine(); - System.out.println("Using device: " + device); + System.out.println("Using device: " + "/dev/" + device); + fullPath = "/dev/" + device; + return fullPath; } } From 66e424719936c71e367702a54c9d0f13765ca8bd Mon Sep 17 00:00:00 2001 From: Cametendo Date: Sat, 4 Apr 2026 19:54:18 +0200 Subject: [PATCH 6/6] Added dd --- Dd.java | 26 ++++++++++++++++++++++++++ Flasher.java | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Dd.java diff --git a/Dd.java b/Dd.java new file mode 100644 index 0000000..9db9a6a --- /dev/null +++ b/Dd.java @@ -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(); + } + } +} diff --git a/Flasher.java b/Flasher.java index 997e549..3cca041 100644 --- a/Flasher.java +++ b/Flasher.java @@ -12,10 +12,12 @@ public class Flasher { System.out.println(" - To be used oflag: " + OflagHandler.oflagHandleString); input = UserInput.nextLine(); if (YesNo.check(input)) { - System.out.println("Flashing..."); + System.out.println("Starting to flash..."); } else { System.out.println("Canceling..."); System.exit(0); } + Dd.dd(); + System.out.println("Flash completed."); } }