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) 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")
} }

View File

@ -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..."
# Download and add GPG key for cmd in curl tar; do
curl -fsSL "$APT_KEY_URL" | sudo gpg --dearmor -o /usr/share/keyrings/debros-archive-keyring.gpg if ! command -v $cmd &>/dev/null; then
missing_deps+=("$cmd")
# 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
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
fi fi
done
if [ ${#missing_deps[@]} -gt 0 ]; then
log "Installing missing dependencies: ${missing_deps[*]}"
sudo apt update
sudo apt install -y "${missing_deps[@]}"
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..." exit 1
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 fi
success "Go installed" log "Latest release: $LATEST_RELEASE"
else }
log "Go already installed: $(go version)"
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 fi
# Clone repository # Extract
TEMP_DIR="/tmp/debros-network-install-$$" log "Extracting network-cli..."
log "Cloning DeBros Network repository..."
git clone --branch "$FALLBACK_BRANCH" --single-branch "$FALLBACK_REPO" "$TEMP_DIR"
cd "$TEMP_DIR" cd "$TEMP_DIR"
tar xzf network-cli.tar.gz
# Build network-cli # Install
log "Building network-cli..." log "Installing to $INSTALL_DIR..."
export PATH=$PATH:/usr/local/go/bin sudo cp network-cli "$INSTALL_DIR/"
make build sudo chmod +x "$INSTALL_DIR/network-cli"
# Install to /usr/local/bin success "network-cli installed successfully"
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() { verify_installation() {
if command -v network-cli &>/dev/null; then if command -v network-cli &>/dev/null; then
INSTALLED_VERSION=$(network-cli version 2>/dev/null || echo "unknown") INSTALLED_VERSION=$(network-cli version 2>/dev/null || echo "unknown")
success "network-cli is installed: $INSTALLED_VERSION" success "network-cli is ready: $INSTALLED_VERSION"
return 0 return 0
else else
error "network-cli installation failed" error "network-cli not found in PATH"
return 1 return 1
fi fi
} }
main() { run_setup() {
display_banner
echo -e "" echo -e ""
log "Starting DeBros Network installation..." echo -e "${BLUE}========================================${NOCOLOR}"
echo -e "" echo -e "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
echo -e "${BLUE}========================================${NOCOLOR}"
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
fi
echo -e ""
log "${BLUE}========================================${NOCOLOR}"
log "${GREEN}Step 2: Run Interactive Setup${NOCOLOR}"
log "${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 "$@"