Skip to content

Commit 7bb880a

Browse files
authored
Update main.cr
1 parent 4cf7fb9 commit 7bb880a

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

source-code/src/main.cr

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1-
// apt
2-
// flatpak
1+
require "option_parser"
32

4-
> sudo apt update
5-
> sudo apt upgrade -y
6-
> flatpak update -y
3+
only_system = false
4+
5+
OptionParser.parse do |parser|
6+
parser.banner = "Usage: update_tool [options]"
7+
8+
parser.on("--only-system", "Run only the system update script") do
9+
only_system = true
10+
end
11+
12+
parser.on("-h", "--help", "Show this help") do
13+
puts parser
14+
exit
15+
end
16+
17+
parser.invalid_option do |flag|
18+
STDERR.puts "ERROR: #{flag} is not a valid option."
19+
STDERR.puts parser
20+
exit(1)
21+
end
22+
end
23+
24+
def run_command(cmd : String)
25+
process = Process.new(cmd, shell: true, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
26+
status = process.wait
27+
if !status.success?
28+
puts "Command '#{cmd}' failed with exit code #{status.exit_code}"
29+
exit(status.exit_code)
30+
end
31+
end
32+
33+
if only_system
34+
puts "Running only system update script..."
35+
run_command("/usr/share/HackerOS/Scripts/Bin/update-hackeros.sh")
36+
else
37+
puts "Running full updates..."
38+
run_command("sudo apt update")
39+
run_command("sudo apt upgrade -y")
40+
run_command("flatpak update -y")
41+
end
42+
43+
puts "Updates completed successfully."

0 commit comments

Comments
 (0)