This repository has been archived by the owner on Jan 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnevermore.cr
65 lines (59 loc) · 2.38 KB
/
nevermore.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Usage: update_hosts [arguments]
# -v, --version Show the version
# -b, --basic Get the basic hosts file that will block Ads
# -e, --everything Get the hosts file that blocks fake news, gambling, porn, and social media
# -r, --reset Reset the hosts file
# -h, --help Show this help
# -d HTTPFILE, --download=HTTPFILE Download a hosts file via http or https
# -l LOCALFILE, --local=LOCALFILE Overwrite your hosts file using a local file
# For download options, this downloads a "hosts" file to the directory that this application is running in
# Big thanks to StevenBlack for aggregating and all the great sources
# basic hosts file: "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
# everything hosts file: "https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts"
require "option_parser"
require "./update_hosts_functions.cr"
# paramaters
option = "basic"
version = "Version 0.1"
download_file = ""
local_file = ""
os_info = get_os
# command-line options
OptionParser.parse do |parser|
parser.banner = "Usage: update-hosts [arguments]"
parser.on("-v", "--version", "Show the version") do
puts version
exit(0)
end
parser.on("-b", "--basic", "Get the basic hosts file that will block Ads") { option = "basic" }
parser.on("-e", "--everything", "Get the hosts file that blocks fake news, gambling, porn, and social media") { option = "everything" }
parser.on("-r", "--reset", "Reset the hosts file") { option = "reset" }
parser.on("-h", "--help", "Show this help") do
puts parser
exit
end
parser.on("-d HTTPFILE", "--download=HTTPFILE", "Download a hosts file via http or https") do |httpfile|
option = "download"
download_file = httpfile
end
parser.on("-l LOCALFILE", "--local=LOCALFILE", "Overwrite your hosts file using a local file") do |localfile|
option = "local"
local_file = localfile
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
# Driver code
if ["basic", "everything", "download", "local"].includes?(option)
get_hosts_file(option, download_file, local_file)
write_hosts_file(os_info)
reset_network(os_info)
elsif option == "reset"
write_reset_file(os_info)
reset_network(os_info)
else
# NA
end