Skip to content

Run script for linux easy installation #21

@kadavilrahul

Description

@kadavilrahul

I have made shellscript run.sh for easy installation on linux. Kindly consider adding it.

#!/bin/bash

run.sh: Build and run script for Tablecruncher on Linux

Use it on a machine with display

This script automates the build process for Tablecruncher on Linux systems.

============================================================================

CONFIGURATION & ENVIRONMENT VARIABLES

============================================================================

Auto-detect project root and change to it

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_ROOT"

BUILD_DIR="$PROJECT_ROOT/build"
FLTK_PATH_FILE="$PROJECT_ROOT/.fltk_path"
DEPS_OK=false

============================================================================

UTILITY FUNCTIONS

============================================================================

print_success() { echo -e "\033[0;32m✅ $1\033[0m"; }
print_error() { echo -e "\033[0;31m❌ $1\033[0m"; }
print_warning() { echo -e "\033[0;33m⚠️ $1\033[0m"; }
print_info() { echo -e "\033[0;34mℹ️ $1\033[0m"; }

command_exists() {
command -v "$1" >/dev/null 2>&1
}

confirm() {
read -r -p "${1:-Are you sure?} [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}

============================================================================

DEPENDENCY CHECKS

============================================================================

check_dependencies() {
local missing_deps=()
local required_tools=("g++" "cmake" "make" "wget")

for tool in "${required_tools[@]}"; do
    if ! command_exists "$tool"; then
        missing_deps+=("$tool")
    fi
done

if [ ${#missing_deps[@]} -ne 0 ]; then
    DEPS_OK=false
    return 1
else
    DEPS_OK=true
    return 0
fi

}

============================================================================

CORE OPERATIONS

============================================================================

install_dependencies() {
print_info "Detecting Linux distribution..."
local install_cmd=""
if command_exists dnf; then
print_info "Fedora-based system detected."
install_cmd="sudo dnf install gcc-c++ cmake make git wget libX11-devel libXft-devel"
elif command_exists apt; then
print_info "Debian/Ubuntu-based system detected."
install_cmd="sudo apt install g++ cmake make wget libx11-dev libxft-dev"
else
print_error "Could not detect package manager (dnf/apt)."
print_warning "Please install the C++ toolchain, CMake, Make, wget, and development files for X11 and Xft manually."
return 1
fi

print_info "The following command will be executed:"
echo "$install_cmd"

if confirm "Do you want to run this command now?"; then
    eval "$install_cmd"
    print_info "Re-checking dependencies..."
    if check_dependencies; then
        print_success "All dependencies are now installed."
    else
        print_error "Some dependencies are still missing. Please try installing them manually."
    fi
else
    print_info "Installation cancelled."
fi

}

build_fltk() {
if ! $DEPS_OK; then
print_error "Dependencies are missing. Please run option 1 first."
return 1
fi

print_info "Building FLTK library..."

# Check if FLTK is already built and path is saved
if [ -f "$FLTK_PATH_FILE" ]; then
    local existing_path
    existing_path=$(cat "$FLTK_PATH_FILE")
    if [ -d "$existing_path" ] && [ -f "$existing_path/lib/libfltk.a" ]; then
        print_success "FLTK is already built at: $existing_path"
        if confirm "Do you want to rebuild FLTK?"; then
            print_info "Rebuilding FLTK..."
        else
            print_info "Using existing FLTK build."
            return 0
        fi
    fi
fi

# Set FLTK version and download URL
local FLTK_VERSION="1.4.4"
local FLTK_TAR="fltk-$FLTK_VERSION-source.tar.gz"
local FLTK_URL="https://www.fltk.org/pub/fltk/$FLTK_VERSION/$FLTK_TAR"
local FLTK_DIR="fltk-$FLTK_VERSION"

# Alternative URL if the primary one fails
local FLTK_ALT_URL="https://github.com/fltk/fltk/releases/download/release-$FLTK_VERSION/$FLTK_TAR"

# Check if FLTK source already exists
if [ ! -d "$FLTK_DIR" ]; then
    print_info "Downloading FLTK $FLTK_VERSION..."
    local download_success=false
    
    if command_exists wget; then
        print_info "Trying primary URL..."
        wget "$FLTK_URL" -O "$FLTK_TAR" && download_success=true
        
        if [ $? -ne 0 ]; then
            print_warning "Primary URL failed, trying alternative URL..."
            wget "$FLTK_ALT_URL" -O "$FLTK_TAR" && download_success=true
        fi
    elif command_exists curl; then
        print_info "Trying primary URL..."
        curl -L "$FLTK_URL" -o "$FLTK_TAR" && download_success=true
        
        if [ $? -ne 0 ]; then
            print_warning "Primary URL failed, trying alternative URL..."
            curl -L "$FLTK_ALT_URL" -o "$FLTK_TAR" && download_success=true
        fi
    else
        print_error "Neither wget nor curl found. Please install one of them."
        return 1
    fi
    
    if ! $download_success; then
        print_error "Failed to download FLTK from both URLs."
        print_info "You can manually download FLTK from: https://www.fltk.org/software.php"
        return 1
    fi
    
    print_info "Extracting FLTK..."
    tar -xzf "$FLTK_TAR"
    if [ $? -ne 0 ]; then
        print_error "Failed to extract FLTK archive."
        return 1
    fi
    
    # Clean up the downloaded archive
    rm -f "$FLTK_TAR"
else
    print_info "FLTK source directory already exists: $FLTK_DIR"
fi

cd "$FLTK_DIR" || return 1

# Clean previous build if it exists
if [ -f "Makefile" ]; then
    print_info "Cleaning previous FLTK build..."
    make clean
fi

print_info "Configuring FLTK..."
./configure --enable-localzlib --disable-wayland
if [ $? -ne 0 ]; then
    print_error "FLTK configuration failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_info "Compiling FLTK... (This may take a while)"
make -j$(nproc)
if [ $? -ne 0 ]; then
    print_error "FLTK build failed."
    cd "$PROJECT_ROOT"
    return 1
fi

# Save the absolute path
local fltk_abs_path
fltk_abs_path="$(pwd)"
echo "$fltk_abs_path" > "$FLTK_PATH_FILE"
print_success "FLTK built successfully at: $fltk_abs_path"
print_success "Path saved for future operations."
cd "$PROJECT_ROOT"

}

build_tablecruncher() {
if ! $DEPS_OK; then
print_error "Dependencies are missing. Please run option 1 first."
return 1
fi
if [ ! -f "$FLTK_PATH_FILE" ]; then
print_error "FLTK path not set. Please build FLTK first (Option 2)."
return 1
fi
local fltk_path
fltk_path=$(cat "$FLTK_PATH_FILE")
print_info "Building Tablecruncher using FLTK from: $fltk_path"

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || return 1

print_info "Running CMake to configure the project..."
cmake -DFLTKDIR="$fltk_path" ..
if [ $? -ne 0 ]; then
    print_error "CMake configuration failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_info "Compiling Tablecruncher..."
cmake --build . -- -j$(nproc)
if [ $? -ne 0 ]; then
    print_error "Tablecruncher build failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_success "Tablecruncher built successfully in '$BUILD_DIR'."
cd "$PROJECT_ROOT"

}

build_appimage() {
if ! $DEPS_OK; then
print_error "Dependencies are missing. Please run option 1 first."
return 1
fi
if [ ! -f "$FLTK_PATH_FILE" ]; then
print_error "FLTK path not set. Please build FLTK first (Option 2)."
return 1
fi
local fltk_path
fltk_path=$(cat "$FLTK_PATH_FILE")
print_info "Building AppImage using FLTK from: $fltk_path"

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || return 1

print_info "Running CMake for AppImage..."
cmake -DFLTKDIR="$fltk_path" -DAPPIMAGE=1 ..
 if [ $? -ne 0 ]; then
    print_error "CMake configuration for AppImage failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_info "Compiling Tablecruncher for AppImage..."
cmake --build . -- -j$(nproc)
if [ $? -ne 0 ]; then
    print_error "AppImage build failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_info "Running the AppImage packaging script..."
cd "$PROJECT_ROOT/scripts" || return 1
./build_appimage.sh
if [ $? -ne 0 ]; then
    print_error "AppImage packaging script failed."
    cd "$PROJECT_ROOT"
    return 1
fi

print_success "AppImage created successfully in '$PROJECT_ROOT/build'."
cd "$PROJECT_ROOT"

}

run_app() {
local app_path="$BUILD_DIR/dist/Tablecruncher"
if [ -f "$app_path" ]; then
print_info "Starting Tablecruncher..."
"$app_path"
else
print_error "Tablecruncher executable not found. Please build it first (Option 3)."
fi
}

clean() {
print_info "Cleaning build artifacts..."
if [ -d "$BUILD_DIR" ]; then
if confirm "This will remove the '$BUILD_DIR' directory. Are you sure?"; then
rm -rf "$BUILD_DIR"
print_success "Build directory cleaned."
else
print_info "Clean operation cancelled."
fi
else
print_info "Build directory not found, nothing to clean."
fi
}

============================================================================

INTERACTIVE MENU

============================================================================

show_menu() {
clear
echo "========================================"
echo " Tablecruncher Control Panel "
echo "========================================"
echo ""
if ! $DEPS_OK; then
print_warning "Dependencies are missing. Please run option 1."
echo ""
fi
echo " 1. Install/Check Dependencies"
echo " 2. Build FLTK (Required First Step)"
echo " 3. Build Tablecruncher"
echo " 4. Run Tablecruncher"
echo " 5. Build AppImage Package"
echo " 6. Clean Build Directory"
echo ""
echo " 0. Exit"
echo ""
printf "Select option: "
}

handle_choice() {
case "$1" in
1) install_dependencies ;;
2) build_fltk ;;
3) build_tablecruncher ;;
4) run_app ;;
5) build_appimage ;;
6) clean ;;
0) print_success "Exiting."; exit 0 ;;
*) print_error "Invalid option. Please try again." ;;
esac
echo ""
read -p "Press Enter to continue..."
}

============================================================================

MAIN EXECUTION

============================================================================

Initial dependency check

check_dependencies

Handle command-line arguments

if [ -n "$1" ]; then
if ! $DEPS_OK && [[ "$1" != "install" ]]; then
print_error "Dependencies are missing. Please run './run.sh install' first."
exit 1
fi
case "$1" in
install) install_dependencies ;;
build_fltk) build_fltk ;;
build) build_tablecruncher ;;
run) run_app ;;
appimage) build_appimage ;;
clean) clean ;;
*)
print_error "Unknown command: $1"
echo "Usage: ./run.sh [install|build_fltk|build|run|appimage|clean]"
exit 1
;;
esac
exit 0
fi

No arguments - show interactive menu

while true; do
show_menu
read -r choice
handle_choice "$choice"
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions