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:
anonpenguin23 2025-10-26 07:02:25 +02:00
parent 1bc6292db3
commit c315cd4a86
No known key found for this signature in database
GPG Key ID: 1CBB1FE35AFBEE30
2 changed files with 156 additions and 148 deletions

View File

@ -242,9 +242,27 @@ func ensureGo() {
os.Exit(1)
}
// Add to PATH
// Add to PATH for current process
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")
}

View File

@ -1,13 +1,13 @@
#!/bin/bash
# DeBros Network Installation Script (APT-Ready)
# This script installs network-cli and runs the interactive setup command.
# DeBros Network Installation Script
# Downloads network-cli from GitHub releases and runs interactive setup
#
# Supported: Ubuntu 18.04+, Debian 10+
#
# Usage:
# curl -fsSL https://install.debros.network | bash
# OR
# wget -qO- https://install.debros.network | bash
# OR
# bash scripts/install-debros-network.sh
set -e
@ -22,10 +22,9 @@ YELLOW='\033[1;33m'
NOCOLOR='\033[0m'
# Configuration
APT_REPO_URL="https://debros-official.github.io/network/apt"
APT_KEY_URL="${APT_REPO_URL}/pubkey.gpg"
FALLBACK_REPO="https://github.com/DeBrosOfficial/network.git"
FALLBACK_BRANCH="nightly"
GITHUB_REPO="DeBrosOfficial/network"
GITHUB_API="https://api.github.com/repos/$GITHUB_REPO"
INSTALL_DIR="/usr/local/bin"
log() { echo -e "${CYAN}[$(date '+%Y-%m-%d %H:%M:%S')]${NOCOLOR} $1"; }
error() { echo -e "${RED}[ERROR]${NOCOLOR} $1"; }
@ -71,174 +70,131 @@ ${NOCOLOR}"
}
detect_os() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
VERSION=$VERSION_ID
else
if [ ! -f /etc/os-release ]; then
error "Cannot detect operating system"
exit 1
fi
. /etc/os-release
OS=$ID
VERSION=$VERSION_ID
# Only support Debian and Ubuntu
case $OS in
ubuntu|debian) PACKAGE_MANAGER="apt" ;;
centos|rhel|fedora)
PACKAGE_MANAGER="yum"
if command -v dnf &> /dev/null; then PACKAGE_MANAGER="dnf"; fi
ubuntu|debian)
log "Detected OS: $OS ${VERSION:-unknown}"
;;
*)
warning "Unsupported operating system: $OS"
echo -e "${YELLOW}This script is optimized for Ubuntu/Debian.${NOCOLOR}"
echo -e "${YELLOW}Installation will continue but may require manual steps.${NOCOLOR}"
PACKAGE_MANAGER="apt"
*)
error "Unsupported operating system: $OS"
echo -e "${YELLOW}This script only supports Ubuntu 18.04+ and Debian 10+${NOCOLOR}"
exit 1
;;
esac
log "Detected OS: $OS ${VERSION:-unknown}"
}
check_architecture() {
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH_SUPPORTED=true ;;
aarch64|arm64) ARCH_SUPPORTED=true ;;
*)
x86_64)
GITHUB_ARCH="amd64"
;;
aarch64|arm64)
GITHUB_ARCH="arm64"
;;
*)
error "Unsupported architecture: $ARCH"
echo -e "${YELLOW}Supported: x86_64, aarch64/arm64${NOCOLOR}"
exit 1
;;
esac
log "Architecture: $ARCH"
log "Architecture: $ARCH (using $GITHUB_ARCH)"
}
try_install_from_apt() {
log "Checking for APT repository..."
check_dependencies() {
log "Checking required tools..."
# Check if APT repo is available
if curl -fsSL "$APT_KEY_URL" > /dev/null 2>&1; then
log "APT repository found! Installing from APT..."
# Download and add GPG key
curl -fsSL "$APT_KEY_URL" | sudo gpg --dearmor -o /usr/share/keyrings/debros-archive-keyring.gpg
# Add APT source
echo "deb [signed-by=/usr/share/keyrings/debros-archive-keyring.gpg arch=$(dpkg --print-architecture)] $APT_REPO_URL stable main" | \
sudo tee /etc/apt/sources.list.d/debros.list > /dev/null
# Update and install
local missing_deps=()
for cmd in curl tar; do
if ! command -v $cmd &>/dev/null; then
missing_deps+=("$cmd")
fi
done
if [ ${#missing_deps[@]} -gt 0 ]; then
log "Installing missing dependencies: ${missing_deps[*]}"
sudo apt update
sudo apt install -y debros-network-cli
success "network-cli installed from APT"
return 0
else
warning "APT repository not available yet (coming soon!)"
return 1
sudo apt install -y "${missing_deps[@]}"
fi
success "All required tools available"
}
install_from_source() {
log "Installing network-cli from source..."
get_latest_release() {
log "Fetching latest release information..."
# Install build dependencies
log "Installing build dependencies..."
case $PACKAGE_MANAGER in
apt)
sudo apt update
sudo apt install -y git make curl wget build-essential
;;
yum|dnf)
sudo $PACKAGE_MANAGER install -y git make curl wget gcc
;;
esac
# Get latest release (exclude pre-releases and nightly)
LATEST_RELEASE=$(curl -fsSL "$GITHUB_API/releases" | \
grep -v "prerelease.*true" | \
grep -v "draft.*true" | \
grep '"tag_name"' | \
head -1 | \
cut -d'"' -f4)
# Check/Install Go
if ! command -v go &> /dev/null; then
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
if [ -z "$LATEST_RELEASE" ]; then
error "Could not determine latest release"
exit 1
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 ""
log "${BLUE}========================================${NOCOLOR}"
log "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
log "${BLUE}========================================${NOCOLOR}"
echo -e "${BLUE}========================================${NOCOLOR}"
echo -e "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
echo -e "${BLUE}========================================${NOCOLOR}"
echo -e ""
log "The setup command will:"
@ -260,13 +216,15 @@ main() {
echo -e "${CYAN}To complete setup later, run:${NOCOLOR}"
echo -e "${GREEN} sudo network-cli setup${NOCOLOR}"
echo -e ""
exit 0
return 0
fi
echo -e ""
log "Running setup (requires sudo)..."
sudo network-cli setup
}
show_completion() {
echo -e ""
echo -e "${BLUE}========================================================================${NOCOLOR}"
success "DeBros Network installation complete!"
@ -287,4 +245,36 @@ main() {
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 "$@"