/
NewestISO
executable file
·85 lines (73 loc) · 1.32 KB
/
NewestISO
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
#! /usr/pkg/bin/ruby200
# $Id: $
require 'net/ftp'
FTP="nyftp.netbsd.org"
CDN="nycdn.netbsd.org"
#FTP="ftp.jp.netbsd.org"
#FTP="ftp7.jp.netbsd.org"
BRANCH="/pub/NetBSD-daily/HEAD/"
IMAGES="/usr/release/images/"
ARCH="earmv7hf"
#ARCH="earm"
class ISO
def initialize(list)
@iso = list
@path= nil
end
def check(path,arch)
l = @iso
while f=l.shift
if /#{arch}.iso/ =~ f
@path = path+f
return path+f
end
end
return nil
end
def print
p @iso
end
def path
return @path
end
def date
return (@path.scan(/[0-9]+Z/))[0]
end
def body
return (@path.scan(/NetBSD-[0-9]+.*.iso/))[0].sub(".iso","")
end
end
ftp = Net::FTP.open(FTP) do |ftp|
# login and set mode
ftp.login()
ftp.passive = TRUE
# ftp.debug_mode = TRUE
# chdir to branch
ftp.chdir(BRANCH)
# Get Daily build list
list=((ftp.nlst()).select{|s| /^[0-9][0-9][0-9]/ =~ s }).sort
# Check most recent image
while s=list.pop
# is image dir?
image=BRANCH+s+"/images/"
begin
path=ftp.chdir(image)
rescue Net::FTPPermError
next
end
# is ARCH iso?
begin
isofile=ISO.new(ftp.nlst())
if isofile.check(image,ARCH)
break
else
next
end
rescue Net::FTPTempError
next
end
end
puts "ftp http://"+CDN+isofile.path
puts "mv "+isofile.body+".iso "+IMAGES+isofile.body+"-"+isofile.date+".iso"
ftp.quit
end