1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-05-06 07:03:08 +00:00

Tools-Func: Better Function Handling + gs (#4238)

This commit is contained in:
CanbiZ 2025-05-05 15:47:43 +02:00 committed by GitHub
parent bff0ab3d3d
commit 0ea0f56e1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
#!/bin/bash
install_node_and_modules() { install_node_and_modules() {
local NODE_VERSION="${NODE_VERSION:-22}" local NODE_VERSION="${NODE_VERSION:-22}"
local NODE_MODULE="${NODE_MODULE:-}" local NODE_MODULE="${NODE_MODULE:-}"
@ -47,7 +48,7 @@ install_node_and_modules() {
msg_ok "Installed Node.js ${NODE_VERSION}" msg_ok "Installed Node.js ${NODE_VERSION}"
fi fi
export NODE_OPTIONS="--max_old_space_size=4096" export NODE_OPTIONS="--max-old-space-size=4096"
# Install global Node modules # Install global Node modules
if [[ -n "$NODE_MODULE" ]]; then if [[ -n "$NODE_MODULE" ]]; then
@ -345,7 +346,7 @@ install_go() {
esac esac
# Determine version # Determine version
if [[ -z "$GO_VERSION" || "$GO_VERSION" == "latest" ]]; then if [[ -z "${GO_VERSION:-}" || "${GO_VERSION}" == "latest" ]]; then
GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | sed 's/^go//') GO_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text | head -n1 | sed 's/^go//')
if [[ -z "$GO_VERSION" ]]; then if [[ -z "$GO_VERSION" ]]; then
msg_error "Could not determine latest Go version" msg_error "Could not determine latest Go version"
@ -389,7 +390,7 @@ install_go() {
} }
install_java() { install_java() {
local JAVA_VERSION="${JAVA_VERSION:-17}" local JAVA_VERSION="${JAVA_VERSION:-21}"
local DISTRO_CODENAME local DISTRO_CODENAME
DISTRO_CODENAME=$(awk -F= '/VERSION_CODENAME/ { print $2 }' /etc/os-release) DISTRO_CODENAME=$(awk -F= '/VERSION_CODENAME/ { print $2 }' /etc/os-release)
local DESIRED_PACKAGE="temurin-${JAVA_VERSION}-jdk" local DESIRED_PACKAGE="temurin-${JAVA_VERSION}-jdk"
@ -658,8 +659,8 @@ setup_local_ip_helper() {
# Install networkd-dispatcher if not present # Install networkd-dispatcher if not present
if ! dpkg -s networkd-dispatcher >/dev/null 2>&1; then if ! dpkg -s networkd-dispatcher >/dev/null 2>&1; then
$STD apt-get update -qq apt-get update -qq
$STD apt-get install -yq networkd-dispatcher apt-get install -yq networkd-dispatcher
fi fi
# Write update_local_ip.sh # Write update_local_ip.sh
@ -757,6 +758,34 @@ import_local_ip() {
export LOCAL_IP export LOCAL_IP
} }
function download_with_progress() {
local url="$1"
local output="$2"
if [ -n "$SPINNER_PID" ] && ps -p "$SPINNER_PID" >/dev/null; then kill "$SPINNER_PID" >/dev/null; fi
if ! command -v pv &>/dev/null; then
$STD apt-get install -y pv
fi
set -o pipefail
# Content-Length aus HTTP-Header holen
local content_length
content_length=$(curl -fsSLI "$url" | awk '/Content-Length/ {print $2}' | tr -d '\r' || true)
if [[ -z "$content_length" ]]; then
#msg_warn "Content-Length not available, falling back to plain download"
if ! curl -fL# -o "$output" "$url"; then
msg_error "Download failed"
return 1
fi
else
if ! curl -fsSL "$url" | pv -s "$content_length" >"$output"; then
msg_error "Download failed"
return 1
fi
fi
}
function setup_uv() { function setup_uv() {
$STD msg_info "Checking uv installation..." $STD msg_info "Checking uv installation..."
UV_BIN="/usr/local/bin/uv" UV_BIN="/usr/local/bin/uv"
@ -818,3 +847,57 @@ function ensure_usr_local_bin_persist() {
chmod +x "$PROFILE_FILE" chmod +x "$PROFILE_FILE"
fi fi
} }
function setup_gs() {
msg_info "Setup Ghostscript"
mkdir -p /tmp
TMP_DIR=$(mktemp -d)
CURRENT_VERSION=$(gs --version 2>/dev/null || echo "0")
RELEASE_JSON=$(curl -fsSL https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/latest)
LATEST_VERSION=$(echo "$RELEASE_JSON" | grep '"tag_name":' | head -n1 | cut -d '"' -f4 | sed 's/^gs//')
LATEST_VERSION_DOTTED=$(echo "$RELEASE_JSON" | grep '"name":' | head -n1 | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
if [[ -z "$LATEST_VERSION" ]]; then
msg_error "Could not determine latest Ghostscript version from GitHub."
rm -rf "$TMP_DIR"
return
fi
if dpkg --compare-versions "$CURRENT_VERSION" ge "$LATEST_VERSION_DOTTED"; then
msg_ok "Ghostscript is already at version $CURRENT_VERSION"
rm -rf "$TMP_DIR"
return
fi
msg_info "Installing/Updating Ghostscript to $LATEST_VERSION_DOTTED"
curl -fsSL "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs${LATEST_VERSION}/ghostscript-${LATEST_VERSION_DOTTED}.tar.gz" -o "$TMP_DIR/ghostscript.tar.gz"
if ! tar -xzf "$TMP_DIR/ghostscript.tar.gz" -C "$TMP_DIR"; then
msg_error "Failed to extract Ghostscript archive."
rm -rf "$TMP_DIR"
return
fi
cd "$TMP_DIR/ghostscript-${LATEST_VERSION_DOTTED}" || {
msg_error "Failed to enter Ghostscript source directory."
rm -rf "$TMP_DIR"
}
$STD apt-get install -y build-essential libpng-dev zlib1g-dev
./configure >/dev/null && make && sudo make install >/dev/null
local EXIT_CODE=$?
hash -r
if [[ ! -x "$(command -v gs)" ]]; then
if [[ -x /usr/local/bin/gs ]]; then
ln -sf /usr/local/bin/gs /usr/bin/gs
fi
fi
rm -rf "$TMP_DIR"
if [[ $EXIT_CODE -eq 0 ]]; then
msg_ok "Ghostscript installed/updated to version $LATEST_VERSION_DOTTED"
else
msg_error "Ghostscript installation failed"
fi
}