This commit is contained in:
Henry Dollman
2025-01-21 18:51:34 -05:00
2 changed files with 69 additions and 29 deletions

View File

@@ -8,12 +8,25 @@ is_openwrt() {
cat /etc/os-release | grep -q "OpenWrt" cat /etc/os-release | grep -q "OpenWrt"
} }
# Function to ensure the proxy URL ends with a /
ensure_trailing_slash() {
if [ -n "$1" ]; then
case "$1" in
*/) echo "$1" ;;
*) echo "$1/" ;;
esac
else
echo "$1"
fi
}
# Define default values # Define default values
PORT=45876 PORT=45876
UNINSTALL=false UNINSTALL=false
CHINA_MAINLAND=false CHINA_MAINLAND=false
GITHUB_URL="https://github.com" GITHUB_URL="https://github.com"
GITHUB_API_URL="https://api.github.com" GITHUB_API_URL="https://api.github.com"
GITHUB_PROXY_URL="https://ghfast.top/" # Default proxy URL
KEY="" KEY=""
# Check for help flag first # Check for help flag first
@@ -25,7 +38,8 @@ case "$1" in
printf " -k : SSH key (required, or interactive if not provided)\n" printf " -k : SSH key (required, or interactive if not provided)\n"
printf " -p : Port (default: $PORT)\n" printf " -p : Port (default: $PORT)\n"
printf " -u : Uninstall Beszel Agent\n" printf " -u : Uninstall Beszel Agent\n"
printf " --china-mirrors : Using GitHub mirror sources to resolve network timeout issues in mainland China\n" printf " --china-mirrors [URL] : Using GitHub mirror sources to resolve network timeout issues in mainland China\n"
printf " (optional: specify a custom proxy URL, e.g., https://ghfast.top/)\n"
printf " -h, --help : Display this help message\n" printf " -h, --help : Display this help message\n"
exit 0 exit 0
;; ;;
@@ -73,6 +87,10 @@ while [ $# -gt 0 ]; do
;; ;;
--china-mirrors) --china-mirrors)
CHINA_MAINLAND=true CHINA_MAINLAND=true
if [ "$2" != "" ] && ! echo "$2" | grep -q '^-'; then
GITHUB_PROXY_URL=$(ensure_trailing_slash "$2")
shift
fi
;; ;;
*) *)
echo "Invalid option: $1" >&2 echo "Invalid option: $1" >&2
@@ -147,14 +165,12 @@ if [ "$UNINSTALL" = true ]; then
fi fi
if [ "$CHINA_MAINLAND" = true ]; then if [ "$CHINA_MAINLAND" = true ]; then
printf "\nConfirmed to use GitHub mirrors (ghp.ci) for download beszel-agent?\nThis helps to install Agent properly in mainland China. (Y/n): " printf "\nConfirmed to use GitHub mirrors (%s) for download beszel-agent?\nThis helps to install Agent properly in mainland China. (Y/n): " "$GITHUB_PROXY_URL"
read USE_MIRROR read USE_MIRROR
USE_MIRROR=${USE_MIRROR:-Y} USE_MIRROR=${USE_MIRROR:-Y}
if [ "$USE_MIRROR" = "Y" ] || [ "$USE_MIRROR" = "y" ]; then if [ "$USE_MIRROR" = "Y" ] || [ "$USE_MIRROR" = "y" ]; then
GITHUB_URL="https://ghp.ci/https://github.com" GITHUB_URL="${GITHUB_PROXY_URL}https://github.com"
# In China, only github.com is blocked, while api.github.com is not (for now). echo "Using GitHub Mirror ($GITHUB_PROXY_URL) for downloads..."
# GITHUB_API_URL="https://api.github.com"
echo "Using GitHub Mirror for downloads..."
else else
echo "GitHub mirrors will not be used for installation." echo "GitHub mirrors will not be used for installation."
fi fi
@@ -385,7 +401,7 @@ start_service() {
procd_set_param env PORT="$PORT" procd_set_param env PORT="$PORT"
procd_set_param env KEY="$KEY" procd_set_param env KEY="$KEY"
procd_set_param stdout 1 procd_set_param stdout 1
procd_set_param stdout 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
} }

View File

@@ -2,32 +2,56 @@
# Check if running as root # Check if running as root
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
if command -v sudo >/dev/null 2>&1; then if command -v sudo >/dev/null 2>&1; then
exec sudo "$0" "$@" exec sudo "$0" "$@"
else else
echo "This script must be run as root. Please either:" echo "This script must be run as root. Please either:"
echo "1. Run this script as root (su root)" echo "1. Run this script as root (su root)"
echo "2. Install sudo and run with sudo" echo "2. Install sudo and run with sudo"
exit 1 exit 1
fi fi
fi fi
# Define default values
version=0.0.1 version=0.0.1
PORT=8090 # Default port PORT=8090 # Default port
GITHUB_PROXY_URL="https://ghfast.top/" # Default proxy URL
# Function to ensure the proxy URL ends with a /
ensure_trailing_slash() {
if [ -n "$1" ]; then
case "$1" in
*/) echo "$1" ;;
*) echo "$1/" ;;
esac
else
echo "$1"
fi
}
# Ensure the proxy URL ends with a /
GITHUB_PROXY_URL=$(ensure_trailing_slash "$GITHUB_PROXY_URL")
# Read command line options # Read command line options
while getopts ":uhp:" opt; do while getopts ":uhp:c:" opt; do
case $opt in case $opt in
u) UNINSTALL="true";; u) UNINSTALL="true" ;;
h) printf "Beszel Hub installation script\n\n"; h)
printf "Usage: ./install-hub.sh [options]\n\n"; printf "Beszel Hub installation script\n\n"
printf "Options: \n" printf "Usage: ./install-hub.sh [options]\n\n"
printf " -u : Uninstall the Beszel Hub\n"; printf "Options: \n"
printf " -p <port> : Specify a port number (default: 8090)\n"; printf " -u : Uninstall the Beszel Hub\n"
echo " -h : Display this help message"; printf " -p <port> : Specify a port number (default: 8090)\n"
exit 0;; printf " -c <url> : Use a custom GitHub mirror URL (e.g., https://ghfast.top/)\n"
p) PORT=$OPTARG;; echo " -h : Display this help message"
\?) echo "Invalid option: -$OPTARG"; exit 1;; exit 0
;;
p) PORT=$OPTARG ;;
c) GITHUB_PROXY_URL=$(ensure_trailing_slash "$OPTARG") ;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
esac esac
done done
@@ -81,14 +105,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
if ! id -u beszel > /dev/null 2>&1; then if ! id -u beszel >/dev/null 2>&1; then
echo "Creating a dedicated user for the Beszel Hub service..." echo "Creating a dedicated user for the Beszel Hub service..."
useradd -M -s /bin/false beszel useradd -M -s /bin/false beszel
fi fi
# Download and install the Beszel Hub # Download and install the Beszel Hub
echo "Downloading and installing the Beszel Hub..." echo "Downloading and installing the Beszel Hub..."
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel | tee ./beszel >/dev/null && chmod +x beszel curl -sL "${GITHUB_PROXY_URL}https://github.com/henrygd/beszel/releases/latest/download/beszel_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel | tee ./beszel >/dev/null && chmod +x beszel
mkdir -p /opt/beszel/beszel_data mkdir -p /opt/beszel/beszel_data
mv ./beszel /opt/beszel/beszel mv ./beszel /opt/beszel/beszel
chown -R beszel:beszel /opt/beszel chown -R beszel:beszel /opt/beszel