mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
update linux install scripts to work with other distros
This commit is contained in:
58
supplemental/scripts/install-agent.sh
Normal file → Executable file
58
supplemental/scripts/install-agent.sh
Normal file → Executable file
@@ -9,13 +9,13 @@ while getopts ":k:p:uh" opt; do
|
||||
k) KEY="$OPTARG";;
|
||||
p) PORT="$OPTARG";;
|
||||
u) UNINSTALL="true";;
|
||||
h) echo "Beszel Agent installation script"; echo ""
|
||||
echo "Usage: ./install.sh [options]"; echo ""
|
||||
echo "Options: "
|
||||
echo " -k : SSH key (required, or interactive if not provided)"; echo ""
|
||||
echo " -p : Port (default: $PORT)"; echo ""
|
||||
echo " -u : Uninstall the Beszel Agent"; echo ""
|
||||
echo " -h : Display this help message"; echo ""
|
||||
h) printf "Beszel Agent installation script\n\n"
|
||||
printf "Usage: ./install-agent.sh [options]\n\n"
|
||||
printf "Options: \n"
|
||||
printf " -k : SSH key (required, or interactive if not provided)\n"
|
||||
printf " -p : Port (default: $PORT)\n"
|
||||
printf " -u : Uninstall the Beszel Agent\n"
|
||||
printf " -h : Display this help message\n"
|
||||
exit 0;;
|
||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
||||
esac
|
||||
@@ -45,10 +45,27 @@ if [ "$UNINSTALL" = "true" ]; then
|
||||
|
||||
echo "The Beszel Agent has been uninstalled successfully!"
|
||||
else
|
||||
# Check if the distribution is supported
|
||||
if [ "$(cat /etc/os-release | grep '^ID=')" != "ID=debian" ] && [ "$(cat /etc/os-release | grep '^ID=')" != "ID=ubuntu" ] && [ "$(cat /etc/os-release | grep '^ID_LIKE=')" != "ID_LIKE=debian" ]; then
|
||||
echo "Error: This script only supports Debian and Ubuntu distributions."
|
||||
exit 1
|
||||
# Function to check if a package is installed
|
||||
package_installed() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Check for package manager and install necessary packages if not installed
|
||||
if package_installed apt-get; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tar curl
|
||||
fi
|
||||
elif package_installed yum; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo yum install -y tar curl
|
||||
fi
|
||||
elif package_installed pacman; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo pacman -Sy --noconfirm tar curl
|
||||
fi
|
||||
else
|
||||
echo "Warning: Please ensure 'tar' and 'curl' are installed."
|
||||
fi
|
||||
|
||||
# If no SSH key is provided, ask for the SSH key interactively
|
||||
@@ -56,14 +73,10 @@ else
|
||||
read -p "Enter your SSH key: " KEY
|
||||
fi
|
||||
|
||||
# Check if necessary packages are installed
|
||||
sudo apt update
|
||||
sudo apt install -y tar curl
|
||||
|
||||
# Create a dedicated user for the service if it doesn't exist
|
||||
if ! id -u beszel-agent > /dev/null 2>&1; then
|
||||
if ! id -u beszel > /dev/null 2>&1; then
|
||||
echo "Creating a dedicated user for the Beszel Agent service..."
|
||||
sudo useradd -m -s /bin/false beszel
|
||||
sudo useradd -M -s /bin/false beszel
|
||||
fi
|
||||
|
||||
# Create the directory for the Beszel Agent
|
||||
@@ -76,7 +89,8 @@ else
|
||||
|
||||
# Download and install the Beszel Agent
|
||||
echo "Downloading and installing the Beszel Agent..."
|
||||
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel-agent_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -C /opt/beszel-agent -f - beszel-agent
|
||||
curl -sL "https://github.com/henrygd/beszel/releases/latest/download/beszel-agent_$(uname -s)_$(uname -m | sed 's/x86_64/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/').tar.gz" | tar -xz -O beszel-agent | tee ./beszel-agent >/dev/null
|
||||
sudo mv ./beszel-agent /opt/beszel-agent/beszel-agent
|
||||
sudo chown beszel:beszel /opt/beszel-agent/beszel-agent
|
||||
sudo chmod 755 /opt/beszel-agent/beszel-agent
|
||||
|
||||
@@ -99,16 +113,20 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Load and start the service
|
||||
echo "Loading and starting the Beszel Agent service..."
|
||||
printf "\nLoading and starting the Beszel Agent service...\n"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-agent.service
|
||||
sudo systemctl start beszel-agent.service
|
||||
|
||||
# Wait for the service to start or fail
|
||||
sleep 1
|
||||
|
||||
# Check if the service is running
|
||||
if [ "$(systemctl is-active beszel-agent.service)" != "active" ]; then
|
||||
echo "Error: The Beszel Agent service is not running."
|
||||
echo "$(systemctl status beszel-agent.service)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "The Beszel Agent has been installed and configured successfully! It is now running on port $PORT."
|
||||
fi
|
||||
fi
|
||||
|
60
supplemental/scripts/install-hub.sh
Normal file → Executable file
60
supplemental/scripts/install-hub.sh
Normal file → Executable file
@@ -6,11 +6,11 @@ version=0.0.1
|
||||
while getopts ":uh" opt; do
|
||||
case $opt in
|
||||
u) UNINSTALL="true";;
|
||||
h) echo "Beszel Hub installation script"; echo ""
|
||||
echo "Usage: ./install.sh [options]"; echo ""
|
||||
echo "Options: "
|
||||
echo " -u : Uninstall the Beszel Hub"; echo ""
|
||||
echo " -h : Display this help message"; echo ""
|
||||
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";
|
||||
echo " -h : Display this help message";
|
||||
exit 0;;
|
||||
\?) echo "Invalid option: -$OPTARG"; exit 1;;
|
||||
esac
|
||||
@@ -44,38 +44,52 @@ if [ "$UNINSTALL" = "true" ]; then
|
||||
|
||||
echo "The Beszel Hub has been uninstalled successfully!"
|
||||
else
|
||||
# Check if the distribution is supported
|
||||
if [ "$(cat /etc/os-release | grep '^ID=')" != "ID=debian" ] && [ "$(cat /etc/os-release | grep '^ID=')" != "ID=ubuntu" ] && [ "$(cat /etc/os-release | grep '^ID_LIKE=')" != "ID_LIKE=debian" ]; then
|
||||
echo "Error: This script only supports Debian and Ubuntu distributions."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if necessary packages are installed
|
||||
sudo apt update
|
||||
sudo apt install -y tar curl
|
||||
# Function to check if a package is installed
|
||||
package_installed() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Create a dedicated user for the service
|
||||
# Check for package manager and install necessary packages if not installed
|
||||
if package_installed apt-get; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tar curl
|
||||
fi
|
||||
elif package_installed yum; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo yum install -y tar curl
|
||||
fi
|
||||
elif package_installed pacman; then
|
||||
if ! package_installed tar || ! package_installed curl; then
|
||||
sudo pacman -Sy --noconfirm tar curl
|
||||
fi
|
||||
else
|
||||
echo "Warning: Please ensure 'tar' and 'curl' are installed."
|
||||
fi
|
||||
|
||||
# Create a dedicated user for the service if it doesn't exist
|
||||
if ! id -u beszel > /dev/null 2>&1; then
|
||||
echo "Creating a dedicated user for the Beszel Hub service..."
|
||||
sudo useradd -m -s /bin/false beszel
|
||||
sudo 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
|
||||
sudo mkdir -p /opt/beszel
|
||||
sudo mkdir -p /opt/beszel/beszel_data
|
||||
sudo mv ./beszel /opt/beszel/beszel
|
||||
sudo chown beszel:beszel /opt/beszel/beszel
|
||||
sudo chown -R beszel:beszel /opt/beszel
|
||||
|
||||
# Create the systemd service
|
||||
echo "Creating the systemd service for the Beszel Hub..."
|
||||
printf "Creating the systemd service for the Beszel Hub...\n\n"
|
||||
sudo tee /etc/systemd/system/beszel-hub.service <<EOF
|
||||
[Unit]
|
||||
Description=Beszel Hub Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/beszel/beszel
|
||||
ExecStart=/opt/beszel/beszel serve
|
||||
WorkingDirectory=/opt/beszel
|
||||
User=beszel
|
||||
Restart=always
|
||||
|
||||
@@ -84,14 +98,18 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Load and start the service
|
||||
echo "Loading and starting the Beszel Hub service..."
|
||||
printf "\nLoading and starting the Beszel Hub service...\n"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable beszel-hub.service
|
||||
sudo systemctl start beszel-hub.service
|
||||
|
||||
# Wait for the service to start or fail
|
||||
sleep 2
|
||||
|
||||
# Check if the service is running
|
||||
if [ "$(systemctl is-active beszel-hub.service)" != "active" ]; then
|
||||
echo "Error: The Beszel Hub service is not running."
|
||||
echo "$(systemctl status beszel-hub.service)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user