1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grav_ynh.git synced 2024-09-03 19:16:01 +02:00
grav_ynh/.github/workflows/updater.sh

75 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
#############################
# PACKAGE UPDATING HELPER #
#############################
# This script is meant to be run by GitHub actions: check .github/workflows/updater.yml
# Since each app is different, maintainers can adapt its contents
# so as to perform automatic actions when a new upstream release is detected.
# The ASSETS environment variable is a space-separated list of urls
# of assets published with the latest upstream release.
# Let's convert it into an array.
eval "ASSETS=($ASSETS)"
echo "${#ASSETS[@]} available asset(s)"
# Let's loop over the array of assets URLs
for asset_url in ${ASSETS[@]}; do
2022-10-06 00:00:31 +02:00
echo "Handling asset at $asset_url"
2022-10-06 00:00:31 +02:00
# Assign the asset to a source file in conf/ directory
# Leave $src empty to ignore the asset
case $asset_url in
*"admin"*)
src="app"
;;
*"update"*)
src="app-upgrade"
;;
*)
src=""
;;
esac
2022-10-06 00:00:31 +02:00
# If $src is not empty, let's process the asset
if [ ! -z "$src" ]; then
2022-10-06 00:00:31 +02:00
# Create the temporary directory
tempdir="$(mktemp -d)"
2022-10-06 00:00:31 +02:00
# Download sources and calculate checksum
filename=${asset_url##*/}
curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
2022-10-06 00:00:31 +02:00
# Delete temporary directory
rm -rf $tempdir
2022-10-06 00:00:31 +02:00
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
2022-10-06 00:00:31 +02:00
# Rewrite source file
cat <<EOT > conf/$src.src
SOURCE_URL=$asset_url
SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true
2022-10-06 00:00:31 +02:00
SOURCE_FILENAME=
SOURCE_EXTRACT=true
EOT
2022-10-06 00:00:31 +02:00
echo "... conf/$src.src updated"
2022-10-06 00:00:31 +02:00
else
echo "... asset ignored"
fi
done
echo "Done!"