#!/bin/bash # Integrated CRM Application Build Script # Uses local modules from ~/repos instead of cloning from git set -e APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPOS_DIR="$HOME/repos" echo "Building Integrated CRM Application at: $APP_DIR" echo "Using local modules from: $REPOS_DIR" # Step 1: Create required directories mkdir -p "$APP_DIR/pkgs" mkdir -p "$APP_DIR/logs" mkdir -p "$APP_DIR/files" mkdir -p "$APP_DIR/wwwroot" # Step 2: Setup Python virtual environment if [ ! -d "$APP_DIR/py3" ]; then echo "Creating Python virtual environment..." python3 -m venv "$APP_DIR/py3" fi source "$APP_DIR/py3/bin/activate" # Step 3: Install core dependencies echo "Installing core dependencies..." pip install --quiet git+https://git.opencomputing.cn/yumoqing/apppublic pip install --quiet git+https://git.opencomputing.cn/yumoqing/sqlor pip install --quiet git+https://git.opencomputing.cn/yumoqing/ahserver pip install --quiet xls2ddl # Step 4: Install local modules from ~/repos echo "Installing local modules..." MODULES="apppublic sqlor ahserver appbase rbac customer_management opportunity_management contract_management financial_management workflow_approval unified_dashboard bricks" for module in $MODULES; do MOD_DIR="$REPOS_DIR/$module" if [ -d "$MOD_DIR" ]; then echo " Installing $module from $MOD_DIR..." # Create symlink in pkgs for consistency ln -sf "$MOD_DIR" "$APP_DIR/pkgs/$module" pip install -e "$MOD_DIR" --quiet 2>/dev/null || echo " (pip install failed for $module, may be a non-package module)" else echo " WARNING: Module $module not found at $MOD_DIR" fi done # Step 5: Generate database DDL for all modules with models/ echo "Generating database DDL..." # Collect all DDL into a single file > "$APP_DIR/integrated_crm_app_schema.sql" for module in appbase rbac customer_management opportunity_management contract_management financial_management workflow_approval unified_dashboard; do MOD_DIR="$APP_DIR/pkgs/$module" if [ -d "$MOD_DIR/models" ]; then echo " Processing models for $module..." cd "$MOD_DIR/models" # Check for .xlsx files first if ls *.xlsx >/dev/null 2>&1; then xls2ddl mysql . > "$MOD_DIR/mysql.ddl.sql" 2>/dev/null || true # Check for .json files elif ls *.json >/dev/null 2>&1; then json2ddl mysql . > "$MOD_DIR/mysql.ddl.sql" 2>/dev/null || true fi # Append to combined schema if DDL was generated if [ -f "$MOD_DIR/mysql.ddl.sql" ] && [ -s "$MOD_DIR/mysql.ddl.sql" ]; then echo "-- Module: $module" >> "$APP_DIR/integrated_crm_app_schema.sql" cat "$MOD_DIR/mysql.ddl.sql" >> "$APP_DIR/integrated_crm_app_schema.sql" echo "" >> "$APP_DIR/integrated_crm_app_schema.sql" echo " Generated DDL for $module" else echo " No DDL generated for $module (using existing mysql.ddl.sql if available)" if [ -f "$MOD_DIR/mysql.ddl.sql" ] && [ -s "$MOD_DIR/mysql.ddl.sql" ]; then echo "-- Module: $module" >> "$APP_DIR/integrated_crm_app_schema.sql" cat "$MOD_DIR/mysql.ddl.sql" >> "$APP_DIR/integrated_crm_app_schema.sql" echo "" >> "$APP_DIR/integrated_crm_app_schema.sql" fi fi fi done echo "Combined schema written to: $APP_DIR/integrated_crm_app_schema.sql" wc -l "$APP_DIR/integrated_crm_app_schema.sql" # Step 6: Generate CRUD UI for all modules with json/ echo "Generating CRUD UI..." for module in appbase rbac customer_management opportunity_management contract_management financial_management workflow_approval unified_dashboard; do MOD_DIR="$APP_DIR/pkgs/$module" if [ -d "$MOD_DIR/json" ] && [ -d "$MOD_DIR/models" ]; then echo " Generating UI for $module..." cd "$MOD_DIR/json" # Get list of json files (excluding potential subdirectories) for jsonfile in *.json; do if [ -f "$jsonfile" ]; then xls2ui -m ../models -o ../wwwroot "$module" "$jsonfile" 2>/dev/null || echo " Warning: xls2ui failed for $jsonfile" fi done fi done # Step 7: Create symbolic links for wwwroot echo "Creating wwwroot symbolic links..." mkdir -p "$APP_DIR/wwwroot" for module in appbase rbac customer_management opportunity_management contract_management financial_management workflow_approval unified_dashboard; do MOD_DIR="$APP_DIR/pkgs/$module" if [ -d "$MOD_DIR/wwwroot" ]; then ln -sf "$MOD_DIR/wwwroot" "$APP_DIR/wwwroot/$module" echo " Linked $module/wwwroot" fi done # Step 8: Setup Bricks framework echo "Setting up Bricks framework..." BRICKS_DIR="$REPOS_DIR/bricks" if [ -d "$BRICKS_DIR" ]; then if [ -f "$BRICKS_DIR/build.sh" ]; then echo " Building bricks framework..." cd "$BRICKS_DIR" && ./build.sh fi if [ -d "$BRICKS_DIR/dist" ]; then ln -sf "$BRICKS_DIR/dist" "$APP_DIR/wwwroot/bricks" echo " Linked bricks/dist to wwwroot/bricks" else echo " WARNING: bricks/dist not found" fi else echo " WARNING: bricks module not found at $BRICKS_DIR" fi # Step 9: Create main app wwwroot links echo "Setting up main app wwwroot..." # Link main app wwwroot files if [ -d "$APP_DIR/wwwroot_main" ]; then cp -r "$APP_DIR/wwwroot_main"/* "$APP_DIR/wwwroot/" 2>/dev/null || true fi # Step 10: Create start/stop scripts echo "Creating service scripts..." cat > "$APP_DIR/start.sh" << 'STARTSCRIPT' #!/bin/bash APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$APP_DIR" source "$APP_DIR/py3/bin/activate" export PYTHONPATH="$APP_DIR:$PYTHONPATH" echo "Starting Integrated CRM Application on port 8080..." python app/integrated_crm_app.py --port 8080 --root wwwroot/ STARTSCRIPT cat > "$APP_DIR/stop.sh" << 'STOPSCRIPT' #!/bin/bash pkill -f "integrated_crm_app.py" 2>/dev/null || true echo "Application stopped." STOPSCRIPT chmod +x "$APP_DIR/start.sh" "$APP_DIR/stop.sh" echo "" echo "==========================================" echo "Build completed successfully!" echo "==========================================" echo "" echo "Next steps:" echo "1. Apply database schema:" echo " mysql -u hermes -phermes123 < $APP_DIR/integrated_crm_app_schema.sql" echo "" echo "2. Start the application:" echo " ./start.sh" echo "" echo "3. Access the application:" echo " http://localhost:8080/main/login.ui" echo ""