Skip to content

Commit

Permalink
Update build scripts/move main package/add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolyB committed Feb 26, 2025
1 parent 452b901 commit 9e63e80
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 28 deletions.
20 changes: 10 additions & 10 deletions src/main/main.odin → main/main.odin
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import "../core/client"
import "../core/const"
import "../core/engine"
import "../core/engine/config"
import "../core/engine/data"
import "../core/engine/data/metadata"
import "../core/engine/security"
import "../core/server"
import "../core/types"
import "../utils"
import "../src/core/client"
import "../src/core/const"
import "../src/core/engine"
import "../src/core/engine/config"
import "../src/core/engine/data"
import "../src/core/engine/data/metadata"
import "../src/core/engine/security"
import "../src/core/server"
import "../src/core/types"
import "../src/utils"
import "core:fmt"
import "core:strings"
/********************************************************
Expand Down
8 changes: 4 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change to the project root directory
cd "$DIR/.."

# Change to the src directory
cd src

# Print the current directory
# echo "Current directory: $(pwd)"
# Build the project in the src directory
# odin build main
odin build main

# Check if build was successful
if [ $? -eq 0 ]; then
echo "$(tput setaf 2)Build successful$(tput sgr0)"

# Try to create bin directory and move the executable
if mkdir -p ../bin 2>/dev/null && mv main.bin ../bin/ 2>/dev/null; then
if mkdir -p ./bin 2>/dev/null && mv main.bin ./bin/ 2>/dev/null; then
echo "$(tput setaf 2)Successfully moved executable to bin directory$(tput sgr0)"
else
echo "$(tput setaf 1)Could not move executable to bin directory$(tput sgr0)"
Expand Down
10 changes: 5 additions & 5 deletions scripts/build_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Change to the project root directory
cd "$DIR/.."

# Change to the src directory
cd src
# # Change to the src directory
# cd src

# Build the project in the src directory
odin build main
Expand All @@ -25,14 +25,14 @@ if [ $? -eq 0 ]; then
echo "$(tput setaf 2)Build successful$(tput sgr0)"

# Try to create bin directory and move the executable
if mkdir -p ../bin 2>/dev/null && mv main.bin ../bin/ 2>/dev/null; then
cd ../bin
if mkdir -p ./bin 2>/dev/null && mv main.bin ./bin/ 2>/dev/null; then
cd bin
else
echo "$(tput setaf 1)Could not move executable to bin directory. Running from src.$(tput sgr0)"
fi

# Run the program
odin run main
./main.bin

# Capture the exit code
exit_code=$?
Expand Down
123 changes: 123 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash
set -e

# Configuration
PROGRAM_NAME="OstrichDB"
REPO="Solitude-Software-Solutions/OstrichDB"
RELEASE_TAG="Pre_Rel_v0.6.0_dev"
RELEASE_URL="https://github.com/${REPO}/archive/refs/tags/${RELEASE_TAG}.tar.gz"
BUILD_SCRIPT="scripts/build.sh"

echo "============== OstrichDB Installer =============="

# Detect the operating system
OS=$(uname -s)
ARCH=$(uname -m)
echo "Detected system: $OS $ARCH"

# Setup installation directory
INSTALL_DIR="$HOME/.ostrichdb/"
mkdir -p "$INSTALL_DIR"

# Add the installation directory to PATH immediately for this session
export PATH="$INSTALL_DIR:$PATH"

# Ensure that installation directory is in the PATH permanently
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo "Adding $INSTALL_DIR to PATH permanently"

# Determine shell config file
if [[ "$SHELL" == *"bash"* ]]; then
SHELL_CONFIG="$HOME/.bashrc"
elif [[ "$SHELL" == *"zsh"* ]]; then
SHELL_CONFIG="$HOME/.zshrc"
fi

# Add to shell config if not already present
if [[ -f "$SHELL_CONFIG" ]]; then
if ! grep -q "export PATH=\"$INSTALL_DIR:\$PATH\"" "$SHELL_CONFIG"; then
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$SHELL_CONFIG"
echo "Updated $SHELL_CONFIG with PATH information"
fi
else
echo "Warning: Could not determine your shell configuration file."
echo "Please manually add $INSTALL_DIR to your PATH."
fi
fi

# Check for Odin compiler
if ! command -v odin &> /dev/null; then
echo "Error: Odin compiler not found in PATH."
echo "Please install Odin first. You can install it via:"
if [[ "$OS" == "Darwin" ]]; then
echo " - Homebrew: brew install odin"
elif [[ "$OS" == "Linux" ]]; then
echo " - Check your distribution's package manager"
fi
echo " - Or from source: https://github.com/odin-lang/Odin"
exit 1
fi

echo "✓ Odin compiler found"

# Create temporary directory
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"

echo "Downloading $PROGRAM_NAME version $RELEASE_TAG..."
curl -fsSL "$RELEASE_URL" -o "${PROGRAM_NAME}.tar.gz"
tar -xzf "${PROGRAM_NAME}.tar.gz"

# The extraction creates a directory with the release tag
EXTRACT_DIR="OstrichDB-${RELEASE_TAG//\//_}"
cd "$EXTRACT_DIR"

# Check if build script exists
if [ ! -f "$BUILD_SCRIPT" ]; then
echo "Error: Build script not found at expected path: $BUILD_SCRIPT"
echo "The release structure may have changed. Please check the repository."
exit 1
fi

echo "Building $PROGRAM_NAME..."
# Change to the src directory and build
cd src
odin build main

# Check if build was successful
if [ $? -eq 0 ]; then
echo "$(tput setaf 2)Build successful$(tput sgr0)"

# Create bin directory and move the executable
mkdir -p ../bin && mv main.bin ../bin/

# Copy the binary to installation directory
echo "Installing OstrichDB to $INSTALL_DIR/ostrichdb"
cp "../bin/main.bin" "$INSTALL_DIR/ostrichdb"
chmod +x "$INSTALL_DIR/ostrichdb"
else
echo "$(tput setaf 1)Build failed$(tput sgr0)"
exit 1
fi

# Cleanup
cd
rm -rf "$TMP_DIR"

if command -v ostrichdb >/dev/null 2>&1; then
echo "✅ Installation successful!"
echo "OstrichDB has been installed to $INSTALL_DIR/ostrichdb"
echo ""
echo "To start using OstrichDB, open a new terminal and run:"
echo " ostrichdb"
else
echo "Warning: Installation complete, but the 'ostrichdb' command is not in your PATH."
echo "Please restart your terminal or run:"
echo " source $SHELL_CONFIG"
echo ""
echo "Then you can start OstrichDB by running:"
echo " ostrichdb"
fi

echo ""
echo "Thank you for installing OstrichDB!"
35 changes: 35 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Used to run OstrichDB without rebuilding. Mostly used for development purposes.
#Author: Marshall A Burns
#GitHub: @SchoolyB
#License: Apache License 2.0 (see LICENSE file for details)
#Copyright (c) 2024-Present Marshall A Burns and Solitude Software Solutions LLC

# Get the directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Change to the project root directory
cd "$DIR/.."

# Change to the bin directory
cd bin

# Check if the executable exists
if [ -f "main.bin" ]; then
# Run the program
./main.bin

# Capture the exit code
exit_code=$?

# Check the exit code
if [ $exit_code -ne 0 ]; then
echo "$(tput setaf 1)Program exited with code $exit_code$(tput sgr0)"
fi

# Return to the project root directory
cd "$DIR/.."
else
echo "$(tput setaf 1)Executable not found. Please build the project first.$(tput sgr0)"
fi
18 changes: 9 additions & 9 deletions src/core/const/constants.odin
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ File Description:

//PATH CONSTANTS
OST_FFVF_PATH :: "ost_file_format_version.tmp"
OST_TMP_PATH :: "./tmp/"
OST_COLLECTION_PATH :: "./collections/"
OST_SECURE_COLLECTION_PATH :: "./secure/"
OST_BACKUP_PATH :: "./backups/"
OST_CORE_PATH :: "./core/"
OST_CONFIG_PATH :: "./core/config.ost"
OST_ID_PATH :: "./core/ids.ost"
OST_HISTORY_PATH :: "./core/history.ost"
OST_BENCHMARK_PATH :: "./benchmark/"
OST_TMP_PATH :: "tmp/"
OST_COLLECTION_PATH :: "collections/"
OST_SECURE_COLLECTION_PATH :: "secure/"
OST_BACKUP_PATH :: "backups/"
OST_CORE_PATH :: "core/"
OST_CONFIG_PATH :: "core/config.ost"
OST_ID_PATH :: "core/ids.ost"
OST_HISTORY_PATH :: "core/history.ost"
OST_BENCHMARK_PATH :: "benchmark/"
CONFIG_CLUSTER :: "OSTRICH_CONFIGS"
CLUSTER_ID_CLUSTER :: "CLUSTER__IDS"
USER_ID_CLUSTER :: "USER__IDS"
Expand Down

0 comments on commit 9e63e80

Please sign in to comment.