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
|
# File 'lib/disk.rb', line 7
def self.download_debian_netinstall
susi_dir = File.expand_path("~/.susi")
Dir.mkdir(susi_dir) unless Dir.exist?(susi_dir)
iso_dir = File.join(susi_dir, "iso")
Dir.mkdir(iso_dir) unless Dir.exist?(iso_dir)
output_path = File.join(iso_dir, DEFAULT_IMG)
url = "https://mirrors.tuna.tsinghua.edu.cn/debian-cd/current/amd64/iso-cd/#{DEFAULT_IMG}"
Susi::debug "Downloading Debian netinstall ISO..."
begin
URI.open(url) do |remote_file|
File.open(output_path, "wb") do |local_file|
local_file.write(remote_file.read)
end
end
Susi::debug "Download completed successfully."
rescue OpenURI::HTTPError => e
Susi::debug "Error downloading the ISO: #{e.message}"
rescue SocketError => e
Susi::debug "Network error: #{e.message}"
rescue => e
Susi::debug "An unexpected error occurred: #{e.message}"
end
end
|