94 lines
2.6 KiB
Crystal
94 lines
2.6 KiB
Crystal
require "option_parser"
|
|
|
|
orange = "\e[38;5;214m"
|
|
red = "\e[0;31m"
|
|
bold = "\033[1m"
|
|
reset = "\e[0m"
|
|
|
|
sudo_user = ENV["SUDO_USER"]?
|
|
home = "/home/#{sudo_user}"
|
|
|
|
OptionParser.parse do |parser|
|
|
parser.banner = "Usage: wf-tool [arguments]"
|
|
parser.on("-i", "--install-only", "Only instals wfetch; Does not run setup") {
|
|
if LibC.getuid != 0
|
|
puts "#{red}#{bold}You must be in root to install wfetch!#{reset}"
|
|
exit(0)
|
|
end
|
|
|
|
puts "#{orange}#{bold}wfetch installer#{reset}"
|
|
|
|
File.copy("data/wfetch", "/usr/bin/wfetch")
|
|
|
|
puts "#{orange}#{bold}Finished installing!#{reset}"
|
|
exit
|
|
}
|
|
parser.on("-u", "--uninstall", "Uninstalls wfetch"){
|
|
if LibC.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")
|
|
Dir.delete("#{home}/.local/share/Wfetch")
|
|
puts "#{bold}#{orange}Finished#{reset}"
|
|
exit
|
|
}
|
|
parser.on("-s", "--setup", "Runs setup") {
|
|
if LibC.getuid == 0
|
|
puts "#{red}#{bold}Don't run the setup in root!#{reset}"
|
|
exit(0)
|
|
end
|
|
|
|
Dir.mkdir(Path["~/.local/share/Wfetch"].expand(home: true))
|
|
|
|
|
|
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(Path["~/.local/share/Wfetch/config.toml"].expand(home: true), "
|
|
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", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true))
|
|
elsif choice == "2"
|
|
File.copy("data/2.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true))
|
|
elsif choice == "3"
|
|
File.copy("data/3.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true))
|
|
else
|
|
File.copy("data/1.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true))
|
|
end
|
|
|
|
puts "#{orange}#{bold}Setup finnished. Enjoy!#{reset}"
|
|
exit
|
|
}
|
|
parser.on("-h", "--help", "Show this help") do
|
|
|
|
puts parser
|
|
exit(1)
|
|
end
|
|
parser.invalid_option do |flag|
|
|
STDERR.puts "ERROR: #{flag} is not a valid option."
|
|
STDERR.puts parser
|
|
exit(1)
|
|
end
|
|
end
|
|
|
|
if ARGV.empty?
|
|
puts "Run wf-tool -h"
|
|
end |