Skip to content

Commit cedaedc

Browse files
authored
Adding Source Code
java,javascript,ruby,rust,lua,perl
1 parent 5736316 commit cedaedc

File tree

8 files changed

+905
-0
lines changed

8 files changed

+905
-0
lines changed

java/EFIFixer.java

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import java.io.BufferedReader;
2+
import java.io.File;
3+
import java.io.InputStreamReader;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.nio.file.StandardCopyOption;
8+
import java.util.Scanner;
9+
10+
public class EFIFixer {
11+
// Color codes
12+
private static final String RED = "\u001B[31m";
13+
private static final String BLUE = "\u001B[34m";
14+
private static final String GREEN = "\u001B[32m";
15+
private static final String YELLOW = "\u001B[33m";
16+
private static final String UL = "\u001B[4m";
17+
private static final String RESET = "\u001B[0m";
18+
19+
public static void main(String[] args) {
20+
clearScreen();
21+
coderMark();
22+
23+
String backupDir = getBackupDir();
24+
String efiPartition = getEfiPartition();
25+
String volEfiDir = "/Volumes/EFI/";
26+
String volEfiEfi = "/Volumes/EFI/EFI";
27+
28+
System.out.println(YELLOW + "\nChoose a method: \n" + RESET);
29+
System.out.println("1. " + GREEN + "Format EFI partition and restore backup" + RESET);
30+
System.out.println("2. " + BLUE + "Delete contents of EFI partition and restore backup" + RESET);
31+
System.out.println("3. " + RED + "Exit" + RESET);
32+
33+
System.out.print("\nEnter your choice: ");
34+
Scanner scanner = new Scanner(System.in);
35+
String choice = scanner.nextLine();
36+
37+
switch (choice) {
38+
case "1":
39+
System.out.println(GREEN + "Starting format process and backup..." + RESET);
40+
executeCommand("cd " + volEfiDir + " && cp -r EFI " + backupDir);
41+
executeCommand("sudo diskutil unmount " + efiPartition);
42+
executeCommand("sudo newfs_msdos -v EFI -F 32 " + efiPartition);
43+
executeCommand("sudo diskutil mount " + efiPartition);
44+
executeCommand("cd " + backupDir + " && cp -r EFI " + volEfiDir);
45+
System.out.println(GREEN + "Fixed EFI Partition Successfully.." + RESET);
46+
break;
47+
case "2":
48+
System.out.println(RED + "Starting deletion process and backup..." + RESET);
49+
executeCommand("cd " + volEfiDir + " && cp -r EFI " + backupDir);
50+
executeCommand("sudo rm -rf " + volEfiEfi);
51+
executeCommand("cd " + backupDir + " && cp -r EFI " + volEfiDir);
52+
System.out.println(GREEN + "Fixed EFI Partition Successfully.." + RESET);
53+
break;
54+
case "3":
55+
clearScreen();
56+
coderMark();
57+
System.out.println(GREEN + "Thanks for using this script!" + RESET);
58+
break;
59+
default:
60+
System.out.println(RED + "Invalid choice." + RESET);
61+
}
62+
63+
scanner.close();
64+
}
65+
66+
private static void coderMark() {
67+
System.out.println(
68+
"╭━━━╮╱╱╱╱╱╱╱╱╱╱╱╱╱╭━━━┳╮\n" +
69+
"┃╭━━╯╱╱╱╱╱╱╱╱╱╱╱╱╱┃╭━━┫┃" + GREEN + "\n" +
70+
"┃╰━━┳╮╭┳━┳━━┳━━┳━╮┃╰━━┫┃╭╮╱╭┳━╮╭━╮\n" +
71+
"┃╭━━┫┃┃┃╭┫╭╮┃╭╮┃╭╮┫╭━━┫┃┃┃╱┃┃╭╮┫╭╮╮" + BLUE + "\n" +
72+
"┃┃╱╱┃╰╯┃┃┃╰╯┃╰╯┃┃┃┃┃╱╱┃╰┫╰━╯┃┃┃┃┃┃┃\n" +
73+
"╰╯╱╱╰━━┻╯╰━╮┣━━┻╯╰┻╯╱╱╰━┻━╮╭┻╯╰┻╯╰╯" + RESET + "\n" +
74+
"╱╱╱╱╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱╱╱╱╭━╯┃\n" +
75+
"╱╱╱╱╱╱╱╱╱╱╱╰╯╱╱╱╱╱╱╱╱╱╱╱╰━━╯\n\n" +
76+
UL + GREEN + "EFI Fixer Hackintosh " + RESET + UL + "v0.1" + RESET
77+
);
78+
}
79+
80+
private static boolean isMounted(String partition) {
81+
try {
82+
Process process = Runtime.getRuntime().exec("mount");
83+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
84+
String line;
85+
while ((line = reader.readLine()) != null) {
86+
if (line.contains(partition) && line.contains("type fat32")) {
87+
return true;
88+
}
89+
}
90+
return false;
91+
} catch (Exception e) {
92+
System.out.println(RED + "Error checking mount status: " + e.getMessage() + RESET);
93+
return false;
94+
}
95+
}
96+
97+
private static String getEfiPartition() {
98+
System.out.println(YELLOW + "\n(Executed diskutil list ~ [just copy EFI Partition])" + RESET);
99+
executeCommand("diskutil list");
100+
System.out.print(GREEN + "\nEnter EFI partition directory" + RESET + " (e.g., /dev/disk2s1): ");
101+
Scanner scanner = new Scanner(System.in);
102+
String efiPartition = scanner.nextLine().trim();
103+
104+
if (!isMounted(efiPartition)) {
105+
System.out.println(RED + "Partition is not mounted or invalid.\n" + RESET);
106+
System.out.print(YELLOW + "Do you want to mount now?" + RED + " Sudo Password Required!" + RESET + " (y/n) ");
107+
String answer = scanner.nextLine().toLowerCase();
108+
if (answer.equals("y")) {
109+
executeCommand("sudo diskutil mount " + efiPartition);
110+
}
111+
}
112+
113+
return efiPartition;
114+
}
115+
116+
private static String getBackupDir() {
117+
System.out.println(YELLOW + "\n(e.g., Below using pwd command ~ [just copy and paste enter])" + RESET);
118+
executeCommand("pwd");
119+
System.out.print(GREEN + "\nEnter Backup directory: " + RESET);
120+
Scanner scanner = new Scanner(System.in);
121+
return scanner.nextLine().trim();
122+
}
123+
124+
private static void executeCommand(String command) {
125+
try {
126+
Process process = Runtime.getRuntime().exec(command);
127+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
128+
String line;
129+
while ((line = reader.readLine()) != null) {
130+
System.out.println(line);
131+
}
132+
process.waitFor();
133+
} catch (Exception e) {
134+
System.out.println(RED + "Error executing command: " + YELLOW + e.getMessage() + RESET);
135+
136+
if (e.getMessage().contains("already unmounted") || e.getMessage().contains("failed to unmount")) {
137+
System.out.println(YELLOW + "Trying to force unmount..." + RESET);
138+
try {
139+
Runtime.getRuntime().exec("sudo diskutil unmount force " + getEfiPartition());
140+
} catch (Exception ex) {
141+
System.out.println(RED + "Forceful unmount failed: " + YELLOW + ex.getMessage() + RESET);
142+
System.out.println(RED + "Please try rebooting your system and running the script again." + RESET);
143+
System.exit(1);
144+
}
145+
} else {
146+
System.out.println(RED + "Unhandled error: " + YELLOW + e.getMessage() + RESET);
147+
System.out.println(RED + "Please check the system logs for more details." + RESET);
148+
System.exit(1);
149+
}
150+
}
151+
}
152+
153+
private static void clearScreen() {
154+
System.out.print("\033[H\033[2J");
155+
System.out.flush();
156+
}
157+
}
158+

