mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 17:59:28 +08:00
Enhance proxy handling in install scripts for GitHub mirrors
This commit is contained in:
@@ -8,12 +8,22 @@ is_openwrt() {
|
||||
cat /etc/os-release | grep -q "OpenWrt"
|
||||
}
|
||||
|
||||
# Function to ensure the proxy URL ends with a /
|
||||
ensure_trailing_slash() {
|
||||
if [ -n "$1" ] && [ "${1: -1}" != "/" ]; then
|
||||
echo "$1/"
|
||||
else
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Define default values
|
||||
PORT=45876
|
||||
UNINSTALL=false
|
||||
CHINA_MAINLAND=false
|
||||
GITHUB_URL="https://github.com"
|
||||
GITHUB_API_URL="https://api.github.com"
|
||||
GITHUB_PROXY_URL="https://ghfast.top/" # Default proxy URL
|
||||
KEY=""
|
||||
|
||||
# Check for help flag first
|
||||
@@ -25,7 +35,8 @@ case "$1" in
|
||||
printf " -k : SSH key (required, or interactive if not provided)\n"
|
||||
printf " -p : Port (default: $PORT)\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"
|
||||
exit 0
|
||||
;;
|
||||
@@ -73,6 +84,10 @@ while [ $# -gt 0 ]; do
|
||||
;;
|
||||
--china-mirrors)
|
||||
CHINA_MAINLAND=true
|
||||
if [ "$2" != "" ] && ! echo "$2" | grep -q '^-'; then
|
||||
GITHUB_PROXY_URL=$(ensure_trailing_slash "$2")
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: $1" >&2
|
||||
@@ -147,14 +162,12 @@ if [ "$UNINSTALL" = true ]; then
|
||||
fi
|
||||
|
||||
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
|
||||
USE_MIRROR=${USE_MIRROR:-Y}
|
||||
if [ "$USE_MIRROR" = "Y" ] || [ "$USE_MIRROR" = "y" ]; then
|
||||
GITHUB_URL="https://ghp.ci/https://github.com"
|
||||
# In China, only github.com is blocked, while api.github.com is not (for now).
|
||||
# GITHUB_API_URL="https://api.github.com"
|
||||
echo "Using GitHub Mirror for downloads..."
|
||||
GITHUB_URL="${GITHUB_PROXY_URL}https://github.com"
|
||||
echo "Using GitHub Mirror ($GITHUB_PROXY_URL) for downloads..."
|
||||
else
|
||||
echo "GitHub mirrors will not be used for installation."
|
||||
fi
|
||||
@@ -385,7 +398,7 @@ start_service() {
|
||||
procd_set_param env PORT="$PORT"
|
||||
procd_set_param env KEY="$KEY"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
|
@@ -12,22 +12,43 @@ if [ "$(id -u)" != "0" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Define default values
|
||||
version=0.0.1
|
||||
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" ] && [ "${1: -1}" != "/" ]; then
|
||||
echo "$1/"
|
||||
else
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ensure the proxy URL ends with a /
|
||||
GITHUB_PROXY_URL=$(ensure_trailing_slash "$GITHUB_PROXY_URL")
|
||||
|
||||
# Read command line options
|
||||
while getopts ":uhp:" opt; do
|
||||
while getopts ":uhp:c:" opt; do
|
||||
case $opt in
|
||||
u) UNINSTALL="true";;
|
||||
h) printf "Beszel Hub installation script\n\n";
|
||||
printf "Usage: ./install-hub.sh [options]\n\n";
|
||||
u) UNINSTALL="true" ;;
|
||||
h)
|
||||
printf "Beszel Hub installation script\n\n"
|
||||
printf "Usage: ./install-hub.sh [options]\n\n"
|
||||
printf "Options: \n"
|
||||
printf " -u : Uninstall the Beszel Hub\n";
|
||||
printf " -p <port> : Specify a port number (default: 8090)\n";
|
||||
echo " -h : Display this help message";
|
||||
exit 0;;
|
||||
p) PORT=$OPTARG;;
|
||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
||||
printf " -u : Uninstall the Beszel Hub\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"
|
||||
echo " -h : Display this help message"
|
||||
exit 0
|
||||
;;
|
||||
p) PORT=$OPTARG ;;
|
||||
c) GITHUB_PROXY_URL=$(ensure_trailing_slash "$OPTARG") ;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -81,14 +102,14 @@ else
|
||||
fi
|
||||
|
||||
# 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..."
|
||||
useradd -M -s /bin/false beszel
|
||||
fi
|
||||
|
||||
# Download and install 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
|
||||
mv ./beszel /opt/beszel/beszel
|
||||
chown -R beszel:beszel /opt/beszel
|
||||
|
Reference in New Issue
Block a user