-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoldsuite.rb
executable file
·135 lines (112 loc) · 3.86 KB
/
coldsuite.rb
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
require 'json'
$cache_downloads = false # Set this to true to speed up development etc
$tool_folder = './tools'
$index_template = File.read('./index_template.html')
$TOOLS = JSON.parse(File.read('./tools.json'), symbolize_names: true)
def install
print_header
setup_tool_folder
download_tools
create_index
print_instructions
end
def setup_tool_folder
puts "Tool Suite will be installed into: '#{$tool_folder}'"
puts
print 'Press enter to continue...'
STDIN.readline
puts
remove_existing_tool_folder if Dir.exist?($tool_folder)
end
# Remove existing tools folder for complete rebuild
def remove_existing_tool_folder
puts "Warning: '#{$tool_folder}' already exists. This will be removed and recreated!"
print " Is this ok? (type 'yes' if so) : "
exit unless STDIN.readline.strip == 'yes'
FileUtils.remove_dir($tool_folder)
puts
end
def download_tools
$TOOLS.each do |tool|
download_tool(tool)
end
end
def download_tool(tool)
fullpath = File.join($tool_folder, tool[:folder])
puts " • Installing #{tool[:name]} to '#{fullpath}'"
tool[:src].each { |src| download_file(src, fullpath) }
end
def download_file(src, dest)
filename = src.split('/')[-1]
FileUtils.mkdir_p(dest)
# Delete the downloaded file if it exists and we aren't caching
File.unlink(filename) if File.exist?(filename) && !$cache_downloads
unless File.exist?(filename)
puts " • Downloading #{src}"
# TODO: Check MD5 hashes here that are entered into tools.json
# TODO: Make this more portable
`curl --location -O -# #{src}`
end
# Copy or unzip the file to the destination
if src.end_with?('.zip')
# TODO: Make this portable
`unzip -d #{dest} #{filename}`
else
FileUtils.copy(filename, dest)
end
# Delete the downloaded file if it exists and we aren't caching
File.unlink(filename) if File.exist?(filename) && !$cache_downloads
end
def get_index_file_for_tool(tool)
return tool[:index] if tool[:index]
raise "Ambiguous index file for '#{tool[:name]}'" unless tool[:src].length == 1
return 'index.html' if tool[:src].first.end_with?('.zip')
tool[:src].first.split('/')[-1]
end
def tool_links
$TOOLS.group_by { |x| x[:category] }.map do |category, tools|
["<h2>#{category}</h2>"] +
tools.map do |tool|
index = get_index_file_for_tool(tool)
"<h3><a href='#{File.join(tool[:folder], index)}'>#{tool[:name]}</a></h3>"
end
end.join("\n")
end
def create_index
file = File.join($tool_folder, 'index.html')
puts " • Writing index file: #{file}"
html = $index_template.gsub('__TOOL_LINKS_HERE__', tool_links)
File.unlink(file) if File.exist?(file)
File.open(file, 'w') do |f|
f.write(html)
end
end
def print_instructions
file = File.join($tool_folder, 'index.html')
puts <<~INSTRUCTIONS
Done.
Copy the folder: '#{$tool_folder}' to your offline computer and open '#{file}'
To test on this computer browse to:
file://#{File.expand_path(file)}
INSTRUCTIONS
end
def print_header
puts '
____ _ _ ____ _ _
/ ___| ___ | | __| | / ___| _ _ (_)| |_ ___
| | / _ \ | | / _` | \___ \ | | | || || __|/ _ \
| |___( (_) )| |( (_| | ___) )| |_| || || |_( __/
\____|\___/ |_| \__,_| |____/ \__,_||_| \__|\___|
Curated cold storage and offline cryptocurrency tools
_______________________________________________________
Cold Suite will download various offline web based tools into a bundled package
you can move to an air-gapped computer for proper, safe cold storage purposes.
IMPORTANT: Please take a careful look at all the files in this repo, in
particular tools.json, to verify the source and trustworthiness of each tool and
the legitimacy of the code that packages them together!
'
end
install