From 6b79c0a4ee2eca6e296fdaef2bca9b303dafc19f Mon Sep 17 00:00:00 2001 From: Nemric <56299157+Nemric@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:24:23 +0100 Subject: [PATCH] Make it more strong --- Jenkinsfile | 9 +++++---- Update.sh | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7bfca98..c3d2300 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -107,19 +107,20 @@ pipeline { steps { sh ''' ./Update.sh --stream $STREAM --arch $ARCH --artifact $ARTIFACT --format $FORMAT --verbose true - if ls *.$STREAM; then touch updated; fi; ''' } } stage("Upload Files") { - when { expression { fileExists('updated') } } + when { expression { fileExists('$FORMAT.$ARTIFACT.$ARCH.$STREAM') } } steps { sshagent(credentials: ['Jenkins-Key']) { sh ''' - echo uploading *.$STREAM files - scp *.$STREAM jenkins@$ARTEFACTS_SERVER:/media/img/coreos/ + files=$(cat $FORMAT.$ARTIFACT.$ARCH.$STREAM) + echo uploading $FORMAT.$ARTIFACT.$ARCH.$STREAM files + scp $files jenkins@$ARTEFACTS_SERVER:/media/img/coreos/ ''' + sh 'touch updated' } } } diff --git a/Update.sh b/Update.sh index 3664d47..1c95e19 100755 --- a/Update.sh +++ b/Update.sh @@ -8,7 +8,7 @@ stream="stable" arch="x86_64" artifact="metal" format="pxe" -versions='coreos.json' +history='coreos.json' streampath='https://builds.coreos.fedoraproject.org/streams' verbose=false @@ -29,6 +29,9 @@ while [ $# -gt 0 ]; do -v|--verbose) verbose="$2" ;; + -h|--history) + history="$2" + ;; *) printf "***************************\n" printf "* Error: Invalid argument.*\n" @@ -38,8 +41,9 @@ while [ $# -gt 0 ]; do shift shift done + echo Looking for previous files -jqverbose "$(cat $versions)" +jqverbose "$(cat $history)" data="$streampath/$stream.json" echo "Checking updates for $stream stream from : $data" @@ -49,15 +53,14 @@ data=$(curl --no-progress-meter $data | jq .architectures.$arch.artifacts.$artif jqverbose "${data}" FCOSrelease=$(jq -n "$data" | jq --raw-output .release) -FCOSversion=$(jq --raw-output .$stream.$arch.$artifact.$format $versions) +FCOSversion=$(jq --raw-output .$stream.$arch.$artifact.$format $history) -if [ "${FCOSversion}" = "null" ] -then - FCOSversion=0 -fi +if [ "${FCOSversion}" = "null" ]; then FCOSversion=0; fi; echo FCOSrelease: $FCOSrelease / FCOSversion: $FCOSversion +failed=false + if $(jq -n "$data" | jq --raw-output --arg version $FCOSversion '.release > $version') then echo "Looking for $format files" @@ -80,13 +83,21 @@ then echo "Check 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 break else rm $filename $filename.sig fi + failed=true + done done - cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'$format' = $release' $versions) > $versions + + if ! $failed + then + cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'$format' = $release' $history) > $history + fi + else echo "Up to date, nothing to do" fi \ No newline at end of file