From 4d211f68e8aba12127823ab4ff7c2f865eef1e2c Mon Sep 17 00:00:00 2001 From: Nemric <56299157+Nemric@users.noreply.github.com> Date: Sun, 26 Nov 2023 13:08:35 +0100 Subject: [PATCH] Too much changes for a commit --- Jenkinsfile | 6 ++++-- README.md | 5 +++-- Update.sh | 26 +++++++++++++++----------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 82823fe..65886f6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +def updated = false; + pipeline { triggers { cron(env.BRANCH_NAME == 'main' ? 'H H * * 4' : '') @@ -120,7 +122,7 @@ pipeline { echo uploading $FORMAT.$ARTIFACT.$ARCH.$STREAM files scp $files jenkins@$ARTEFACTS_SERVER:/media/img/coreos/ ''' - sh 'touch updated' + script { updated = true } } } } @@ -129,7 +131,7 @@ pipeline { } stage("Upload versions update") { - when { expression { fileExists('updated') } } + when { expression { updated == true } } steps { sshagent(credentials: ['Jenkins-Key']) { sh ''' diff --git a/README.md b/README.md index bb0ba53..3025f4d 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,12 @@ Options are, space delimited : (e.g.: `./Update.sh -v true`) - `-s` or `--stream` usually: stable, testing or next -> défault : `stable` - `-a` or `--arch` usually: aarch64, ppc64le, s390x, x86_64 -> default: `x86_64` - `-t` or `--artifact` ouch ! aliyun, aws, azure, azurestack, digitalocean, exoscale, gcp, hyperv, ibmcloud, kubevirt, metal, nutanix, openstack, qemu, irtualbox, vmware, vultr... and so on depending previous choices -> default : `metal` -- `-f` or `--format`Arrgh ! Really depending of previous choices -> default : `pxe` +- `-f` or `--format` Arrgh ! Really depending of previous choices -> default : `pxe` - `-v` or `--verbose` If ever you want to see well formatted json output -> default : `false` -- `-h` or `--history`default file path to `coreos.json` that must at least contains `{}`data, there's no error check for this option ! +- `-h` or `--history` default file path to `coreos.json` that must at least contains `{}` data, there's no error check for this option ! It will ouput artefacts, GPG and SHASUM checked, and a file named as `$format.$artifact.$arch.$stream` that contains the list of downloaded files for later use .. or not + `coreos.json`/`--history` file will be updated with version number from released/downloaded artefacts to remember last updates ## Jenkinsfile diff --git a/Update.sh b/Update.sh index 3f8b438..835ce0d 100755 --- a/Update.sh +++ b/Update.sh @@ -59,46 +59,50 @@ 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" files=$(jq -n "$data" | jq .formats.$format) #filtering $format files version jqverbose "${files}" + filecounter=0 + for file in $(jq -n "$files" | jq --raw-output 'keys[]') #downloading all files do - echo "Looking for $file" + 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}" for try in {1..2} #let's try 2 times downloading with correct checksum 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" if echo "$(jq -n "$fileinfo" | jq --raw-output .sha256) $filename" | sha256sum --check && gpg --verify $filename.sig then - echo $filename >> $format.$artifact.$arch.$stream + echo $filename >> $format.$artifact.$arch.$stream.part + rm $filename.sig break else rm $filename $filename.sig fi - - if [ try == 2 ]; then failed=true; fi; - done done - if ! $failed - then - cat <<< $(jq --arg release $FCOSrelease '.'$stream'.'$arch'.'$artifact'.'$format' = $release' $history) > $history + 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 fi - else echo "Up to date, nothing to do" fi \ No newline at end of file