Skip to content

Commit d11d99d

Browse files
authored
Update main.cr
1 parent bce0cb8 commit d11d99d

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

HackerOS-Updater/main.cr

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ RESET = "\e[0m"
1313
HACKEROS_UPDATE_SCRIPT = "/usr/share/HackerOS/Scripts/Bin/update-hackeros.sh"
1414
WALLPAPERS_UPDATE_SCRIPT = "/usr/share/HackerOS/Scripts/Bin/update-wallpapers.sh"
1515
BIN_PATH = "#{ENV["HOME"]}/.hackeros/hacker/HackerOS-Updates/HackerOS-Updater"
16-
AUTO_SCRIPT_PATH = "#{ENV["HOME"]}/.hackeros/auto-update.sh" # Script to wait for internet
16+
AUTO_SCRIPT_PATH = "#{ENV["HOME"]}/.hackeros/auto-update.sh" # Script to wait for internet
1717

1818
def display_header(title : String)
1919
puts "<--------[ #{title} ]-------->".colorize(:yellow)
2020
end
2121

2222
def run_command(cmd : String) : {Bool, String}
23-
output = IO::Memory.new
24-
status = Process.run(cmd, shell: true, output: output, error: output)
25-
{status.success?, output.to_s}
23+
status = Process.run(cmd, shell: true, input: Process::Redirect::Inherit, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
24+
{status.success?, ""}
2625
end
2726

2827
def get_status(success : Bool) : String
@@ -33,7 +32,7 @@ def get_status(success : Bool) : String
3332
end
3433
end
3534

36-
def perform_updates : {String, String, String, String}
35+
def perform_updates : {String, String, String, String, String, String}
3736
# APT Update
3837
display_header("System Update")
3938
apt_success = true
@@ -60,20 +59,24 @@ def perform_updates : {String, String, String, String}
6059

6160
# HackerOS Update
6261
display_header("HackerOS Update")
63-
run_command(HACKEROS_UPDATE_SCRIPT)
62+
hacker_success, _ = run_command(HACKEROS_UPDATE_SCRIPT)
63+
hacker_status = get_status(hacker_success)
6464

6565
# Wallpapers Update
6666
display_header("Wallpaper Updates")
67-
run_command(WALLPAPERS_UPDATE_SCRIPT)
67+
wall_success, _ = run_command(WALLPAPERS_UPDATE_SCRIPT)
68+
wall_status = get_status(wall_success)
6869

69-
{apt_status, flatpak_status, snap_status, fw_status}
70+
{apt_status, flatpak_status, snap_status, fw_status, hacker_status, wall_status}
7071
end
7172

72-
def show_summary(apt_status, flatpak_status, snap_status, fw_status)
73+
def show_summary(apt_status, flatpak_status, snap_status, fw_status, hacker_status, wall_status)
7374
puts "\nSystem Updates - #{apt_status}"
7475
puts "Flatpak Updates - #{flatpak_status}"
7576
puts "Snap Updates - #{snap_status}"
7677
puts "Firmware Updates - #{fw_status}"
78+
puts "HackerOS Updates - #{hacker_status}"
79+
puts "Wallpaper Updates - #{wall_status}"
7780
end
7881

7982
def enable_automatic_updates
@@ -85,7 +88,6 @@ def enable_automatic_updates
8588
done
8689
#{BIN_PATH}
8790
SCRIPT
88-
8991
File.write(AUTO_SCRIPT_PATH, auto_script)
9092
File.chmod(AUTO_SCRIPT_PATH, 0o755)
9193

@@ -97,7 +99,6 @@ def enable_automatic_updates
9799
run_command("crontab /tmp/crontab.txt")
98100
File.delete("/tmp/crontab.txt")
99101
end
100-
101102
puts "#{GREEN}Automatic updates enabled.#{RESET}"
102103
end
103104

@@ -111,7 +112,6 @@ def disable_automatic_updates
111112

112113
# Remove script if exists
113114
File.delete(AUTO_SCRIPT_PATH) if File.exists?(AUTO_SCRIPT_PATH)
114-
115115
puts "#{GREEN}Automatic updates disabled.#{RESET}"
116116
end
117117

@@ -123,10 +123,8 @@ def show_gui_menu
123123
puts "[L]og out - Log out from current session"
124124
puts "[T]erminal - Open a new Alacritty terminal"
125125
puts "[A]utomatic Updates - Enable automatic updates on boot"
126-
127126
print "Enter your choice: "
128127
choice = gets.try(&.chomp.upcase)
129-
130128
case choice
131129
when "Q"
132130
exit(0)
@@ -172,12 +170,12 @@ def main
172170
return
173171
end
174172

175-
apt_status, flatpak_status, snap_status, fw_status = perform_updates
176-
show_summary(apt_status, flatpak_status, snap_status, fw_status)
173+
apt_status, flatpak_status, snap_status, fw_status, hacker_status, wall_status = perform_updates
174+
show_summary(apt_status, flatpak_status, snap_status, fw_status, hacker_status, wall_status)
177175

178176
if gui_mode
179177
show_gui_menu
180178
end
181179
end
182180

183-
main if __FILE__ == Process.executable_path
181+
main

0 commit comments

Comments
 (0)