lua/efifix.lua

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
local lfs = require("lfs")
2+
local os = require("os")
3+
4+
-- Color codes
5+
local RED = "\27[31m"
6+
local BLUE = "\27[34m"
7+
local GREEN = "\27[32m"
8+
local YELLOW = "\27[33m"
9+
local UL = "\27[4m"
10+
local RESET = "\27[0m"
11+
12+
-- Display coder sign
13+
local function coder_mark()
14+
print([[
15+
╭━━━╮╱╱╱╱╱╱╱╱╱╱╱╱╱╭━━━┳╮
16+
┃╭━━╯╱╱╱╱╱╱╱╱╱╱╱╱╱┃╭━━┫┃]] .. GREEN .. [[
17+
┃╰━━┳╮╭┳━┳━━┳━━┳━╮┃╰━━┫┃╭╮╱╭┳━╮╭━╮
18+
┃╭━━┫┃┃┃╭┫╭╮┃╭╮┃╭╮┫╭━━┫┃┃┃╱┃┃╭╮┫╭╮╮]] .. BLUE .. [[
19+
┃┃╱╱┃╰╯┃┃┃╰╯┃╰╯┃┃┃┃┃╱╱┃╰┫╰━╯┃┃┃┃┃┃┃
20+
╰╯╱╱╰━━┻╯╰━╮┣━━┻╯╰┻╯╱╱╰━┻━╮╭┻╯╰┻╯╰╯]] .. RESET .. [[
21+
╱╱╱╱╱╱╱╱╱╱╱┃┃╱╱╱╱╱╱╱╱╱╱╱╭━╯┃
22+
╱╱╱╱╱╱╱╱╱╱╱╰╯╱╱╱╱╱╱╱╱╱╱╱╰━━╯
23+
24+
]] .. UL .. GREEN .. "EFI Fixer Hackintosh " .. RESET .. UL .. "v0.1" .. RESET)
25+
end
26+
27+
-- Check if a partition is mounted
28+
local function is_mounted(partition)
29+
local f = io.popen("mount")
30+
local output = f:read("*all")
31+
f:close()
32+
33+
for line in output:gmatch("[^\r\n]+") do
34+
if line:find(partition) and line:find("type fat32") then
35+
return true
36+
end
37+
end
38+
return false
39+
end
40+
41+
-- Get the EFI partition from the user
42+
local function get_efi_partition()
43+
print(YELLOW .. "\n(Executed diskutil list ~ [just copy EFI Partition])" .. RESET)
44+
os.execute('diskutil list')
45+
io.write(GREEN .. "\nEnter EFI partition directory" .. RESET .. " (e.g., /dev/disk2s1): ")
46+
local efi_partition = io.read():gsub("^%s*(.-)%s*$", "%1")
47+
48+
if not is_mounted(efi_partition) then
49+
print(RED .. "Partition is not mounted or invalid.\n" .. RESET)
50+
io.write(YELLOW .. "Do you want to mount now?" .. RED .. " Sudo Password Required!" .. RESET .. " (y/n) ")
51+
local answer = io.read():lower()
52+
if answer == 'y' then
53+
os.execute("sudo diskutil mount " .. efi_partition)
54+
end
55+
end
56+
57+
return efi_partition
58+
end
59+
60+
-- Get the backup directory from the user
61+
local function get_backup_dir()
62+
print(YELLOW .. "\n(e.g., Below using pwd command ~ [just copy and paste enter])" .. RESET)
63+
os.execute('pwd')
64+
io.write(GREEN .. "\nEnter Backup directory: " .. RESET)
65+
local backup_dir = io.read():gsub("^%s*(.-)%s*$", "%1")
66+
return backup_dir
67+
end
68+
69+
-- Execute a system command and handle errors
70+
local function execute_command(command)
71+
local success, exit_type, exit_code = os.execute(command)
72+
if not success then
73+
print(RED .. "Error executing command: " .. YELLOW .. command .. RESET)
74+
if exit_type == "exit" and exit_code == 1 then
75+
print(YELLOW .. "Trying to force unmount..." .. RESET)
76+
local force_success = os.execute('sudo diskutil unmount force ' .. efi_partition)
77+
if not force_success then
78+
print(RED .. "Forceful unmount failed." .. RESET)
79+
print(RED .. "Please try rebooting your system and running the script again." .. RESET)
80+
os.exit(1)
81+
end
82+
else
83+
print(RED .. "Unhandled error." .. RESET)
84+
print(RED .. "Please check the system logs for more details." .. RESET)
85+
os.exit(1)
86+
end
87+
end
88+
end
89+
90+
-- Main function
91+
local function main()
92+
os.execute('clear')
93+
coder_mark()
94+
95+
local backup_dir = get_backup_dir()
96+
local efi_partition = get_efi_partition()
97+
local vol_efi_dir = '/Volumes/EFI/'
98+
local vol_efi_efi = '/Volumes/EFI/EFI'
99+
100+
print(YELLOW .. "\nChoose a method: \n" .. RESET)
101+
print("1. " .. GREEN .. "Format EFI partition and restore backup" .. RESET)
102+
print("2. " .. BLUE .. "Delete contents of EFI partition and restore backup" .. RESET)
103+
print("3. " .. RED .. "Exit" .. RESET)
104+
105+
io.write("\nEnter your choice: ")
106+
local choice = io.read()
107+
108+
if choice == '1' then
109+
print(GREEN .. "Starting format process and backup..." .. RESET)
110+
execute_command("cd " .. vol_efi_dir .. " && cp -r EFI " .. backup_dir)
111+
execute_command("sudo diskutil unmount " .. efi_partition)
112+
execute_command("sudo newfs_msdos -v EFI -F 32 " .. efi_partition)
113+
execute_command("sudo diskutil mount " .. efi_partition)
114+
execute_command("cd " .. backup_dir .. " && cp -r EFI " .. vol_efi_dir)
115+
print(GREEN .. "Fixed EFI Partition Successfully.." .. RESET)
116+
elseif choice == '2' then
117+
print(RED .. "Starting deletion process and backup..." .. RESET)
118+
execute_command("cd " .. vol_efi_dir .. " && cp -r EFI " .. backup_dir)
119+
execute_command("sudo rm -rf " .. vol_efi_efi)
120+
execute_command("cd " .. backup_dir .. " && cp -r EFI " .. vol_efi_dir)
121+
print(GREEN .. "Fixed EFI Partition Successfully.." .. RESET)
122+
elseif choice == '3' then
123+
os.execute('clear')
124+
coder_mark()
125+
print(GREEN .. "Thanks for using this script!" .. RESET)
126+
else
127+
print(RED .. "Invalid choice." .. RESET)
128+
end
129+
end
130+
131+
main()
132+

0 commit comments

Comments
 (0)