forked from domoticz/domoticz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdaterelease
More file actions
executable file
·122 lines (104 loc) · 4.06 KB
/
updaterelease
File metadata and controls
executable file
·122 lines (104 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# Domoticz Update Script - Release channel
# Usage: ./updaterelease [-nobackup]
lowercase() {
echo "$1" | tr '[:upper:]' '[:lower:]'
}
log_info() { echo "$(date '+%Y-%m-%d %H:%M:%S.%3N') >> $*"; }
log_warn() { echo "$(date '+%Y-%m-%d %H:%M:%S.%3N') >> WARNING: $*"; }
die() { echo "$(date '+%Y-%m-%d %H:%M:%S.%3N') >> ERROR: $*" >&2; exit 1; }
OS=$(lowercase "$(uname -s)")
MACH=$(uname -m)
ARCH=$(dpkg --print-architecture)
OPENSSL_VERSION=$(openssl version | awk '{print $2}' | cut -d. -f1)
SCRIPT_NAME=$(basename "$0")
ARCHIVE="domoticz_release.tgz"
if [ "$MACH" = "armv6l" ]; then
die "ARMv6 is not supported anymore... Please upgrade your hardware"
fi
if [ "$ARCH" = "armhf" ]; then
MACH="armv7l"
fi
if [ "$OPENSSL_VERSION" -ne 3 ]; then
die "OpenSSL version 3 required!"
fi
# List of required packages — extend as needed
REQUIRED_PACKAGES=(
"libmosquitto1"
#"libcurl4"
#"libssl3"
)
check_dependencies() {
log_info "Checking package dependencies..."
local missing_packages=()
local pkg
for pkg in "${REQUIRED_PACKAGES[@]}"; do
if ! dpkg -l | grep -q "^ii $pkg"; then
log_warn "Package '$pkg' is not installed"
missing_packages+=("$pkg")
else
log_info "Package '$pkg' is already installed"
fi
done
if [[ ${#missing_packages[@]} -gt 0 ]]; then
log_info "Installing missing packages: ${missing_packages[*]}"
log_info "Updating package list..."
if ! sudo apt-get update -qq; then
log_warn "Failed to update package list, continuing anyway..."
fi
if ! sudo apt-get install -y "${missing_packages[@]}"; then
die "Failed to install required packages: ${missing_packages[*]}"
fi
log_info "Successfully installed: ${missing_packages[*]}"
else
log_info "All required packages are already installed"
fi
}
if [ "${DOMOTICZ_UPDATE_REEXEC}" != "1" ]; then
log_info "Downloading latest release version..."
wget -4 -q --show-progress -O "$ARCHIVE" --no-check-certificate \
"https://www.domoticz.com/download.php?channel=release&type=release&system=${OS}&machine=${MACH}"
if [ $? -ne 0 ]; then
die "Problem downloading new Domoticz version!!"
fi
log_info "Checking file integrity..."
if ! tar tzf "$ARCHIVE" >/dev/null 2>&1; then
rm -f "$ARCHIVE"
die "Problem in downloaded Domoticz archive!!"
fi
log_info "Checking for updated upgrade script..."
updated_script=$(tar -zxf "$ARCHIVE" --no-anchored "$SCRIPT_NAME" -O 2>/dev/null)
if [ -n "$updated_script" ] && ! diff <(cat "$0") <(echo "$updated_script") >/dev/null 2>&1; then
log_info "Found updated script, re-executing..."
export DOMOTICZ_UPDATE_REEXEC=1
exec bash -c "$updated_script" "$SCRIPT_NAME" "$@"
fi
fi
# Ensure archive exists (re-exec starts a new process; archive file persists on disk)
if [ ! -f "$ARCHIVE" ]; then
log_info "Downloading latest release version..."
if ! wget -4 -q --show-progress -O "$ARCHIVE" --no-check-certificate \
"https://www.domoticz.com/download.php?channel=release&type=release&system=${OS}&machine=${MACH}"; then
die "Failed to download Domoticz archive"
fi
fi
log_info "Stopping Domoticz..."
sudo service domoticz.sh stop
if [ "$1" != "-nobackup" ]; then
log_info "Making backup of current installation..."
ls -t backups/domoticz_backup_* 2>/dev/null | tail -n +6 | xargs --no-run-if-empty -I {} rm -- {}
timestamp=$(date +%Y%m%d_%H%M%S)
mkdir -p backups
log_info "Output file: backups/domoticz_backup_${timestamp}.tar.gz"
sudo tar -czf "backups/domoticz_backup_${timestamp}.tar.gz" domoticz domoticz.db* History.txt updatebeta updaterelease
log_info "Backup finished..."
fi
check_dependencies
log_info "Installing new version..."
if ! tar xfz "$ARCHIVE" --checkpoint=.100; then
die "Failed to extract Domoticz archive"
fi
rm -f "$ARCHIVE"
log_info "Starting Domoticz... (please standby...)"
sudo service domoticz.sh start
log_info "Update completed successfully"