-
Notifications
You must be signed in to change notification settings - Fork 1
/
mksnapidx.awk
178 lines (158 loc) · 5.15 KB
/
mksnapidx.awk
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#
# Copyright 2018 John-Mark Gurney.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id$
#
BEGIN {
vmroot = "https://download.freebsd.org/ftp/snapshots/VM-IMAGES/"
isoroot = "https://download.freebsd.org/ftp/snapshots/ISO-IMAGES/"
relvmroot = "https://download.freebsd.org/ftp/releases/VM-IMAGES/"
relisoroot = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/"
}
tolower($1) == "message-id:" {
MID=$2
sub(".*<", "", MID)
sub(">.*", "", MID)
}
$0 == "== ISO CHECKSUMS ==" ||
$0 == "ISO Image Checksums" {
type = "iso"
}
$0 == "== VM IMAGE CHECKSUMS ==" ||
$0 == "Virtual Machine Disk Image Checksums" {
type = "vm"
}
function isdate(date) {
m = match(date, "[0-9]+")
if (m && RLENGTH == 8)
return 1
return 0
}
function isrelease(relpart) {
if (index(relpart, "BETA") == 1 || index(relpart, "RC") == 1 ||
index(relpart, "RELEASE") == 1)
return 1
return 0
}
#FreeBSD-13.0-CURRENT-powerpc-powerpcspe-20181026-r339752-bootonly.iso
#FreeBSD-13.0-CURRENT-sparc64-20181026-r339752-bootonly.iso.asc
#FreeBSD-13.0-CURRENT-arm64-aarch64-PINE64-LTS-20181026-r339752.img.xz
#FreeBSD-13.0-CURRENT-i386-20181026-r339752.vmdk.xz
#FreeBSD-12.1-BETA3-amd64-mini-memstick.img.xz
#FreeBSD-12.1-RC1-amd64-mini-memstick.img.xz
#FreeBSD-12.1-RELEASE-arm64-aarch64.vmdk.xz
$1 == "SHA512" {
# Strip parens
fname = substr($2, 2, length($2) - 2)
split(fname, dotparts, ".")
# recombine around dot in version, strips off ALL extensions (including vm type)
basename = dotparts[1] "." dotparts[2]
cnt = split(basename, parts, "-")
# make arch part, may include additional part
arch = parts[4]
basearch = arch
if (parts[4] == "arm" ||
(parts[4] == "powerpc" && parts[5] == "powerpcspe") ||
(parts[4] == "powerpc" && parts[5] == "powerpc64") ||
parts[4] == "arm64") {
# FreeBSD-11.3-STABLE-arm64-aarch64-20191011-r353406-memstick.img
basearch = parts[5]
arch = parts[4] "-" parts[5]
nextidx = 6
} else {
# FreeBSD-11.3-STABLE-amd64-20191011-r353406.qcow2.xz
nextidx = 5
}
# find date, may be platform first
if (isrelease(parts[3])) {
if (nextidx > cnt) {
# FreeBSD-12.1-BETA3-i386.vhd.xz
platform = "xxx"
} else if (cnt == nextidx) {
# FreeBSD-12.1-RC1-powerpc-powerpcspe-dvd1.iso
platform = parts[nextidx]
nextidx += 1
} else {
# FreeBSD-12.1-BETA3-amd64-mini-memstick.img.xz
platform = parts[nextidx] "-" parts[nextidx + 1]
nextidx += 2
}
date = "xxx"
} else if (isdate(parts[nextidx])) {
# FreeBSD-11.3-STABLE-amd64-20191011-r353406.qcow2.xz
platform = "xxx"
date = parts[nextidx]
nextidx += 1
} else {
# FreeBSD-13.0-CURRENT-arm64-aarch64-PINE64-LTS-20181026-r339752.img.xz
platform = parts[nextidx]
date = parts[nextidx + 1]
if (isdate(date)) {
# FreeBSD-13.0-CURRENT-arm64-aarch64-PINEBOOK-20191011-r353427.img.xz
nextidx += 2
} else {
# FreeBSD-13.0-CURRENT-arm64-aarch64-PINE64-LTS-20181026-r339752.img.xz
date = parts[nextidx + 2]
platform = parts[nextidx] "-" parts[nextidx + 1]
nextidx += 3
}
}
if (nextidx >= cnt)
vers="xxx"
else {
vers=""
sep=""
for (i = nextidx + 1; i <= cnt; i++) {
vers = vers sep parts[i]
sep="-"
}
}
if (isrelease(parts[3])) {
if (type == "vm") {
vers = dotparts[3]
url = relvmroot parts[2] "-" parts[3] "/" basearch "/Latest/" fname
} else
url = relisoroot parts[2] "/" fname
} else {
if (type == "vm") {
vers = dotparts[3]
url = vmroot parts[2] "-" parts[3] "/" basearch "/" date "/" fname
} else
url = isoroot parts[2] "/" fname
}
# if this part doesn't begin w/ r (for svn rev), skip it, we can't parse
# others for now
rev = parts[nextidx]
if (isrelease(parts[3])) {
# FreeBSD-12.1-RC1-amd64-mini-memstick.img.xz
rev = "unspec"
} else if (substr(rev, 1, 1) != "r") {
next
}
# double check that date is valid, if not, skip it
if (date != "xxx" && !isdate(date))
next
printf("%s %s %s %s %s %s %s %s %s %s\n", type, parts[2] "-" parts[3], arch, platform, date, rev, vers, fname, url, MID)
}