Files
mates 1eede74dc6 fix: odstranit emoji ze vsech souboru
Kompletne odstraneno:
- Emoji (smajliky, symboly, boxes, arrows) z README
- Emoji ze skriptu (sipky, symboly)
- Emoji z docker-compose (adresare)

Nahrano za:
- Textove alternativy (sipky -> '->', boxes -> '+', atd.)
- ASCII pouze kde to slo

Ciste vsechny 7 repo (overeno Python skriptem).
2026-08-02 08:50:13 +02:00

97 lines
2.8 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#
# update.sh - aktualizace systemu (apt update + upgrade) + restart pokud nutny
# + Telegram notifikace o vysledku.
#
# Spust jednou rucne: sudo bash update.sh
# Spust automaticky: systemd timer update-rpi.timer (kazdy patek 18:00)
#
# Konfigurace: /home/mates/.telegram.conf (nebo nastav TELEGRAM_BOT_TOKEN a TELEGRAM_CHAT_ID v env)
#
set -euo pipefail
# === KONFIGURACE ===
CONFIG_FILE="/home/mates/.telegram.conf"
USER_NAME="mates"
WORK_DIR="/home/$USER_NAME"
LOG_FILE="$WORK_DIR/update.log"
HOST=$(hostname)
RESTART_REQUIRED="/var/run/reboot-required"
# === TELEGRAM KONFIGURACE ===
if [[ -f "$CONFIG_FILE" ]]; then
# shellcheck disable=SC1090
source "$CONFIG_FILE"
fi
TELEGRAM_BOT_TOKEN="${TELEGRAM_BOT_TOKEN:-}"
TELEGRAM_CHAT_ID="${TELEGRAM_CHAT_ID:-}"
# === TELEGRAM HELPER ===
send_msg() {
local TEXT="$1"
if [[ -z "$TELEGRAM_BOT_TOKEN" || -z "$TELEGRAM_CHAT_ID" ]]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Telegram neni nakonfigurovan, preskakuji notifikaci" >> "$LOG_FILE"
return 0
fi
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d chat_id="${TELEGRAM_CHAT_ID}" \
-d text="$TEXT" \
-d parse_mode="Markdown" \
--max-time 10 \
--retry 3 > /dev/null || echo "[$(date '+%Y-%m-%d %H:%M:%S')] Telegram chyba" >> "$LOG_FILE"
}
# === PROMENNE ===
START_TIME=$(date +%s)
# === CHYBA HANDLER ===
on_error() {
local exit_code=$?
local end_time=$(date +%s)
local duration=$((end_time - START_TIME))
echo "[$(date '+%Y-%m-%d %H:%M:%S')] CHYBA: update.sh skončil s chybou (exit code $exit_code)" >> "$LOG_FILE"
send_msg " *[$HOST]* Aktualizace systému selhala (${duration}s).
Zkontroluj log:
\`$LOG_FILE\`"
exit "$exit_code"
}
trap on_error ERR
# === HLAVNI LOGIKA ===
echo "[$(date '+%Y-%m-%d %H:%M:%S')] === update.sh spusten ===" >> "$LOG_FILE"
# Notifikace o zacatku
send_msg " *[$HOST]* Spoustim aktualizaci systemu..."
# Aktualizace baliku
echo "[$(date '+%Y-%m-%d %H:%M:%S')] apt update..." >> "$LOG_FILE"
sudo apt-get update -qq 2>>"$LOG_FILE"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] apt upgrade..." >> "$LOG_FILE"
sudo apt-get upgrade -y -qq 2>>"$LOG_FILE"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] apt autoremove..." >> "$LOG_FILE"
sudo apt-get autoremove -y -qq 2>>"$LOG_FILE"
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# Restart?
if [[ -f "$RESTART_REQUIRED" ]]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Restart required" >> "$LOG_FILE"
send_msg " *[$HOST]* Aktualizace systemu dokoncena (${DURATION}s).
**Restart serveru je nutny!** Reboot bude proveden za 1 minutu."
# Naplanovany restart za 1 minutu (at muzes kanclovat)
sudo shutdown -r +1 "Systemovy restart po update"
else
send_msg " *[$HOST]* Aktualizace systemu dokoncena (${DURATION}s).
Restart nutny neni."
fi
echo "[$(date '+%Y-%m-%d %H:%M:%S')] === update.sh dokoncen (${DURATION}s) ===" >> "$LOG_FILE"
exit 0