Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemric committed Nov 26, 2023
1 parent 4d211f6 commit 92053e8
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions Update.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

jqverbose() {
if $verbose; then echo $1 | jq; fi;
if $verbose; then echo $1; echo $2 | jq; fi;
}

stream="stable"
Expand Down Expand Up @@ -42,52 +42,49 @@ while [ $# -gt 0 ]; do
shift
done

echo Looking for previous files
jqverbose "$(cat $history)"
jqverbose "Looking for previous files :" "$(cat $history)"

data="$streampath/$stream.json"
echo "Checking updates for $stream stream from : $data"

echo "Looking for $artifact $arch release"
data=$(curl --no-progress-meter $data | jq .architectures.$arch.artifacts.$artifact)
jqverbose "${data}"
jqverbose "Looking for $artifact $arch release :" "$data"

FCOSrelease=$(jq -n "$data" | jq --raw-output .release)
FCOSversion=$(jq --raw-output .$stream.$arch.$artifact.$format $history)

if [ "${FCOSversion}" = "null" ]; then FCOSversion=0; fi;

echo FCOSrelease: $FCOSrelease / FCOSversion: $FCOSversion
echo FCOS release: $FCOSrelease / FCOS version: $FCOSversion

if $(jq -n "$data" | jq --raw-output --arg version $FCOSversion '.release > $version')
if $(jq -n "$data" | jq --raw-output --arg version $FCOSversion '.release > $version') # Check for updates
then

echo "Looking for $format files"
downloads=$format.$artifact.$arch.$stream
files=$(jq -n "$data" | jq .formats.$format) #filtering $format files version
jqverbose "${files}"
jqverbose "Update found for $format files :" "$files"
filecounter=0

for file in $(jq -n "$files" | jq --raw-output 'keys[]') #downloading all files
do

let filecounter+=1
echo "Looking for file #$filecounter : $file"
filename="$file.$format.$artifact.$arch.$stream"
fileinfo=$(jq -n "$files" | jq .$file) #filtering each file informations
jqverbose "${fileinfo}"
jqverbose "#$filecounter $file :" "$fileinfo"

for try in {1..2} #let's try 2 times downloading with correct checksum
for try in {1..2} #let's try 2 times downloading with correct checksum/gpg
do

echo "Downloading $(jq -n "$fileinfo" | jq --raw-output .location) to $filename"
curl -C - --no-progress-meter --parallel \
-o $filename $(jq -n "$fileinfo" | jq --raw-output .location) \
-o $filename.sig $(jq -n "$fileinfo" | jq --raw-output .signature) #Downloading fileinfo.location and .signature

echo "Check sha256sum and GPG signature"
echo "Checking sha256sum and GPG signature"
if echo "$(jq -n "$fileinfo" | jq --raw-output .sha256) $filename" | sha256sum --check && gpg --verify $filename.sig
then
echo $filename >> $format.$artifact.$arch.$stream.part
echo $filename >> $downloads.part
rm $filename.sig
break
else
Expand All @@ -96,13 +93,12 @@ then
done
done

if [[ -f $format.$artifact.$arch.$stream.part ]] then
if [[ $(wc -l < $format.$artifact.$arch.$stream.part) == $filecounter ]]
then
mv $format.$artifact.$arch.$stream.part $format.$artifact.$arch.$stream
cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'$format' = $release' $history) > $history
fi
if [[ -f $downloads.part ]] && [[ $(wc -l < $downloads.part) == $filecounter ]]
then # All files wwas successfully downloaded and checked
mv $downloads.part $downloads
cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'$format' = $release' $history) > $history
fi

else
echo "Up to date, nothing to do"
fi

0 comments on commit 92053e8

Please sign in to comment.