forked from cockpit-project/hubbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-publish-images
executable file
·110 lines (91 loc) · 2.63 KB
/
vm-publish-images
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
#!/bin/bash
# -*- coding: utf-8 -*-
#
# This file is part of Hubbot.
#
# Copyright (C) 2015 Red Hat, Inc.
#
# Hubbot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hubbot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hubbot. If not, see <http://www.gnu.org/licenses/>
SELF=vm-publish-images
targetdir=/srv/testdata/images
TEST_DATA=${TEST_DATA:-$PWD}
set -eu
publishable () {
[ -f "$1" ] && (echo $1 | grep -q -v rhel-7)
}
make_sum() {
sha512sum "$1" | while read sum file; do
echo $sum
done
}
# Build an index in the virt-builder format
index_lines() {
echo "$1" | sed -n 's/^\(.\+\)-\([^-]\+\)-\([0-9]\+\)\.\([^.]\+\)$/\1 \2 \3 \4/p' |
while read name arch release format; do
case "$format" in
img)
format=raw
;;
qcow2)
;;
*)
continue
;;
esac
sum="$(make_sum "$targetdir/$2")"
printf "[%s-%s]\nname=%s\n" $name $release $name
printf "arch=%s\n" $arch
printf "file=%s\n" "$2"
printf "checksum=%s\n" "$sum"
printf "format=%s\n" $format
printf "size=%s\n" $(stat --printf="%s" "$1")
printf "compressed_size=%s\n" $(stat --printf="%s" "$targetdir/$2")
printf "\n"
done
}
maybe_publish () {
checksum_file=$1
cat "$checksum_file" | while read sum file; do
if [ ! -f "$targetdir/$file.xz" ]; then
echo Publishing $file
pv "$file" | xz -ze >"$targetdir/$file.xz"
fi
cp "$checksum_file" "$targetdir/$checksum_file"
index_lines $file $file.xz >> "$targetdir/index"
done
}
maybe_unpublish () {
checksum_file=$1
if [ -f "$TEST_DATA/images/$checksum_file" ]; then
return
fi
cat "$checksum_file" | while read sum file; do
echo Unpublishing $file
rm $file.xz
done
rm "$checksum_file"
}
cd "$TEST_DATA/images"
rm -f "$targetdir/index"
for f in *-checksum; do
if publishable "$f"; then
maybe_publish "$f"
fi
done
cd "$targetdir"
for f in *-checksum; do
if publishable "$f"; then
maybe_unpublish "$f"
fi
done