mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-15 00:58:49 +00:00
feat: enhance installation script for persistent Go setup
- Updated `setup.go` to add Go binary path to the current process and the `debros` user's `.bashrc` for persistent availability. - Implemented error handling for updating `.bashrc` and ensured proper ownership of the file. - Refined `install-debros-network.sh` to improve OS detection, dependency checks, and installation flow, including downloading the latest release of `network-cli` from GitHub. - Streamlined the installation process with clearer logging and error messages, enhancing user experience.
This commit is contained in:
parent
1bc6292db3
commit
c315cd4a86
@ -242,9 +242,27 @@ func ensureGo() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to PATH
|
// Add to PATH for current process
|
||||||
os.Setenv("PATH", os.Getenv("PATH")+":/usr/local/go/bin")
|
os.Setenv("PATH", os.Getenv("PATH")+":/usr/local/go/bin")
|
||||||
|
|
||||||
|
// Also add to debros user's .bashrc for persistent availability
|
||||||
|
debrosHome := "/home/debros"
|
||||||
|
bashrc := debrosHome + "/.bashrc"
|
||||||
|
pathLine := "\nexport PATH=$PATH:/usr/local/go/bin\n"
|
||||||
|
|
||||||
|
// Read existing bashrc
|
||||||
|
existing, _ := os.ReadFile(bashrc)
|
||||||
|
existingStr := string(existing)
|
||||||
|
|
||||||
|
// Add PATH if not already present
|
||||||
|
if !strings.Contains(existingStr, "/usr/local/go/bin") {
|
||||||
|
if err := os.WriteFile(bashrc, []byte(existingStr+pathLine), 0644); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "⚠️ Failed to update debros .bashrc: %v\n", err)
|
||||||
|
}
|
||||||
|
// Fix ownership
|
||||||
|
exec.Command("chown", "debros:debros", bashrc).Run()
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf(" ✓ Go installed\n")
|
fmt.Printf(" ✓ Go installed\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# DeBros Network Installation Script (APT-Ready)
|
# DeBros Network Installation Script
|
||||||
# This script installs network-cli and runs the interactive setup command.
|
# Downloads network-cli from GitHub releases and runs interactive setup
|
||||||
|
#
|
||||||
|
# Supported: Ubuntu 18.04+, Debian 10+
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# curl -fsSL https://install.debros.network | bash
|
# curl -fsSL https://install.debros.network | bash
|
||||||
# OR
|
# OR
|
||||||
# wget -qO- https://install.debros.network | bash
|
|
||||||
# OR
|
|
||||||
# bash scripts/install-debros-network.sh
|
# bash scripts/install-debros-network.sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@ -22,10 +22,9 @@ YELLOW='\033[1;33m'
|
|||||||
NOCOLOR='\033[0m'
|
NOCOLOR='\033[0m'
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
APT_REPO_URL="https://debros-official.github.io/network/apt"
|
GITHUB_REPO="DeBrosOfficial/network"
|
||||||
APT_KEY_URL="${APT_REPO_URL}/pubkey.gpg"
|
GITHUB_API="https://api.github.com/repos/$GITHUB_REPO"
|
||||||
FALLBACK_REPO="https://github.com/DeBrosOfficial/network.git"
|
INSTALL_DIR="/usr/local/bin"
|
||||||
FALLBACK_BRANCH="nightly"
|
|
||||||
|
|
||||||
log() { echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')]${NOCOLOR} $1"; }
|
log() { echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')]${NOCOLOR} $1"; }
|
||||||
error() { echo -e "${RED}[ERROR]${NOCOLOR} $1"; }
|
error() { echo -e "${RED}[ERROR]${NOCOLOR} $1"; }
|
||||||
@ -71,174 +70,131 @@ ${NOCOLOR}"
|
|||||||
}
|
}
|
||||||
|
|
||||||
detect_os() {
|
detect_os() {
|
||||||
if [ -f /etc/os-release ]; then
|
if [ ! -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
|
||||||
OS=$ID
|
|
||||||
VERSION=$VERSION_ID
|
|
||||||
else
|
|
||||||
error "Cannot detect operating system"
|
error "Cannot detect operating system"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
. /etc/os-release
|
||||||
|
OS=$ID
|
||||||
|
VERSION=$VERSION_ID
|
||||||
|
|
||||||
|
# Only support Debian and Ubuntu
|
||||||
case $OS in
|
case $OS in
|
||||||
ubuntu|debian) PACKAGE_MANAGER="apt" ;;
|
ubuntu|debian)
|
||||||
centos|rhel|fedora)
|
log "Detected OS: $OS ${VERSION:-unknown}"
|
||||||
PACKAGE_MANAGER="yum"
|
|
||||||
if command -v dnf &> /dev/null; then PACKAGE_MANAGER="dnf"; fi
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warning "Unsupported operating system: $OS"
|
error "Unsupported operating system: $OS"
|
||||||
echo -e "${YELLOW}This script is optimized for Ubuntu/Debian.${NOCOLOR}"
|
echo -e "${YELLOW}This script only supports Ubuntu 18.04+ and Debian 10+${NOCOLOR}"
|
||||||
echo -e "${YELLOW}Installation will continue but may require manual steps.${NOCOLOR}"
|
exit 1
|
||||||
PACKAGE_MANAGER="apt"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
log "Detected OS: $OS ${VERSION:-unknown}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_architecture() {
|
check_architecture() {
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
case $ARCH in
|
case $ARCH in
|
||||||
x86_64) ARCH_SUPPORTED=true ;;
|
x86_64)
|
||||||
aarch64|arm64) ARCH_SUPPORTED=true ;;
|
GITHUB_ARCH="amd64"
|
||||||
*)
|
;;
|
||||||
|
aarch64|arm64)
|
||||||
|
GITHUB_ARCH="arm64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
error "Unsupported architecture: $ARCH"
|
error "Unsupported architecture: $ARCH"
|
||||||
echo -e "${YELLOW}Supported: x86_64, aarch64/arm64${NOCOLOR}"
|
echo -e "${YELLOW}Supported: x86_64, aarch64/arm64${NOCOLOR}"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
log "Architecture: $ARCH"
|
log "Architecture: $ARCH (using $GITHUB_ARCH)"
|
||||||
}
|
}
|
||||||
|
|
||||||
try_install_from_apt() {
|
check_dependencies() {
|
||||||
log "Checking for APT repository..."
|
log "Checking required tools..."
|
||||||
|
|
||||||
# Check if APT repo is available
|
local missing_deps=()
|
||||||
if curl -fsSL "$APT_KEY_URL" > /dev/null 2>&1; then
|
|
||||||
log "APT repository found! Installing from APT..."
|
for cmd in curl tar; do
|
||||||
|
if ! command -v $cmd &>/dev/null; then
|
||||||
# Download and add GPG key
|
missing_deps+=("$cmd")
|
||||||
curl -fsSL "$APT_KEY_URL" | sudo gpg --dearmor -o /usr/share/keyrings/debros-archive-keyring.gpg
|
fi
|
||||||
|
done
|
||||||
# Add APT source
|
|
||||||
echo "deb [signed-by=/usr/share/keyrings/debros-archive-keyring.gpg arch=$(dpkg --print-architecture)] $APT_REPO_URL stable main" | \
|
if [ ${#missing_deps[@]} -gt 0 ]; then
|
||||||
sudo tee /etc/apt/sources.list.d/debros.list > /dev/null
|
log "Installing missing dependencies: ${missing_deps[*]}"
|
||||||
|
|
||||||
# Update and install
|
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y debros-network-cli
|
sudo apt install -y "${missing_deps[@]}"
|
||||||
|
|
||||||
success "network-cli installed from APT"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
warning "APT repository not available yet (coming soon!)"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
success "All required tools available"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_from_source() {
|
get_latest_release() {
|
||||||
log "Installing network-cli from source..."
|
log "Fetching latest release information..."
|
||||||
|
|
||||||
# Install build dependencies
|
# Get latest release (exclude pre-releases and nightly)
|
||||||
log "Installing build dependencies..."
|
LATEST_RELEASE=$(curl -fsSL "$GITHUB_API/releases" | \
|
||||||
case $PACKAGE_MANAGER in
|
grep -v "prerelease.*true" | \
|
||||||
apt)
|
grep -v "draft.*true" | \
|
||||||
sudo apt update
|
grep '"tag_name"' | \
|
||||||
sudo apt install -y git make curl wget build-essential
|
head -1 | \
|
||||||
;;
|
cut -d'"' -f4)
|
||||||
yum|dnf)
|
|
||||||
sudo $PACKAGE_MANAGER install -y git make curl wget gcc
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Check/Install Go
|
if [ -z "$LATEST_RELEASE" ]; then
|
||||||
if ! command -v go &> /dev/null; then
|
error "Could not determine latest release"
|
||||||
log "Installing Go 1.21.6..."
|
|
||||||
GO_ARCH="amd64"
|
|
||||||
if [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then
|
|
||||||
GO_ARCH="arm64"
|
|
||||||
fi
|
|
||||||
GO_TARBALL="go1.21.6.linux-${GO_ARCH}.tar.gz"
|
|
||||||
|
|
||||||
cd /tmp
|
|
||||||
wget -q "https://go.dev/dl/$GO_TARBALL"
|
|
||||||
sudo rm -rf /usr/local/go
|
|
||||||
sudo tar -C /usr/local -xzf "$GO_TARBALL"
|
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
|
||||||
|
|
||||||
# Add to PATH permanently
|
|
||||||
if ! grep -q "/usr/local/go/bin" ~/.bashrc 2>/dev/null; then
|
|
||||||
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
|
|
||||||
fi
|
|
||||||
|
|
||||||
success "Go installed"
|
|
||||||
else
|
|
||||||
log "Go already installed: $(go version)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clone repository
|
|
||||||
TEMP_DIR="/tmp/debros-network-install-$$"
|
|
||||||
log "Cloning DeBros Network repository..."
|
|
||||||
git clone --branch "$FALLBACK_BRANCH" --single-branch "$FALLBACK_REPO" "$TEMP_DIR"
|
|
||||||
cd "$TEMP_DIR"
|
|
||||||
|
|
||||||
# Build network-cli
|
|
||||||
log "Building network-cli..."
|
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
|
||||||
make build
|
|
||||||
|
|
||||||
# Install to /usr/local/bin
|
|
||||||
sudo cp bin/network-cli /usr/local/bin/
|
|
||||||
sudo chmod +x /usr/local/bin/network-cli
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
cd /
|
|
||||||
rm -rf "$TEMP_DIR"
|
|
||||||
|
|
||||||
success "network-cli installed from source"
|
|
||||||
}
|
|
||||||
|
|
||||||
verify_installation() {
|
|
||||||
if command -v network-cli &> /dev/null; then
|
|
||||||
INSTALLED_VERSION=$(network-cli version 2>/dev/null || echo "unknown")
|
|
||||||
success "network-cli is installed: $INSTALLED_VERSION"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
error "network-cli installation failed"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
display_banner
|
|
||||||
|
|
||||||
echo -e ""
|
|
||||||
log "Starting DeBros Network installation..."
|
|
||||||
echo -e ""
|
|
||||||
|
|
||||||
detect_os
|
|
||||||
check_architecture
|
|
||||||
|
|
||||||
echo -e ""
|
|
||||||
log "${BLUE}========================================${NOCOLOR}"
|
|
||||||
log "${GREEN}Step 1: Install network-cli${NOCOLOR}"
|
|
||||||
log "${BLUE}========================================${NOCOLOR}"
|
|
||||||
|
|
||||||
# Try APT first, fallback to source
|
|
||||||
if ! try_install_from_apt; then
|
|
||||||
install_from_source
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Verify installation
|
|
||||||
if ! verify_installation; then
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log "Latest release: $LATEST_RELEASE"
|
||||||
|
}
|
||||||
|
|
||||||
|
download_and_install() {
|
||||||
|
log "Downloading network-cli..."
|
||||||
|
|
||||||
|
# Construct download URL
|
||||||
|
DOWNLOAD_URL="https://github.com/$GITHUB_REPO/releases/download/$LATEST_RELEASE/debros-network_${LATEST_RELEASE#v}_linux_${GITHUB_ARCH}.tar.gz"
|
||||||
|
|
||||||
|
# Create temporary directory
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
trap "rm -rf $TEMP_DIR" EXIT
|
||||||
|
|
||||||
|
# Download
|
||||||
|
log "Downloading from: $DOWNLOAD_URL"
|
||||||
|
if ! curl -fsSL -o "$TEMP_DIR/network-cli.tar.gz" "$DOWNLOAD_URL"; then
|
||||||
|
error "Failed to download network-cli"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract
|
||||||
|
log "Extracting network-cli..."
|
||||||
|
cd "$TEMP_DIR"
|
||||||
|
tar xzf network-cli.tar.gz
|
||||||
|
|
||||||
|
# Install
|
||||||
|
log "Installing to $INSTALL_DIR..."
|
||||||
|
sudo cp network-cli "$INSTALL_DIR/"
|
||||||
|
sudo chmod +x "$INSTALL_DIR/network-cli"
|
||||||
|
|
||||||
|
success "network-cli installed successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_installation() {
|
||||||
|
if command -v network-cli &>/dev/null; then
|
||||||
|
INSTALLED_VERSION=$(network-cli version 2>/dev/null || echo "unknown")
|
||||||
|
success "network-cli is ready: $INSTALLED_VERSION"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
error "network-cli not found in PATH"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_setup() {
|
||||||
echo -e ""
|
echo -e ""
|
||||||
log "${BLUE}========================================${NOCOLOR}"
|
echo -e "${BLUE}========================================${NOCOLOR}"
|
||||||
log "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
|
echo -e "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
|
||||||
log "${BLUE}========================================${NOCOLOR}"
|
echo -e "${BLUE}========================================${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
|
|
||||||
log "The setup command will:"
|
log "The setup command will:"
|
||||||
@ -260,13 +216,15 @@ main() {
|
|||||||
echo -e "${CYAN}To complete setup later, run:${NOCOLOR}"
|
echo -e "${CYAN}To complete setup later, run:${NOCOLOR}"
|
||||||
echo -e "${GREEN} sudo network-cli setup${NOCOLOR}"
|
echo -e "${GREEN} sudo network-cli setup${NOCOLOR}"
|
||||||
echo -e ""
|
echo -e ""
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e ""
|
echo -e ""
|
||||||
log "Running setup (requires sudo)..."
|
log "Running setup (requires sudo)..."
|
||||||
sudo network-cli setup
|
sudo network-cli setup
|
||||||
|
}
|
||||||
|
|
||||||
|
show_completion() {
|
||||||
echo -e ""
|
echo -e ""
|
||||||
echo -e "${BLUE}========================================================================${NOCOLOR}"
|
echo -e "${BLUE}========================================================================${NOCOLOR}"
|
||||||
success "DeBros Network installation complete!"
|
success "DeBros Network installation complete!"
|
||||||
@ -287,4 +245,36 @@ main() {
|
|||||||
echo -e ""
|
echo -e ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
display_banner
|
||||||
|
|
||||||
|
echo -e ""
|
||||||
|
log "Starting DeBros Network installation..."
|
||||||
|
echo -e ""
|
||||||
|
|
||||||
|
detect_os
|
||||||
|
check_architecture
|
||||||
|
check_dependencies
|
||||||
|
|
||||||
|
echo -e ""
|
||||||
|
echo -e "${BLUE}========================================${NOCOLOR}"
|
||||||
|
echo -e "${GREEN}Step 1: Install network-cli${NOCOLOR}"
|
||||||
|
echo -e "${BLUE}========================================${NOCOLOR}"
|
||||||
|
echo -e ""
|
||||||
|
|
||||||
|
get_latest_release
|
||||||
|
download_and_install
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if ! verify_installation; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run setup
|
||||||
|
run_setup
|
||||||
|
|
||||||
|
# Show completion message
|
||||||
|
show_completion
|
||||||
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user