From 456d170b9b5d953a8688ea78dcb4c264898c6914 Mon Sep 17 00:00:00 2001 From: koffeejava Date: Fri, 13 Mar 2026 17:55:16 -0600 Subject: [PATCH] Made the setup not work in root. --- src/installer.cr | 57 +++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/src/installer.cr b/src/installer.cr index 28f3a83..8134ebe 100644 --- a/src/installer.cr +++ b/src/installer.cr @@ -9,17 +9,17 @@ lib C fun getuid : UInt32 end -if C.getuid != 0 - puts "#{red}#{bold}You must be in root to install wfetch!#{reset}" - exit(0) -end - sudo_user = ENV["SUDO_USER"]? home = "/home/#{sudo_user}" OptionParser.parse do |parser| parser.banner = "Usage: installer [arguments]" parser.on("-i", "--install-only", "Only instals wfetch; Does not run setup") { + if C.getuid != 0 + puts "#{red}#{bold}You must be in root to install wfetch!#{reset}" + exit(0) + end + puts "#{orange}#{bold}wfetch installer 1.0.0#{reset}" File.copy("data/wfetch", "/usr/bin/wfetch") @@ -28,6 +28,11 @@ OptionParser.parse do |parser| exit } parser.on("-u", "--uninstall", "Uninstalls wfetch"){ + if C.getuid != 0 + puts "#{red}#{bold}You must be in root to uninstall wfetch!#{reset}" + exit(0) + end + File.delete("/usr/bin/wfetch") File.delete("#{home}/.local/share/Wfetch/disp.toml") File.delete("#{home}/.local/share/Wfetch/config.toml") @@ -36,6 +41,11 @@ OptionParser.parse do |parser| exit } parser.on("-s", "--setup", "Runs setup") { + if C.getuid = 0 + puts "#{red}#{bold}Don't run the setup in root!#{reset}" + exit(0) + end + Dir.mkdir("/home/#{sudo_user}/.local/share/Wfetch") @@ -81,38 +91,5 @@ OptionParser.parse do |parser| end end -puts "#{orange}#{bold}wfetch installer 1.0.0#{reset}" - -File.copy("data/wfetch", "/usr/bin/wfetch") - -puts "#{orange}#{bold}Finished installing! Let's setup.#{reset}" - -puts "Please enter your WeatherApi key (Learn to get one at README.md):" - -api = gets - -puts "Please enter the (closest) city you live in: " - -city = gets - -puts "#{orange}#{bold}Config setup finished. Starting disp setup.#{reset}" - -File.write("/home/#{sudo_user}/.local/share/Wfetch/config.toml", " -api = \"#{api}\" -city = \"#{city}\"") - -puts "#{orange}#{bold}Would you like customary (1), metric (2), or both (3)?#{reset}" - -choice = gets - -if choice == "1" - File.copy("data/1.toml", "/home/#{sudo_user}/.local/share/Wfetch/disp.toml") -elsif choice == "2" - File.copy("data/2.toml", "/home/#{sudo_user}/.local/share/Wfetch/disp.toml") -elsif choice == "3" - File.copy("data/3.toml", "/home/#{sudo_user}/.local/share/Wfetch/disp.toml") -else - File.copy("data/1.toml", "/home/#{sudo_user}/.local/share/Wfetch/disp.toml") -end - -puts "#{orange}#{bold}Install finnished. Enjoy!#{reset}" \ No newline at end of file + if ARGV.empty? + puts "Run installer -h" \ No newline at end of file