vsantos

vsantos / check_id3cli

Last active 1 day ago

Like 0

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

Revision 4159d1c17c9ad41b15271d5939471c316b045011

check_id3cli.sh Raw
1#!/usr/bin/env bash
2
3set -Eeuo pipefail
4
5REPO="atareao/id3cli"
6INSTALL_PATH="${PATH}/id3cli"
7VERSION_FILE="${PATH}/.id3cli_version"
8
9NTFY_SERVER="http://localhost:80"
10NTFY_TOPIC="${TOPIC}"
11NTFY_TOKEN_FILE="${PATH}/${TOKEN_FILE}"
12
13send_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
29current="$(cat "$VERSION_FILE" 2>/dev/null || echo '')"
30latest="$(curl -sf "https://api.github.com/repos/$REPO/releases/latest" \
31 | grep '"tag_name"' \
32 | cut -d'"' -f4)"
33
34if [[ -z "$latest" ]]; then
35 send_notification "id3cli: no s'ha pogut obtenir la versió de GitHub."
36 exit 1
37fi
38
39if [[ "$current" == "$latest" ]]; then
40 exit 0
41fi
42
43send_notification "id3cli: nova versió disponible ($latest). Compilant..."
44
45if 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."
61else
62 podman rmi rust:alpine 2>/dev/null || true
63 send_notification "id3cli: error durant la compilació de $latest."
64 exit 1
65fi