add ocenaudio
This commit is contained in:
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
: "${FILE:?FILE is required}"
|
||||
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
PYTHON_BIN=python
|
||||
elif command -v python3 >/dev/null 2>&1; then
|
||||
PYTHON_BIN=python3
|
||||
else
|
||||
echo "python is required but was not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_version=$($PYTHON_BIN - <<'PY'
|
||||
import re
|
||||
import os
|
||||
p=os.environ["FILE"]
|
||||
s=open(p).read()
|
||||
m=re.search(r'version\s*=\s*"([^"]+)";', s)
|
||||
print(m.group(1) if m else "")
|
||||
PY
|
||||
)
|
||||
|
||||
page=$(curl -fsSL https://www.ocenaudio.com/download)
|
||||
latest_version=$(printf '%s' "$page" | "$PYTHON_BIN" -c 'import re,sys; s=sys.stdin.read(); m=re.search(r"ocenaudio_debian12\.deb</p>\s*<p>Versão ([0-9.]+)</p>", s); print(m.group(1) if m else "")')
|
||||
|
||||
if [ -z "$latest_version" ]; then
|
||||
echo "failed to detect latest ocenaudio version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "current=$current_version"
|
||||
echo "latest=$latest_version"
|
||||
|
||||
if [ "$latest_version" = "$current_version" ]; then
|
||||
echo "updated=false" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
download_url="https://www.ocenaudio.com/downloads/index.php/ocenaudio_debian12.deb?version=v${latest_version}"
|
||||
new_hash=$(nix store prefetch-file --json "$download_url" | "$PYTHON_BIN" -c 'import json,sys; print(json.load(sys.stdin)["hash"])')
|
||||
|
||||
export LATEST_VERSION="$latest_version"
|
||||
export NEW_HASH="$new_hash"
|
||||
|
||||
"$PYTHON_BIN" - <<'PY'
|
||||
import os
|
||||
import re
|
||||
p=os.environ["FILE"]
|
||||
s=open(p).read()
|
||||
s=re.sub(r'version\s*=\s*"[^"]+";', f'version = "{os.environ["LATEST_VERSION"]}";', s, count=1)
|
||||
s=re.sub(r'hash\s*=\s*"[^"]+";', f'hash = "{os.environ["NEW_HASH"]}";', s, count=1)
|
||||
open(p, "w").write(s)
|
||||
PY
|
||||
|
||||
echo "updated=true" >> "$GITHUB_OUTPUT"
|
||||
echo "version=$latest_version" >> "$GITHUB_OUTPUT"
|
||||
echo "previous_version=$current_version" >> "$GITHUB_OUTPUT"
|
||||
echo "release_url=https://www.ocenaudio.com/changelog" >> "$GITHUB_OUTPUT"
|
||||
Reference in New Issue
Block a user