NEWS
Test 'Universelles Update-Skipt / Systempflege'
-
Ich hab mal (mit ein wenig Support seitens der KI 'Le Chat Mistral') ein generelles Update-Skript gebastelt.
Den nachfolgenden Code auf dem System abspeichern und ausführbar machen.Das Skript deckt
- Paketupdates einer Debian-Installation ab (aber keine Dist-Upgrades/Release-Wechsel!) inkl. nodejs-Updates innerhalb einer Major-Version (aber keine Wechsel der Hauptversion oder Reparaturen daran)
- Updates des js-controllers (Das muss am intensivsten getestet werden!)
- ioBroker-Adapter-Updates
ab .
Bitte NICHT auf Produktiv-Systemen testen, nur auf ausdrücklichen Test-Systemen, bei denen es 'egal' ist, wenn die über den Jordan gehen.
#!/usr/bin/env bash # Clear screen clear # Check if 'nc' (netcat) is available if ! command -v nc &> /dev/null; then printf "${RED}Error: 'nc' (netcat) is not installed. Please install it with 'sudo apt-get install netcat-openbsd'.${NC}\n" exit 1 fi # Define colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to display a progress bar progress_bar() { local duration=${1} local columns=$(tput cols) local progress_width=$((columns - 10)) local increment=$((duration * 100 / progress_width)) local progress=0 printf " [" for ((i=0; i<progress_width; i++)); do if [ $((i * increment)) -ge $((progress * duration / 100)) ]; then printf "=" progress=$((progress + 1)) else printf " " fi done printf "] %d%%" $progress printf "\r" } # Function to stop ioBroker with timeout and progress bar stop_iobroker() { printf "${YELLOW}Stopping ioBroker...${NC}\n" iobroker stop & local pid=$! local timeout=60 local elapsed=0 local progress=0 # Show progress bar while waiting while kill -0 $pid 2>/dev/null && [ $elapsed -lt $timeout ]; do progress=$((elapsed * 100 / timeout)) printf " [" for ((i=0; i<20; i++)); do if [ $i -lt $((progress / 5)) ]; then printf "=" else printf " " fi done printf "] %d%%" $progress printf "\r" sleep 1 elapsed=$((elapsed + 1)) done printf "\n" if [ $elapsed -ge $timeout ]; then printf "${RED}Timeout: ioBroker did not stop within $timeout seconds.${NC}\n" kill -9 $pid 2>/dev/null return 1 fi # Verify that js-controller is really stopped if ! wait_for_js_controller_stop; then return 1 fi return 0 } # Function to wait until js-controller is fully stopped wait_for_js_controller_stop() { printf "${YELLOW}Waiting until js-controller is fully stopped..." local timeout=120 local elapsed=0 while pgrep -f "iobroker.js-controller" > /dev/null; do if [ $elapsed -ge $timeout ]; then printf "\n${RED}Timeout: js-controller did not stop within $timeout seconds.${NC}\n" return 1 fi printf "." sleep 1 elapsed=$((elapsed + 1)) done printf "${GREEN} Done.${NC}\n" return 0 } # Function to wait until js-controller is fully started wait_for_js_controller_start() { printf "${YELLOW}Waiting until js-controller is fully started..." local timeout=120 local elapsed=0 while ! pgrep -f "iobroker.js-controller" > /dev/null; do if [ $elapsed -ge $timeout ]; then printf "\n${RED}Timeout: js-controller did not start within $timeout seconds.${NC}\n" return 1 fi printf "." sleep 1 elapsed=$((elapsed + 1)) done # Wait until js-controller is reachable on port 8081 elapsed=0 while ! nc -z localhost 8081; do if [ $elapsed -ge $timeout ]; then printf "\n${RED}Timeout: js-controller did not become reachable within $timeout seconds.${NC}\n" return 1 fi printf "." sleep 1 elapsed=$((elapsed + 1)) done printf "${GREEN} Done.${NC}\n" return 0 } # Header printf "${BLUE}=============================================================================${NC}\n" printf "${BLUE}=== System Update Script ===${NC}\n" printf "${BLUE}=============================================================================${NC}\n" echo "" # 1. Update package lists printf "${YELLOW}1. Updating package lists...${NC}\n" if ! sudo apt-get update -y; then printf "${RED}Error: Failed to update package lists.${NC}\n" exit 1 fi printf "${GREEN}Done.${NC}\n" echo "" # Check if nodejs needs to be updated nodejs_update=false if sudo apt-get --dry-run upgrade | grep -q "nodejs"; then nodejs_update=true fi # If nodejs needs to be updated, stop ioBroker if [ "$nodejs_update" = true ]; then if ! stop_iobroker; then printf "${RED}Error: Failed to stop ioBroker properly.${NC}\n" exit 1 fi fi # 2. Perform system upgrade printf "${YELLOW}2. Performing system upgrade...${NC}\n" if ! sudo apt-get full-upgrade -y; then printf "${RED}Error: System upgrade failed.${NC}\n" exit 1 fi printf "${GREEN}Done.${NC}\n" echo "" # If nodejs was updated, start ioBroker if [ "$nodejs_update" = true ]; then printf "${YELLOW}nodejs has been updated. Starting ioBroker...${NC}\n" if ! iobroker start; then printf "${RED}Error: Failed to start ioBroker.${NC}\n" exit 1 fi if ! wait_for_js_controller_start; then printf "${RED}Error: ioBroker did not start properly.${NC}\n" exit 1 fi fi # 3. Check and install ioBroker updates printf "${YELLOW}3. Checking for ioBroker updates...${NC}\n" iobroker update > "/tmp/iobroker_updates.log" 2>&1 # Check if js-controller needs to be updated if grep -q "js-controller.*Updatable" "/tmp/iobroker_updates.log"; then printf "${YELLOW}js-controller needs to be updated. Stopping ioBroker...${NC}\n" if ! stop_iobroker; then printf "${RED}Error: Failed to stop ioBroker properly.${NC}\n" exit 1 fi printf "${YELLOW}Updating js-controller...${NC}\n" if ! iobroker upgrade self; then printf "${RED}Error: Failed to update js-controller.${NC}\n" exit 1 fi printf "${GREEN}Done.${NC}\n" printf "${YELLOW}Starting ioBroker...${NC}\n" if ! iobroker start; then printf "${RED}Error: Failed to start ioBroker.${NC}\n" exit 1 fi if ! wait_for_js_controller_start; then printf "${RED}Error: ioBroker did not start properly.${NC}\n" exit 1 fi fi # Install all other ioBroker updates printf "${YELLOW}Installing ioBroker updates...${NC}\n" if ! iobroker upgrade --all; then printf "${RED}Error: Failed to install ioBroker updates.${NC}\n" exit 1 fi printf "${GREEN}Done.${NC}\n" echo "" # Reboot check printf "${BLUE}=============================================================================${NC}\n" if [ -f "/var/run/reboot-required" ]; then printf "${RED}IMPORTANT: The system needs to be REBOOTED to complete the changes!${NC}\n" echo "" printf "${YELLOW}Please execute the following command:${NC}\n" printf "${GREEN}sudo reboot${NC}\n" else printf "${GREEN}All updates have been installed successfully. No reboot required.${NC}\n" fi printf "${BLUE}=============================================================================${NC}\n"Auf meinem aktuellen System schaut das dann so aus:
============================================================================= === System Update Script === ============================================================================= 1. Updating package lists... OK:1 https://cli.github.com/packages stable InRelease OK:2 http://archive.raspberrypi.com/debian trixie InRelease OK:3 http://deb.debian.org/debian trixie InRelease OK:4 http://deb.debian.org/debian-security trixie-security InRelease OK:5 https://repo.mosquitto.org/debian trixie InRelease OK:6 http://deb.debian.org/debian trixie-updates InRelease OK:7 https://deb.nodesource.com/node_25.x nodistro InRelease OK:8 https://deb.nodesource.com/node_22.x nodistro InRelease Holen:9 https://pkgs.tailscale.com/stable/debian trixie InRelease OK:10 https://packagecloud.io/ookla/speedtest-cli/debian trixie InRelease Es wurden 6.582 B in 1 s geholt (5.191 B/s). Paketlisten werden gelesen… Fertig Done. 2. Performing system upgrade... Paketlisten werden gelesen… Fertig Abhängigkeitsbaum wird aufgebaut… Fertig Statusinformationen werden eingelesen… Fertig Paketaktualisierung (Upgrade) wird berechnet… Fertig 0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert. Done. 3. Checking for ioBroker updates... Installing ioBroker updates... All adapters are up to date Done. ============================================================================= All updates have been installed successfully. No reboot required. =============================================================================
Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.
Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.
Mit deinem Input könnte dieser Beitrag noch besser werden 💗
Registrieren Anmelden