mirror of
https://github.com/YunoHost-Apps/synapse_ynh.git
synced 2024-09-03 20:26:38 +02:00
Add auto update scripts
This commit is contained in:
parent
0dffaf60cf
commit
a78e6031a0
3 changed files with 194 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,3 +5,6 @@
|
|||
|
||||
*swp
|
||||
|
||||
auto_update_config.sh
|
||||
auto_update/Synapse_build_*.log
|
||||
auto_update/synapse_build_temp.log
|
||||
|
|
167
auto_update/auto_update.sh
Normal file
167
auto_update/auto_update.sh
Normal file
|
@ -0,0 +1,167 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
source auto_update_config.sh
|
||||
|
||||
readonly debian_version_name_1="bookworm"
|
||||
readonly debian_version_name_2="bullseye"
|
||||
|
||||
get_from_manifest() {
|
||||
result=$(python3 <<EOL
|
||||
import toml
|
||||
import json
|
||||
with open("../manifest.toml", "r") as f:
|
||||
file_content = f.read()
|
||||
loaded_toml = toml.loads(file_content)
|
||||
json_str = json.dumps(loaded_toml)
|
||||
print(json_str)
|
||||
EOL
|
||||
)
|
||||
echo $result | jq -r "$1"
|
||||
}
|
||||
|
||||
check_synapse() {
|
||||
synapse_remote_version=$(curl 'https://api.github.com/repos/element-hq/synapse/releases/latest' -H 'Host: api.github.com' --compressed | jq -r ".tag_name" | cut -dv -f2)
|
||||
|
||||
## Check if new build is needed
|
||||
if [[ "$synapse_version" != "$synapse_remote_version" ]]
|
||||
then
|
||||
synapse_version="$synapse_remote_version"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
upgrade_synapse() {
|
||||
(
|
||||
set -eu
|
||||
|
||||
# Define output file name
|
||||
# arm build: ${result_prefix_name_deb_1}-bin1_armv7l.tar.gz
|
||||
# arm build checksum: ${result_prefix_name_deb_1}-bin1_armv7l-sha256.txt
|
||||
# requirement.txt: ${result_prefix_name_deb_1}-build1_requirement.txt
|
||||
readonly result_prefix_name_deb_1="matrix-synapse_${synapse_version}-$debian_version_name_1"
|
||||
readonly result_prefix_name_deb_2="matrix-synapse_${synapse_version}-$debian_version_name_2"
|
||||
|
||||
# Build armv7 build
|
||||
build_cmd_deb_1 $synapse_version $result_prefix_name_deb_1
|
||||
build_cmd_deb_2 $synapse_version $result_prefix_name_deb_2
|
||||
push_armv7_build
|
||||
|
||||
# Update python requirement
|
||||
cp $build_result_path_deb_1/${result_prefix_name_deb_1}-build1_requirement.txt ../conf/requirement_$debian_version_name_1.txt
|
||||
cp $build_result_path_deb_2/${result_prefix_name_deb_2}-build1_requirement.txt ../conf/requirement_$debian_version_name_2.txt
|
||||
|
||||
# Update manifest
|
||||
sed -r -i 's|version = "[[:alnum:].]{4,8}~ynh1"|version = "'${synapse_version}'~ynh1"|' ../manifest.toml
|
||||
|
||||
# Update this link
|
||||
sed -r -i "s|arm.url\s*=(.*)/releases/download/v[[:alnum:].]{4,8}/matrix-synapse_[[:alnum:].]{4,8}-$debian_version_name_1-bin1_armv7l.tar.gz|arm.url =\1/releases/download/v${synapse_version}/matrix-synapse_${synapse_version}-$debian_version_name_1-bin1_armv7l.tar.gz|" ../manifest.toml
|
||||
sed -r -i "s|arm.url\s*=(.*)/releases/download/v[[:alnum:].]{4,8}/matrix-synapse_[[:alnum:].]{4,8}-$debian_version_name_2-bin1_armv7l.tar.gz|arm.url =\1/releases/download/v${synapse_version}/matrix-synapse_${synapse_version}-$debian_version_name_2-bin1_armv7l.tar.gz|" ../manifest.toml
|
||||
|
||||
# Update checksum
|
||||
sha256sum_arm_archive_deb_1=$(cat $build_result_path_deb_1/${result_prefix_name_deb_1}-bin1_armv7l-sha256.txt)
|
||||
sha256sum_arm_archive_deb_2=$(cat $build_result_path_deb_2/${result_prefix_name_deb_2}-bin1_armv7l-sha256.txt)
|
||||
prev_sha256sum_arm_archive_deb_1=$(get_from_manifest ".resources.sources.synapse_prebuilt_armv7_$debian_version_name_1.armhf.sha256")
|
||||
prev_sha256sum_arm_archive_deb_2=$(get_from_manifest ".resources.sources.synapse_prebuilt_armv7_$debian_version_name_2.armhf.sha256")
|
||||
sed -r -i "s|$prev_sha256sum_arm_archive_deb_1|$sha256sum_arm_archive_deb_1|" ../manifest.toml
|
||||
sed -r -i "s|$prev_sha256sum_arm_archive_deb_2|$sha256sum_arm_archive_deb_2|" ../manifest.toml
|
||||
|
||||
git commit -a -m "Upgrade synapse to $synapse_version"
|
||||
git push gitea auto_update:auto_update
|
||||
) 2>&1 | tee "synapse_build_temp.log"
|
||||
return ${PIPESTATUS[0]}
|
||||
}
|
||||
|
||||
push_armv7_build() {
|
||||
## Make a draft release json with a markdown body
|
||||
local release='"tag_name": "v'$synapse_version'", "target_commitish": "master", "name": "v'$synapse_version'", '
|
||||
local body="Synapse prebuilt bin for synapse_ynh\\n=========\\nPlease refer to upstream project for the change : https://github.com/element-hq/synapse/releases\\n\\nSha256sum for $debian_version_name_1 : $(cat $build_result_path_deb_1/SUM_matrix-synapse_${synapse_version}-$debian_version_name_1-bin1_armv7l.tar.gz)\\nSha256sum for $debian_version_name_2 : $(cat $build_result_path_deb_2/SUM_matrix-synapse_${synapse_version}-$debian_version_name_2-bin1_armv7l.tar.gz)"
|
||||
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
|
||||
}
|
||||
|
||||
synapse_version=$(get_from_manifest ".version" | cut -d'~' -f1)
|
||||
|
||||
if check_synapse
|
||||
then
|
||||
set +eu
|
||||
upgrade_synapse
|
||||
res=$?
|
||||
set -eu
|
||||
if [ $res -eq 0 ]; then
|
||||
result="Success"
|
||||
else
|
||||
result="Failed"
|
||||
fi
|
||||
msg="Build: synapse version $synapse_version\n"
|
||||
msg+="$(cat synapse_build_temp.log)"
|
||||
echo -e "$msg" | mail.mailutils -a "Content-Type: text/plain; charset=UTF-8" -s "Autoupgrade synapse : $result" "$notify_email"
|
||||
fi
|
24
auto_update/auto_update_config_example.sh
Normal file
24
auto_update/auto_update_config_example.sh
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
build_cmd_deb_1() {
|
||||
pushd ~
|
||||
sudo /root/build_synapse_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_synapse_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="synapse_python_build"
|
||||
perstok="kkk"
|
Loading…
Reference in a new issue