This commit is contained in:
56
install.sh
56
install.sh
@@ -5,6 +5,8 @@
|
|||||||
#
|
#
|
||||||
# Usage: sudo ./install.sh [options]
|
# Usage: sudo ./install.sh [options]
|
||||||
#
|
#
|
||||||
|
# Note: Run this script from the atlas repository root directory
|
||||||
|
#
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ HTTP_ADDR=":8080"
|
|||||||
DB_PATH="/var/lib/atlas/atlas.db"
|
DB_PATH="/var/lib/atlas/atlas.db"
|
||||||
BUILD_BINARIES=true
|
BUILD_BINARIES=true
|
||||||
SKIP_DEPS=false
|
SKIP_DEPS=false
|
||||||
|
REPO_DIR=""
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
@@ -49,6 +52,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
HTTP_ADDR="$2"
|
HTTP_ADDR="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--repo-dir)
|
||||||
|
REPO_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "AtlasOS Installation Script"
|
echo "AtlasOS Installation Script"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -60,6 +67,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
echo " --skip-deps Skip dependency installation"
|
echo " --skip-deps Skip dependency installation"
|
||||||
echo " --skip-build Skip building binaries (use existing)"
|
echo " --skip-build Skip building binaries (use existing)"
|
||||||
echo " --http-addr ADDR HTTP address (default: :8080)"
|
echo " --http-addr ADDR HTTP address (default: :8080)"
|
||||||
|
echo " --repo-dir DIR Repository directory (if not in current dir)"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@@ -76,6 +84,9 @@ if [[ $EUID -ne 0 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get script directory early (for path resolution)
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# Detect distribution
|
# Detect distribution
|
||||||
detect_distro() {
|
detect_distro() {
|
||||||
if [[ -f /etc/os-release ]]; then
|
if [[ -f /etc/os-release ]]; then
|
||||||
@@ -204,16 +215,49 @@ build_binaries() {
|
|||||||
|
|
||||||
echo -e "${GREEN}Building binaries...${NC}"
|
echo -e "${GREEN}Building binaries...${NC}"
|
||||||
|
|
||||||
# Get script directory
|
# Check if we're in the right directory
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
# Use REPO_DIR if specified, otherwise try current directory, then script directory
|
||||||
cd "$SCRIPT_DIR"
|
if [[ -n "$REPO_DIR" ]] && [[ -d "$REPO_DIR/cmd" ]] && [[ -f "$REPO_DIR/cmd/atlas-api/main.go" ]]; then
|
||||||
|
BUILD_DIR="$(cd "$REPO_DIR" && pwd)"
|
||||||
|
elif [[ -d "./cmd" ]] && [[ -f "./cmd/atlas-api/main.go" ]]; then
|
||||||
|
BUILD_DIR="$(pwd)"
|
||||||
|
elif [[ -d "$SCRIPT_DIR/cmd" ]] && [[ -f "$SCRIPT_DIR/cmd/atlas-api/main.go" ]]; then
|
||||||
|
BUILD_DIR="$SCRIPT_DIR"
|
||||||
|
elif [[ -d "$SCRIPT_DIR/../cmd" ]] && [[ -f "$SCRIPT_DIR/../cmd/atlas-api/main.go" ]]; then
|
||||||
|
BUILD_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
else
|
||||||
|
echo -e "${RED}Error: Cannot find source code directory${NC}"
|
||||||
|
echo " Current directory: $(pwd)"
|
||||||
|
echo " Script directory: $SCRIPT_DIR"
|
||||||
|
echo " Looking for: cmd/atlas-api/main.go"
|
||||||
|
echo ""
|
||||||
|
echo " Please ensure you're running the installer from the atlas repository root"
|
||||||
|
echo " Or specify the repository path with: --repo-dir /path/to/atlas"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$BUILD_DIR"
|
||||||
|
echo "Building from: $(pwd)"
|
||||||
|
|
||||||
|
# Verify source files exist
|
||||||
|
if [[ ! -f "$BUILD_DIR/cmd/atlas-api/main.go" ]]; then
|
||||||
|
echo -e "${RED}Error: Cannot find cmd/atlas-api/main.go${NC}"
|
||||||
|
echo " Expected at: $BUILD_DIR/cmd/atlas-api/main.go"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Build binaries
|
# Build binaries
|
||||||
echo "Building atlas-api..."
|
echo "Building atlas-api..."
|
||||||
go build -o "$INSTALL_DIR/bin/atlas-api" ./cmd/atlas-api
|
if ! go build -o "$INSTALL_DIR/bin/atlas-api" ./cmd/atlas-api; then
|
||||||
|
echo -e "${RED}Error: Failed to build atlas-api${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Building atlas-tui..."
|
echo "Building atlas-tui..."
|
||||||
go build -o "$INSTALL_DIR/bin/atlas-tui" ./cmd/atlas-tui
|
if ! go build -o "$INSTALL_DIR/bin/atlas-tui" ./cmd/atlas-tui; then
|
||||||
|
echo -e "${RED}Error: Failed to build atlas-tui${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Set permissions
|
# Set permissions
|
||||||
chown root:root "$INSTALL_DIR/bin/atlas-api"
|
chown root:root "$INSTALL_DIR/bin/atlas-api"
|
||||||
@@ -221,7 +265,7 @@ build_binaries() {
|
|||||||
chmod 755 "$INSTALL_DIR/bin/atlas-api"
|
chmod 755 "$INSTALL_DIR/bin/atlas-api"
|
||||||
chmod 755 "$INSTALL_DIR/bin/atlas-tui"
|
chmod 755 "$INSTALL_DIR/bin/atlas-tui"
|
||||||
|
|
||||||
echo -e "${GREEN}Binaries built${NC}"
|
echo -e "${GREEN}Binaries built successfully${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create systemd service
|
# Create systemd service
|
||||||
|
|||||||
Reference in New Issue
Block a user