1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jellyfin_ynh.git synced 2024-09-03 19:26:29 +02:00

rewrite update_version.sh in python for toml

This commit is contained in:
Salamandar 2023-10-16 14:40:58 +02:00 committed by Salamandar
parent 5817fbc1a3
commit fdeec614b2
2 changed files with 80 additions and 87 deletions

80
scripts/update_version.py Executable file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env python3
from pathlib import Path
import tomlkit
import requests
REPO_ROOT = Path(__file__).parent.parent
JELLYFIN_REPO = "https://repo.jellyfin.org/releases/server/debian"
ARCHS = [
"armhf",
"arm64",
"amd64",
]
DEBS = [
"buster",
"bullseye",
"bookworm",
]
def version_from__common_sh(name: str) -> str:
content = (REPO_ROOT/"scripts"/"_common.sh").open(encoding="utf-8").readlines()
result = next(filter(lambda line: line.startswith(f"{name}="), content))
return result.split('"')[1]
def server_url(arch: str, version: str) -> str:
version_simple = version.split("-")[0]
return f"{JELLYFIN_REPO}/versions/stable/server/{version_simple}/jellyfin-server_{version}_{arch}.deb"
def web_url(arch: str, version: str) -> str:
version_simple = version.split("-")[0]
return f"{JELLYFIN_REPO}/versions/stable/web/{version_simple}/jellyfin-web_{version}_all.deb"
def ffmpeg_url(arch: str, deb: str, version: str) -> str:
major = version.split(".")[0]
return f"{JELLYFIN_REPO}/versions/jellyfin-ffmpeg/{version}/jellyfin-ffmpeg{major}_{version}-{deb}_{arch}.deb"
def sha256sum_of(url: str) -> str:
result = requests.get(f"{url}.sha256sum", timeout=10)
content = result.content.decode("utf-8")
return content.split(" ")[0]
def main() -> None:
manifest_file = REPO_ROOT/"manifest.toml"
manifest = tomlkit.parse(manifest_file.open(encoding="utf-8").read())
jellyfin_version = version_from__common_sh("pkg_version")
ffmpeg_version = version_from__common_sh("ffmpeg_pkg_version")
ldap_version = version_from__common_sh("ldap_pkg_version")
for arch in ARCHS:
url = server_url(arch, jellyfin_version)
manifest["resources"]["sources"]["server"][arch]["url"] = url
manifest["resources"]["sources"]["server"][arch]["sha256"] = sha256sum_of(url)
url = web_url(arch, jellyfin_version)
manifest["resources"]["sources"]["web"]["url"] = url
manifest["resources"]["sources"]["web"]["sha256"] = sha256sum_of(url)
for arch in ARCHS:
for deb in DEBS:
url = ffmpeg_url(arch, deb, ffmpeg_version)
manifest["resources"]["sources"][f"ffmpeg_{deb}"][arch]["url"] = url
manifest["resources"]["sources"][f"ffmpeg_{deb}"][arch]["sha256"] = sha256sum_of(url)
manifest_file.open("w", encoding="utf-8").write(tomlkit.dumps(manifest))
if __name__ == "__main__":
main()

View file

@ -1,87 +0,0 @@
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# META HELPER FOR PACKAGE RELEASES
#=================================================
# This script is meant to be manually run by the app packagers
# to automatically update the source files.
# Edit version numbers in _common.sh before running the script.
prepare_source () {
# Declare an array to define the options of this helper.
local legacy_args=tda
local -A args_array=( [t]=template= [d]=destination= [a]=architecture= )
local template
local destination
local architecture
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
local template_path
if [ -f "../conf/$template" ]; then
template_path="../conf/$template"
elif [ -f "../settings/conf/$template" ]; then
template_path="../settings/conf/$template"
elif [ -f "$template" ]; then
template_path=$template
else
ynh_die --message="The provided template $template doesn't exist"
fi
cp "$template_path" "$destination"
ynh_replace_vars --file="$destination"
local official_checksum
local official_checksum_url
local filename
local checksum
local url
# Create the temporary directory
tempdir="$(mktemp -d)"
url=$(grep "SOURCE_URL=" "$destination" | cut -d "=" -f 2)
echo $url
filename=${url##*/}
echo $filename
curl -s -4 -L $url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
ynh_secure_remove $tempdir
official_checksum_url=$(grep "SOURCE_SUM=" "$destination" | cut -d "=" -f 2)
if [[ "$official_checksum_url" != "none" ]]; then
official_checksum=$(curl -L -s "${official_checksum_url}" | cut -d ' ' -f 1)
echo $official_checksum
fi
if [[ "$official_checksum_url" != "none" && "$official_checksum" != "$checksum" ]]; then
echo "Downloaded file checksum ($checksum) does not match official checksum ($official_checksum)"
exit 1
else
sed -i "s/SOURCE_SUM=.*/SOURCE_SUM=${checksum}/" "$destination"
echo "$destination updated"
fi
}
debians=("buster" "bullseye")
architectures=("amd64" "arm64" "armhf")
for debian in "${debians[@]}"; do
for architecture in "${architectures[@]}"; do
prepare_source --template="../conf/ffmpeg.src.default" --destination="../conf/ffmpeg.$debian.$architecture.src" --architecture="$architecture"
prepare_source --template="../conf/web.src.default" --destination="../conf/web.$debian.$architecture.src" --architecture="$architecture"
prepare_source --template="../conf/server.src.default" --destination="../conf/server.$debian.$architecture.src" --architecture="$architecture"
done
done
prepare_source --template="../conf/ldap.src.default" --destination="../conf/ldap.src"
sed -i "s# \"version\": \".*# \"version\": \"${version}\~ynh1\",#" ../manifest.json
git add _common.sh ../manifest.json ../conf/ffmpeg.*.src ../conf/web.*.src ../conf/server.*.src ../conf/ldap.src
git commit -m "Upgrade to v$version"