-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate.sh
More file actions
executable file
·108 lines (91 loc) · 3.53 KB
/
Update.sh
File metadata and controls
executable file
·108 lines (91 loc) · 3.53 KB
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
#!/bin/bash
set -euo pipefail
function jqverbose { if $verbose; then echo $1; echo $2 | jq; fi; }
stream="stable"
arch="x86_64"
artifact="metal"
format="pxe"
history='coreos.json'
streampath='https://builds.coreos.fedoraproject.org/streams'
verbose=false
while [ $# -gt 0 ]; do
case "$1" in
-s|--stream)
stream="$2"
;;
-a|--arch)
arch="$2"
;;
-t|--artifact)
artifact="$2"
;;
-f|--format)
format="$2"
;;
-v|--verbose)
verbose="$2"
;;
-h|--history)
history="$2"
;;
*)
printf "Error: Invalid argument : $1 \n"
exit 1
esac
shift 2
done
jqverbose "Looking for previous files :" "$(cat $history)"
data="$streampath/$stream.json"
echo "Checking $stream stream updates from : $data"
data=$(curl --no-progress-meter $data | jq .architectures.$arch.artifacts.$artifact) # Downloading and then Filtering Arch & Artifatct
jqverbose "Looking for $arch $artifact release :" "$data"
FCOSrelease=$(echo $data | jq --raw-output .release) # Filtering new release version
FCOSversion=$(jq --raw-output .$stream.$arch.$artifact.\"$format\" $history) # Filtering current/last local version
if [ "${FCOSversion}" = "null" ]; then FCOSversion=0; fi; # If no previous version was found, set it to 0 for later comparison
echo FCOS $arch $artifact release : $FCOSrelease / version : $FCOSversion
if $(echo $data | jq --raw-output --arg version $FCOSversion '.release > $version') # Check for updates
then
filecounter=0
downloads=$format.$artifact.$arch.$stream
touch $downloads.part
truncate -s 0 $downloads.part
files=$(echo $data | jq .formats.\"$format\") # Filtering $format files version
jqverbose "Update found for $format files :" "$files"
for file in $(echo $files | jq --raw-output 'keys[]') # For each file definition
do
let filecounter+=1
filename="$file.$format.$artifact.$arch.$stream"
fileinfo=$(echo $files | jq .$file) # Filtering file informations
jqverbose "#$filecounter $file :" "$fileinfo"
for try in {1..2} # Let's try 2 times downloading with correct checksum/gpg
do
upstreamfile=$(echo $fileinfo | jq --raw-output .location) # Filtering upstream file location
upstreamsig=$(echo $fileinfo | jq --raw-output .signature) # Filtering upstream file signature
upstreamsha256=$(echo $fileinfo | jq --raw-output .sha256) # Filtering upstream sha256 sum
echo "Downloading $upstreamfile to $filename"
curl -C - --no-progress-meter --parallel \
$upstreamfile -o $filename \
$upstreamsig -o $filename.sig # Downloading file and its signature
echo "Checking sha256sum and GPG signature"
if echo "$upstreamsha256 $filename" | sha256sum --check && gpg --verify $filename.sig
then # GPG & SHASUM are ok
echo $filename >> $downloads.part # Add downloaded file to history
rm $filename.sig # Del signature file that is not needed anymore
break
else
rm $filename $filename.sig # Restart from beginning
fi
done # End for try
done # End for file
if [[ -f $downloads.part ]] && [[ $(wc -l < $downloads.part) == $filecounter ]]
then # All files were successfully downloaded and checked
mv $downloads.part $downloads
cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'\"$format\"' = $release' $history) > $history # Updating history file
jqverbose "Updated versions :" "$(cat $history)"
else
echo "Something went wrong :/"
rm $downloads.part
fi
else
echo "Up to date, nothing to do"
fi