From 7369be1c9f10ffbf973cf0f185148d88c2438815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Mon, 11 Mar 2024 18:46:40 +0100 Subject: [PATCH] Add auto update scripts --- .gitignore | 10 ++ auto_update/auto_update.sh | 176 ++++++++++++++++++++++ auto_update/auto_update_config_example.sh | 24 +++ 3 files changed, 210 insertions(+) create mode 100644 .gitignore create mode 100644 auto_update/auto_update.sh create mode 100644 auto_update/auto_update_config_example.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c3f96c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# From kateproject +.kateproject +.kateproject.d +.directory + +*swp + +auto_update_config.sh +auto_update/Synapse_build_*.log +auto_update/synapse_build_temp.log diff --git a/auto_update/auto_update.sh b/auto_update/auto_update.sh new file mode 100644 index 0000000..0c90dfc --- /dev/null +++ b/auto_update/auto_update.sh @@ -0,0 +1,176 @@ +#!/bin/bash + +set -eu + +readonly app_name=pgadmin + +source auto_update_config.sh + +readonly debian_version_name_1=bullseye +readonly debian_version_name_2=bookworm + +get_from_manifest() { + result=$(python3 <&1 | tee "${app_name}_build_temp.log" + return ${PIPESTATUS[0]} +} + +push_armv7_build() { + ## Make a draft release json with a markdown body + local release='"tag_name": "v'$app_version'", "target_commitish": "master", "name": "v'$app_version'", ' + local body="$app_name prebuilt bin for ${app_name}_ynh\\n=========\\nPlease refer to main PgAdmin project for the change : https://www.pgadmin.org/download/pgadmin-4-source-code\\n\\nSha256sum for $debian_version_name_1 : $(cat $build_result_path_deb_1/${result_prefix_name_deb_1}-bin1_armv7l-sha256.txt)\\nSha256sum for $debian_version_name_2 : $(cat $build_result_path_deb_2/${result_prefix_name_deb_2}-bin1_armv7l-sha256.txt)" + release+='"body": "'$body'",' + release+='"draft": true, "prerelease": false' + release='{'$release'}' + local url="https://api.github.com/repos/$owner/$repo/releases" + local succ=$(curl -H "Authorization: token $perstok" --data "$release" $url) + + ## In case of success, we upload a file + local upload_generic=$(echo "$succ" | grep upload_url) + if [[ $? -eq 0 ]]; then + echo "Release created." + else + echo "Error creating release!" + return 1 + fi + + local upload_prefix + local upload_file + local upload_ok + local download + for archive_name in $build_result_path_deb_1/${result_prefix_name_deb_1}-bin1_armv7l.tar.gz \ + $build_result_path_deb_2/${result_prefix_name_deb_2}-bin1_armv7l.tar.gz + do + + # $upload_generic is like: + # "upload_url": "https://uploads.github.com/repos/:owner/:repo/releases/:ID/assets{?name,label}", + upload_prefix=$(echo $upload_generic | cut -d "\"" -f4 | cut -d "{" -f1) + upload_file="$upload_prefix?name=${archive_name##*/}" + + echo "Start uploading file" + i=0 + upload_ok=false + while [ $i -le 4 ]; do + i=$((i+1)) + # Download file + set +e + succ=$(curl -H "Authorization: token $perstok" \ + -H "Content-Type: $(file -b --mime-type $archive_name)" \ + -H "Accept: application/vnd.github.v3+json" \ + --data-binary @$archive_name $upload_file) + res=$? + set -e + if [ $res -ne 0 ]; then + echo "Curl upload failled" + continue + fi + echo "Upload done, check result" + + set +eu + download=$(echo "$succ" | egrep -o "browser_download_url.+?") + res=$? + if [ $res -ne 0 ] || [ -z "$download" ]; then + set -eu + echo "Result upload error" + continue + fi + set -eu + echo "$download" | cut -d: -f2,3 | cut -d\" -f2 + echo "Upload OK" + upload_ok=true + break + done + + if ! $upload_ok; then + echo "Upload completely failed, exit" + return 1 + fi + done +} + +app_version=$(get_from_manifest ".version" | cut -d'~' -f1) + +if check_app_version +then + set +eu + upgrade_app + res=$? + set -eu + if [ $res -eq 0 ]; then + result="Success" + else + result="Failed" + fi + msg="Build: $app_name version $app_version\n" + msg+="$(cat ${app_name}_build_temp.log)" + echo -e "$msg" | mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "Autoupgrade $app_name : $result" "$notify_email" +fi diff --git a/auto_update/auto_update_config_example.sh b/auto_update/auto_update_config_example.sh new file mode 100644 index 0000000..74ca1b3 --- /dev/null +++ b/auto_update/auto_update_config_example.sh @@ -0,0 +1,24 @@ + +build_cmd_deb_1() { + pushd ~ + sudo /root/build_pgadmin_bin.sh $1 $2 --chroot-yes + popd + sudo chown app_upgrader ~/$2* +} +build_cmd_deb_2() { + local target_dir=~ + sudo chroot /mnt/bookworm_build /root/build_pgadmin_bin.sh $1 $2 --chroot-yes + sudo mv -t $target_dir /mnt/bookworm_build/$2* + sudo chown app_upgrader $target_dir/$2* +} + + +build_result_path_deb_1=~ +build_result_path_deb_2=~ + +notify_email="hello@world.tld" + +# For github arm release +owner="YunoHost-Apps" +repo="pgadmin_python_build" +perstok="kkk"