mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-21 21:26:16 +01:00
improve install scripts with retries, validation, and better error messages
Add curl retries/timeouts, archive integrity checks, binary existence checks, and temp dir cleanup on all failure paths. Unify --mirror flag handling in hub script to match agent. Use cat instead of tee for systemd service file, quiet systemctl output.
This commit is contained in:
@@ -374,7 +374,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Stop existing service if it exists (for upgrades)
|
# Stop existing service if it exists (for upgrades)
|
||||||
if [ -f "$BIN_PATH" ]; then
|
if [ "$UNINSTALL" != true ] && [ -f "$BIN_PATH" ]; then
|
||||||
echo "Existing installation detected. Stopping service for upgrade..."
|
echo "Existing installation detected. Stopping service for upgrade..."
|
||||||
if is_alpine; then
|
if is_alpine; then
|
||||||
rc-service beszel-agent stop 2>/dev/null || true
|
rc-service beszel-agent stop 2>/dev/null || true
|
||||||
@@ -451,7 +451,7 @@ if [ "$UNINSTALL" = true ]; then
|
|||||||
else
|
else
|
||||||
echo "Stopping and disabling the agent service..."
|
echo "Stopping and disabling the agent service..."
|
||||||
systemctl stop beszel-agent.service
|
systemctl stop beszel-agent.service
|
||||||
systemctl disable beszel-agent.service
|
systemctl disable beszel-agent.service >/dev/null 2>&1
|
||||||
|
|
||||||
echo "Removing the systemd service file..."
|
echo "Removing the systemd service file..."
|
||||||
rm /etc/systemd/system/beszel-agent.service
|
rm /etc/systemd/system/beszel-agent.service
|
||||||
@@ -459,7 +459,7 @@ if [ "$UNINSTALL" = true ]; then
|
|||||||
# Remove the update timer and service if they exist
|
# Remove the update timer and service if they exist
|
||||||
echo "Removing the daily update service and timer..."
|
echo "Removing the daily update service and timer..."
|
||||||
systemctl stop beszel-agent-update.timer 2>/dev/null
|
systemctl stop beszel-agent-update.timer 2>/dev/null
|
||||||
systemctl disable beszel-agent-update.timer 2>/dev/null
|
systemctl disable beszel-agent-update.timer >/dev/null 2>&1
|
||||||
rm -f /etc/systemd/system/beszel-agent-update.service
|
rm -f /etc/systemd/system/beszel-agent-update.service
|
||||||
rm -f /etc/systemd/system/beszel-agent-update.timer
|
rm -f /etc/systemd/system/beszel-agent-update.timer
|
||||||
|
|
||||||
@@ -549,14 +549,14 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a dedicated user for the service if it doesn't exist
|
# Create a dedicated user for the service if it doesn't exist
|
||||||
echo "Creating a dedicated user for the Beszel Agent service..."
|
echo "Configuring the dedicated user for the Beszel Agent service..."
|
||||||
if is_alpine; then
|
if is_alpine; then
|
||||||
if ! id -u beszel >/dev/null 2>&1; then
|
if ! id -u beszel >/dev/null 2>&1; then
|
||||||
addgroup beszel
|
addgroup beszel
|
||||||
adduser -S -D -H -s /sbin/nologin -G beszel beszel
|
adduser -S -D -H -s /sbin/nologin -G beszel beszel
|
||||||
fi
|
fi
|
||||||
# Add the user to the docker group to allow access to the Docker socket if group docker exists
|
# Add the user to the docker group to allow access to the Docker socket if group docker exists
|
||||||
if getent group docker; then
|
if getent group docker >/dev/null 2>&1; then
|
||||||
echo "Adding beszel to docker group"
|
echo "Adding beszel to docker group"
|
||||||
addgroup beszel docker
|
addgroup beszel docker
|
||||||
fi
|
fi
|
||||||
@@ -604,12 +604,12 @@ else
|
|||||||
useradd --system --home-dir /nonexistent --shell /bin/false beszel
|
useradd --system --home-dir /nonexistent --shell /bin/false beszel
|
||||||
fi
|
fi
|
||||||
# Add the user to the docker group to allow access to the Docker socket if group docker exists
|
# Add the user to the docker group to allow access to the Docker socket if group docker exists
|
||||||
if getent group docker; then
|
if getent group docker >/dev/null 2>&1; then
|
||||||
echo "Adding beszel to docker group"
|
echo "Adding beszel to docker group"
|
||||||
usermod -aG docker beszel
|
usermod -aG docker beszel
|
||||||
fi
|
fi
|
||||||
# Add the user to the disk group to allow access to disk devices if group disk exists
|
# Add the user to the disk group to allow access to disk devices if group disk exists
|
||||||
if getent group disk; then
|
if getent group disk >/dev/null 2>&1; then
|
||||||
echo "Adding beszel to disk group"
|
echo "Adding beszel to disk group"
|
||||||
usermod -aG disk beszel
|
usermod -aG disk beszel
|
||||||
fi
|
fi
|
||||||
@@ -629,7 +629,6 @@ if [ ! -d "$BIN_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Download and install the Beszel Agent
|
# Download and install the Beszel Agent
|
||||||
echo "Downloading and installing the agent..."
|
|
||||||
|
|
||||||
OS=$(uname -s | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
|
OS=$(uname -s | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
|
||||||
ARCH=$(detect_architecture)
|
ARCH=$(detect_architecture)
|
||||||
@@ -656,19 +655,29 @@ else
|
|||||||
INSTALL_VERSION=$(echo "$INSTALL_VERSION" | sed 's/^v//')
|
INSTALL_VERSION=$(echo "$INSTALL_VERSION" | sed 's/^v//')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Downloading and installing agent version ${INSTALL_VERSION} from ${GITHUB_URL} ..."
|
echo "Downloading beszel-agent v${INSTALL_VERSION}..."
|
||||||
|
|
||||||
# Download checksums file
|
# Download checksums file
|
||||||
TEMP_DIR=$(mktemp -d)
|
TEMP_DIR=$(mktemp -d)
|
||||||
cd "$TEMP_DIR" || exit 1
|
cd "$TEMP_DIR" || exit 1
|
||||||
CHECKSUM=$(curl -sL "$GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/beszel_${INSTALL_VERSION}_checksums.txt" | grep "$FILE_NAME" | cut -d' ' -f1)
|
CHECKSUM=$(curl -fsSL "$GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/beszel_${INSTALL_VERSION}_checksums.txt" | grep "$FILE_NAME" | cut -d' ' -f1)
|
||||||
if [ -z "$CHECKSUM" ] || ! echo "$CHECKSUM" | grep -qE "^[a-fA-F0-9]{64}$"; then
|
if [ -z "$CHECKSUM" ] || ! echo "$CHECKSUM" | grep -qE "^[a-fA-F0-9]{64}$"; then
|
||||||
echo "Failed to get checksum or invalid checksum format"
|
echo "Failed to get checksum or invalid checksum format"
|
||||||
|
echo "Try again with --mirror (or --mirror <url>) if GitHub is not reachable."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! curl -#L "$GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/$FILE_NAME" -o "$FILE_NAME"; then
|
if ! curl -fL# --retry 3 --retry-delay 2 --connect-timeout 10 "$GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/$FILE_NAME" -o "$FILE_NAME"; then
|
||||||
echo "Failed to download the agent from ""$GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/$FILE_NAME"
|
echo "Failed to download the agent from $GITHUB_URL/henrygd/beszel/releases/download/v${INSTALL_VERSION}/$FILE_NAME"
|
||||||
|
echo "Try again with --mirror (or --mirror <url>) if GitHub is not reachable."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! tar -tzf "$FILE_NAME" >/dev/null 2>&1; then
|
||||||
|
echo "Downloaded archive is invalid or incomplete (possible network/proxy issue)."
|
||||||
|
echo "Try again with --mirror (or --mirror <url>) if the download path is unstable."
|
||||||
rm -rf "$TEMP_DIR"
|
rm -rf "$TEMP_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -685,6 +694,12 @@ if ! tar -xzf "$FILE_NAME" beszel-agent; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -s "$TEMP_DIR/beszel-agent" ]; then
|
||||||
|
echo "Downloaded binary is missing or empty."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "$BIN_PATH" ]; then
|
if [ -f "$BIN_PATH" ]; then
|
||||||
echo "Backing up existing binary..."
|
echo "Backing up existing binary..."
|
||||||
cp "$BIN_PATH" "$BIN_PATH.bak"
|
cp "$BIN_PATH" "$BIN_PATH.bak"
|
||||||
@@ -991,7 +1006,7 @@ EOF
|
|||||||
# Load and start the service
|
# Load and start the service
|
||||||
printf "\nLoading and starting the agent service...\n"
|
printf "\nLoading and starting the agent service...\n"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable beszel-agent.service
|
systemctl enable beszel-agent.service >/dev/null 2>&1
|
||||||
systemctl restart beszel-agent.service
|
systemctl restart beszel-agent.service
|
||||||
|
|
||||||
|
|
||||||
@@ -1037,7 +1052,7 @@ WantedBy=timers.target
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable --now beszel-agent-update.timer
|
systemctl enable --now beszel-agent-update.timer >/dev/null 2>&1
|
||||||
|
|
||||||
printf "\nDaily updates have been enabled.\n"
|
printf "\nDaily updates have been enabled.\n"
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ fi
|
|||||||
|
|
||||||
# Define default values
|
# Define default values
|
||||||
PORT=8090
|
PORT=8090
|
||||||
GITHUB_PROXY_URL="https://ghfast.top/"
|
GITHUB_URL="https://github.com"
|
||||||
AUTO_UPDATE_FLAG="false"
|
AUTO_UPDATE_FLAG="false"
|
||||||
UNINSTALL=false
|
UNINSTALL=false
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ while [ $# -gt 0 ]; do
|
|||||||
printf "Options: \n"
|
printf "Options: \n"
|
||||||
printf " -u : Uninstall the Beszel Hub\n"
|
printf " -u : Uninstall the Beszel Hub\n"
|
||||||
printf " -p <port> : Specify a port number (default: 8090)\n"
|
printf " -p <port> : Specify a port number (default: 8090)\n"
|
||||||
printf " -c <url> : Use a custom GitHub mirror URL (e.g., https://ghfast.top/)\n"
|
printf " -c, --mirror [URL] : Use a GitHub mirror/proxy URL (default: https://gh.beszel.dev)\n"
|
||||||
printf " --auto-update : Enable automatic daily updates (disabled by default)\n"
|
printf " --auto-update : Enable automatic daily updates (disabled by default)\n"
|
||||||
printf " -h, --help : Display this help message\n"
|
printf " -h, --help : Display this help message\n"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -183,10 +183,14 @@ while [ $# -gt 0 ]; do
|
|||||||
PORT="$1"
|
PORT="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-c)
|
-c | --mirror)
|
||||||
shift
|
|
||||||
GITHUB_PROXY_URL=$(ensure_trailing_slash "$1")
|
|
||||||
shift
|
shift
|
||||||
|
if [ -n "$1" ] && ! echo "$1" | grep -q '^-'; then
|
||||||
|
GITHUB_URL="$(ensure_trailing_slash "$1")https://github.com"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
GITHUB_URL="https://gh.beszel.dev"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
--auto-update)
|
--auto-update)
|
||||||
AUTO_UPDATE_FLAG="true"
|
AUTO_UPDATE_FLAG="true"
|
||||||
@@ -199,9 +203,6 @@ while [ $# -gt 0 ]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Ensure the proxy URL ends with a /
|
|
||||||
GITHUB_PROXY_URL=$(ensure_trailing_slash "$GITHUB_PROXY_URL")
|
|
||||||
|
|
||||||
# Set paths based on operating system
|
# Set paths based on operating system
|
||||||
if is_freebsd; then
|
if is_freebsd; then
|
||||||
HUB_DIR="/usr/local/etc/beszel"
|
HUB_DIR="/usr/local/etc/beszel"
|
||||||
@@ -323,10 +324,41 @@ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
|||||||
ARCH=$(detect_architecture)
|
ARCH=$(detect_architecture)
|
||||||
FILE_NAME="beszel_${OS}_${ARCH}.tar.gz"
|
FILE_NAME="beszel_${OS}_${ARCH}.tar.gz"
|
||||||
|
|
||||||
curl -sL "${GITHUB_PROXY_URL}https://github.com/henrygd/beszel/releases/latest/download/$FILE_NAME" | tar -xz -O beszel | tee ./beszel >/dev/null
|
TEMP_DIR=$(mktemp -d)
|
||||||
chmod +x ./beszel
|
ARCHIVE_PATH="$TEMP_DIR/$FILE_NAME"
|
||||||
mv ./beszel "$BIN_PATH"
|
DOWNLOAD_URL="$GITHUB_URL/henrygd/beszel/releases/latest/download/$FILE_NAME"
|
||||||
|
|
||||||
|
if ! curl -fL# --retry 3 --retry-delay 2 --connect-timeout 10 "$DOWNLOAD_URL" -o "$ARCHIVE_PATH"; then
|
||||||
|
echo "Failed to download the Beszel Hub from:"
|
||||||
|
echo "$DOWNLOAD_URL"
|
||||||
|
echo "Try again with --mirror (or --mirror <url>) if GitHub is not reachable."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! tar -tzf "$ARCHIVE_PATH" >/dev/null 2>&1; then
|
||||||
|
echo "Downloaded archive is invalid or incomplete (possible network/proxy issue)."
|
||||||
|
echo "Try again with --mirror (or --mirror <url>) if the download path is unstable."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! tar -xzf "$ARCHIVE_PATH" -C "$TEMP_DIR" beszel; then
|
||||||
|
echo "Failed to extract beszel from archive."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -s "$TEMP_DIR/beszel" ]; then
|
||||||
|
echo "Downloaded binary is missing or empty."
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "$TEMP_DIR/beszel"
|
||||||
|
mv "$TEMP_DIR/beszel" "$BIN_PATH"
|
||||||
chown beszel:beszel "$BIN_PATH"
|
chown beszel:beszel "$BIN_PATH"
|
||||||
|
rm -rf "$TEMP_DIR"
|
||||||
|
|
||||||
if is_freebsd; then
|
if is_freebsd; then
|
||||||
echo "Creating FreeBSD rc service..."
|
echo "Creating FreeBSD rc service..."
|
||||||
@@ -375,8 +407,8 @@ EOF
|
|||||||
|
|
||||||
else
|
else
|
||||||
# Original systemd service installation code
|
# Original systemd service installation code
|
||||||
printf "Creating the systemd service for the Beszel Hub...\n\n"
|
printf "Creating the systemd service for the Beszel Hub...\n"
|
||||||
tee /etc/systemd/system/beszel-hub.service <<EOF
|
cat >/etc/systemd/system/beszel-hub.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Beszel Hub Service
|
Description=Beszel Hub Service
|
||||||
After=network.target
|
After=network.target
|
||||||
@@ -393,10 +425,10 @@ WantedBy=multi-user.target
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Load and start the service
|
# Load and start the service
|
||||||
printf "\nLoading and starting the Beszel Hub service...\n"
|
printf "Loading and starting the Beszel Hub service...\n"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable beszel-hub.service
|
systemctl enable --quiet beszel-hub.service
|
||||||
systemctl start beszel-hub.service
|
systemctl start --quiet beszel-hub.service
|
||||||
|
|
||||||
# Wait for the service to start or fail
|
# Wait for the service to start or fail
|
||||||
sleep 2
|
sleep 2
|
||||||
@@ -444,4 +476,4 @@ EOF
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "The Beszel Hub has been installed and configured successfully! It is now accessible on port $PORT."
|
printf "\n\033[32mBeszel Hub has been installed successfully! It is now accessible on port $PORT.\033[0m\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user