mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 20:56:14 +00:00
Fix: download_telemt extract - use dedicated dir instead of find -newer
This commit is contained in:
@@ -65,6 +65,7 @@ download_telemt() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local tmp_file="/tmp/telemt_download_$$"
|
local tmp_file="/tmp/telemt_download_$$"
|
||||||
|
local extract_dir="/tmp/telemt_extract_$$"
|
||||||
log_info "Скачивание: $url"
|
log_info "Скачивание: $url"
|
||||||
|
|
||||||
if ! curl -L -s --max-time 120 -o "$tmp_file" "$url"; then
|
if ! curl -L -s --max-time 120 -o "$tmp_file" "$url"; then
|
||||||
@@ -73,42 +74,58 @@ download_telemt() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Проверяем что файл не пустой и не HTML
|
||||||
|
local file_size
|
||||||
|
file_size=$(stat -c%s "$tmp_file" 2>/dev/null || echo 0)
|
||||||
|
if [ "$file_size" -lt 1000 ]; then
|
||||||
|
log_error "Скачанный файл слишком маленький ($file_size байт) — возможна ошибка сети"
|
||||||
|
rm -f "$tmp_file"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Определяем тип файла и распаковываем
|
# Определяем тип файла и распаковываем
|
||||||
local mime
|
local mime extracted=""
|
||||||
mime=$(file -b --mime-type "$tmp_file" 2>/dev/null)
|
mime=$(file -b --mime-type "$tmp_file" 2>/dev/null)
|
||||||
|
rm -rf "$extract_dir"
|
||||||
|
mkdir -p "$extract_dir"
|
||||||
|
|
||||||
case "$mime" in
|
case "$mime" in
|
||||||
application/gzip|application/x-gzip)
|
application/gzip|application/x-gzip)
|
||||||
tar xzf "$tmp_file" -C /tmp/ 2>/dev/null
|
tar xzf "$tmp_file" -C "$extract_dir" 2>/dev/null
|
||||||
local extracted
|
extracted=$(find "$extract_dir" -name "telemt" -type f 2>/dev/null | head -1)
|
||||||
extracted=$(find /tmp -maxdepth 2 -name "telemt" -type f -newer "$tmp_file" 2>/dev/null | head -1)
|
|
||||||
if [ -z "$extracted" ]; then
|
if [ -z "$extracted" ]; then
|
||||||
# Может быть просто gzip без tar
|
# Может быть просто gzip без tar
|
||||||
gunzip -c "$tmp_file" > /tmp/telemt_bin_$$ 2>/dev/null
|
gunzip -c "$tmp_file" > "$extract_dir/telemt_bin" 2>/dev/null
|
||||||
extracted="/tmp/telemt_bin_$$"
|
extracted="$extract_dir/telemt_bin"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
application/x-tar)
|
application/x-tar)
|
||||||
tar xf "$tmp_file" -C /tmp/ 2>/dev/null
|
tar xf "$tmp_file" -C "$extract_dir" 2>/dev/null
|
||||||
extracted=$(find /tmp -maxdepth 2 -name "telemt" -type f -newer "$tmp_file" 2>/dev/null | head -1)
|
extracted=$(find "$extract_dir" -name "telemt" -type f 2>/dev/null | head -1)
|
||||||
;;
|
;;
|
||||||
application/zip)
|
application/zip)
|
||||||
unzip -o "$tmp_file" -d /tmp/telemt_extract_$$ 2>/dev/null
|
unzip -o "$tmp_file" -d "$extract_dir" 2>/dev/null
|
||||||
extracted=$(find /tmp/telemt_extract_$$ -name "telemt" -type f 2>/dev/null | head -1)
|
extracted=$(find "$extract_dir" -name "telemt" -type f 2>/dev/null | head -1)
|
||||||
;;
|
;;
|
||||||
application/octet-stream|application/x-executable)
|
application/octet-stream|application/x-executable)
|
||||||
# Уже бинарник
|
|
||||||
extracted="$tmp_file"
|
extracted="$tmp_file"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# Пробуем как бинарник
|
# Пробуем определить по содержимому
|
||||||
extracted="$tmp_file"
|
if file "$tmp_file" 2>/dev/null | grep -q "ELF"; then
|
||||||
|
extracted="$tmp_file"
|
||||||
|
else
|
||||||
|
# Пробуем как tar.gz
|
||||||
|
tar xzf "$tmp_file" -C "$extract_dir" 2>/dev/null
|
||||||
|
extracted=$(find "$extract_dir" -name "telemt" -type f 2>/dev/null | head -1)
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -z "$extracted" ] || [ ! -f "$extracted" ]; then
|
if [ -z "$extracted" ] || [ ! -f "$extracted" ]; then
|
||||||
log_error "Не удалось извлечь бинарник telemt"
|
log_error "Не удалось извлечь бинарник telemt (mime: $mime)"
|
||||||
rm -f "$tmp_file"
|
rm -f "$tmp_file"
|
||||||
|
rm -rf "$extract_dir"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -116,14 +133,14 @@ download_telemt() {
|
|||||||
cp "$extracted" "$TELEMT_BIN"
|
cp "$extracted" "$TELEMT_BIN"
|
||||||
chmod 755 "$TELEMT_BIN"
|
chmod 755 "$TELEMT_BIN"
|
||||||
rm -f "$tmp_file"
|
rm -f "$tmp_file"
|
||||||
rm -rf /tmp/telemt_extract_$$ /tmp/telemt_bin_$$
|
rm -rf "$extract_dir"
|
||||||
|
|
||||||
# Проверяем
|
# Проверяем
|
||||||
if "$TELEMT_BIN" --version &>/dev/null; then
|
if "$TELEMT_BIN" --version &>/dev/null; then
|
||||||
log_success "telemt $(get_installed_telemt_version) установлен в $TELEMT_BIN"
|
log_success "telemt $(get_installed_telemt_version) установлен в $TELEMT_BIN"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log_error "Бинарник telemt не запускается"
|
log_error "Бинарник telemt не запускается ($(file -b "$TELEMT_BIN" 2>/dev/null))"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user