vsantos

vsantos / check_id3cli

Last active 1 day ago

Like 0

Script para la actualización automatica de la aplicación

vsantos revised this gist 1 day ago · 6a5c018

1 file changed, 1 insertion, 1 deletion

check_id3cli.sh
@@ -6,7 +6,7 @@ REPO="atareao/id3cli"
6 6 INSTALL_PATH="${PATH}/id3cli"
7 7 VERSION_FILE="${PATH}/.id3cli_version"
8 8
9 - NTFY_SERVER="http://localhost:80"
9 + NTFY_SERVER="https://ntfy.servidor.org"
10 10 NTFY_TOPIC="${TOPIC}"
11 11 NTFY_TOKEN_FILE="${PATH}/${TOKEN_FILE}"
12 12

vsantos revised this gist 1 day ago · 4159d1c

1 file changed, 65 insertions

check_id3cli.sh (file created)
@@ -0,0 +1,65 @@
1 + #!/usr/bin/env bash
2 +
3 + set -Eeuo pipefail
4 +
5 + REPO="atareao/id3cli"
6 + INSTALL_PATH="${PATH}/id3cli"
7 + VERSION_FILE="${PATH}/.id3cli_version"
8 +
9 + NTFY_SERVER="http://localhost:80"
10 + NTFY_TOPIC="${TOPIC}"
11 + NTFY_TOKEN_FILE="${PATH}/${TOKEN_FILE}"
12 +
13 + send_notification() {
14 + local message="$1"
15 + local token
16 +
17 + token="$(tr -d '\r\n' < "$NTFY_TOKEN_FILE" 2>/dev/null)" || return 1
18 + [[ -n "$token" ]] || return 1
19 +
20 + curl --fail --silent --show-error \
21 + -X POST \
22 + -H "Authorization: Bearer ${token}" \
23 + -H "Content-Type: text/plain; charset=utf-8" \
24 + -d "$message" \
25 + --output /dev/null \
26 + "${NTFY_SERVER%/}/${NTFY_TOPIC}" || true
27 + }
28 +
29 + current="$(cat "$VERSION_FILE" 2>/dev/null || echo '')"
30 + latest="$(curl -sf "https://api.github.com/repos/$REPO/releases/latest" \
31 + | grep '"tag_name"' \
32 + | cut -d'"' -f4)"
33 +
34 + if [[ -z "$latest" ]]; then
35 + send_notification "id3cli: no s'ha pogut obtenir la versió de GitHub."
36 + exit 1
37 + fi
38 +
39 + if [[ "$current" == "$latest" ]]; then
40 + exit 0
41 + fi
42 +
43 + send_notification "id3cli: nova versió disponible ($latest). Compilant..."
44 +
45 + if podman run --rm \
46 + -v /tmp:/output \
47 + rust:alpine \
48 + sh -c "apk add --no-cache git musl-dev && \
49 + git clone --branch $latest --depth 1 https://github.com/$REPO.git /src && \
50 + cd /src && \
51 + cargo build --release --target x86_64-unknown-linux-musl && \
52 + cp target/x86_64-unknown-linux-musl/release/id3cli /output/"; then
53 +
54 + podman rmi rust:alpine 2>/dev/null || true
55 +
56 + cp /tmp/id3cli "$INSTALL_PATH"
57 + chmod +x "$INSTALL_PATH"
58 + echo "$latest" > "$VERSION_FILE"
59 +
60 + send_notification "id3cli: actualitzat a $latest correctament."
61 + else
62 + podman rmi rust:alpine 2>/dev/null || true
63 + send_notification "id3cli: error durant la compilació de $latest."
64 + exit 1
65 + fi