jina verze

This commit is contained in:
2026-08-12 10:53:04 +02:00
parent f186ec26a8
commit 93d4f24f07
43 changed files with 1686 additions and 1959 deletions
+172 -54
View File
@@ -112,18 +112,6 @@ function sshDirectoryDelete() {
|| { appError "$error"; return 1; }
}
function fileAtomicWrite() {
local file="$1"
local content="$2"
local path tmp
path="$(dirname "$file")"
mkdir -p "$path"
tmp="$(mktemp "$path/.tmp.XXXXXX")"
printf '%s\n' "$content" > "$tmp"
mv -f "$tmp" "$file"
}
# Create a timestamped backup copy of a file if it exists.
# $1 (file): path to the file to back up.
# [$2] (suffix): custom suffix for the backup file (defaults to a timestamp .bak suffix).
@@ -336,6 +324,8 @@ function archiveExtract() {
# $3 (precision): Precision.
function pathSize() {
local path="$1"
[[ -n "$path" ]] || { appError "Path not specified"; return 1; }
local unit="${2:-}"
local precision="${3:-0}"
local divisor="1"
@@ -344,7 +334,6 @@ function pathSize() {
mb) divisor="1048576" ;;
gb) divisor="1073741824" ;;
esac
[[ -n "$path" ]] || { appError "Path not specified"; return 1; }
local output error bytes
if [[ -d "$path" ]]; then
@@ -360,47 +349,6 @@ function pathSize() {
LC_NUMERIC=C awk -v bytes="$bytes" -v divisor="$divisor" -v precision="$precision" 'BEGIN { printf "%.*f\n", precision, bytes / divisor }'
}
function ftpPathSize() {
local path="$1"
local unit="${2:-}"
local precision="${3:-0}"
local divisor="1"
case "${unit,,}" in
kb) divisor="1024" ;;
mb) divisor="1048576" ;;
gb) divisor="1073741824" ;;
esac
local output error total
if run output error curl -sS -u "$ftpUser:$ftpPass" "ftp://$ftpHost:$ftpPort$ftpPath$path/" --connect-timeout 10; then
total=0
local line file size
while IFS= read -r line; do
file=$(awk '{print $NF}' <<< "$line")
[[ -n "$file" && "$file" != "." && "$file" != ".." ]] || continue
if [[ "$line" =~ ^d ]]; then
size=$(ftpPathSize "$path/$file") || return 1
else
size=$(awk '{print $5}' <<< "$line")
[[ "$size" =~ ^[0-9]+$ ]] || continue
fi
(( total += size ))
done <<< "$output"
else
local parent name
parent=$(dirname "$path")
name=$(basename "$path")
run output error curl -sS -u "$ftpUser:$ftpPass" "ftp://$ftpHost:$ftpPort$ftpPath$parent/" --connect-timeout 10 || {
appError "$error"; return 1
}
total=$(awk -v f="$name" '$NF == f {print $5}' <<< "$output")
[[ "$total" =~ ^[0-9]+$ ]] || { appError "Cannot determine size of: $path"; return 1; }
fi
LC_NUMERIC=C awk -v b="$total" -v d="$divisor" -v p="$precision" 'BEGIN { printf "%.*f\n", p, b/d }'
}
# Return the contents of a file if it exists and is non-empty, otherwise write the given value to it and return it.
# $1 (file): path to the file.
# $2 (value): value to write when the file is missing or empty.
@@ -666,6 +614,25 @@ function fileSignatureAclCheck() {
[[ -z "$output" ]]
}
# ===============================================================================================================
# ===============================================================================================================
# ===============================================================================================================
# Checking the availability of a file (URL) for download.
# Check if a URL is accessible and print the final effective URL on success.
# $1 (url): the URL to check.
@@ -701,6 +668,8 @@ function urlCode() {
return 0
}
# Derive a local filename from a URL, optionally using a custom base name.
# $1 (url): the source URL to extract the filename from.
# [$2] (localFileName): custom base name; if given, the URL extension is appended to it.
@@ -724,3 +693,152 @@ function urlLocalFileGen() {
printf '%s' "$localFileName.$ext"
fi
}
# DEPRECATED
# Retrieves a list of files in an FTP directory along with their sizes (in ftpPath).
#
# $1 (assoc): An associative array where file names and their sizes will be saved.
# $2 (path): The path to the directory on the FTP server.
#
# If a file is a directory, its size is set to "-1". If it's a regular file, its size is saved.
function ftpEntrySizeList() {
local -n assoc=$1
local path="$2"
if ! run output error curl -sS -u "$ftpUser:$ftpPass" "ftp://$ftpHost:$ftpPort$ftpPath$path/" --connect-timeout 10; then
appError "$error"
return 1
fi
local line file size
while IFS= read -r line; do
file=$(echo "$line" | awk '{print $NF}')
size=$(echo "$line" | awk '{print $5}')
if [[ -n "$file" ]] && [[ "$line" =~ ^d.* ]]; then
assoc["$file"]="-1"
elif [[ -n "$file" ]] && [[ -n "$size" ]]; then
assoc["$file"]="$size"
fi
done <<< "$output"
}
# DEPRECATED
# Retrieves a list of files and their sizes from a remote directory via SSH (in sshPath).
#
# $1 (assoc): An associative array where file names and their sizes will be saved.
# $2 (path): The path to the remote directory where file sizes need to be retrieved.
function sshEntrySizeList() {
local -n assoc=$1
local path="$2"
if ! run output error ssh -i "$sshKeyFile" "$sshUser@$sshHost" "du -ab --max-depth=1 $sshPath$path"; then
appError "$error"
return 1
fi
output=$(echo "$output" | grep -v "[[:space:]]\+$sshPath$path$")
local size file
while IFS=$'\t' read -r size file; do
file=$(basename "$file")
if [[ -n "$file" && -n "$size" ]]; then
assoc["$file"]="$size"
fi
done <<< "$output"
}
# DEPRECATED
# Retrieves a list of files and their sizes in a specified directory on extended storage.
#
# $1 (assoc): An associative array where file names and their sizes will be saved.
# $2 (path): The path to the local directory where file sizes need to be retrieved.
function storageEntrySizeList() {
local -A storageFunc=(
["ftp"]=ftpEntrySizeList
["rsync"]=ftpEntrySizeList
["ssh"]=sshEntrySizeList
)
if [[ -z "${storageFunc[$storageType]}" ]]; then
appError "Unknown value storageType: $storageType"
return 1
fi
if ! run output error "${storageFunc[$storageType]}" "$@"; then
appError "$error"
return 1
fi
}
# DEPRECATED
# Retrieves a list of files and their sizes in a specified local directory (in backupPath).
#
# $1 (assoc): An associative array where file names and their sizes will be saved.
# $2 (path): The path to the local directory where file sizes need to be retrieved.
function backupEntrySizeList() {
local -n assoc=$1
local path="$2"
if ! run output error du -ab --max-depth=1 "$backupDailyPath$path"; then
appError "$error"
return 1
fi
local entryList
entryList=$(echo "$output" | grep -v "[[:space:]]\+$backupDailyPath$path$")
local file size
while IFS=$'\t' read -r size file; do
file=$(basename "$file")
if [[ -n "$file" && -n "$size" ]]; then
assoc["$file"]="$size"
fi
done <<< "$entryList"
}
# DEPRECATED
# List entries in a backup daily directory path.
# $1 (path): sub-path within backupDailyPath to list.
# [$2] (type): entry type filter (f: files, d: directories).
function backupEntryList() {
if ! run output error fileList "$backupDailyPath$1" "$2"; then
appError "$error"
return 1
fi
printf '%s\n' "$output"
}