|
| 1 | +#!/bin/bash |
| 2 | +# Default values |
| 3 | +DEFAULT |
| 4 | +_PATH="/home/runner/work/OpenAI-API-dotnet/OpenAI-API-dotnet/package.json" |
| 5 | +FALLBACK |
| 6 | +_DIR="/home/runner/work/OpenAI-API-dotnet/OpenAI-API-dotnet/" |
| 7 | +LOG |
| 8 | +FILE="install |
| 9 | +_ |
| 10 | +_log.txt" |
| 11 | +# Function to log messages |
| 12 | +log_message() { |
| 13 | +local message="$1" |
| 14 | +echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" >> "$LOG |
| 15 | +FILE" |
| 16 | +_ |
| 17 | +} |
| 18 | +# Function to check if a file exists |
| 19 | +file |
| 20 | +_exists() { |
| 21 | +[ -f "$1" ] |
| 22 | +} |
| 23 | +# Function to find package.json in a directory |
| 24 | +find |
| 25 | +_package_json() { |
| 26 | +local search |
| 27 | +dir="$1" |
| 28 | +_ |
| 29 | +find "$search |
| 30 | +_dir" -name "package.json" -print -quit |
| 31 | +} |
| 32 | +# Main script |
| 33 | +log_message "Starting path correction and installation process..." |
| 34 | +# Check if package.json exists at the default path |
| 35 | +if file |
| 36 | +exists "$DEFAULT |
| 37 | +_ |
| 38 | +_PATH"; then |
| 39 | +log_message "package.json found at $DEFAULT |
| 40 | +_ |
| 41 | +PATH." |
| 42 | +else |
| 43 | +log_message "package.json not found at $DEFAULT |
| 44 | +_ |
| 45 | +PATH." |
| 46 | +# Attempt to locate package.json in the fallback directory |
| 47 | +log_message "Searching for package.json in fallback directory $FALLBACK |
| 48 | +_ |
| 49 | +PACKAGE |
| 50 | +JSON |
| 51 | +_ |
| 52 | +_ |
| 53 | +PATH=$(find_package_json "$FALLBACK |
| 54 | +_DIR") |
| 55 | +DIR..." |
| 56 | +if [ -n "$PACKAGE |
| 57 | +JSON |
| 58 | +_ |
| 59 | +_PATH" ]; then |
| 60 | +log_message "package.json found at $PACKAGE |
| 61 | +JSON |
| 62 | +_ |
| 63 | +_ |
| 64 | +DEFAULT |
| 65 | +PATH="$PACKAGE |
| 66 | +JSON |
| 67 | +PATH" |
| 68 | +_ |
| 69 | +_ |
| 70 | +_ |
| 71 | +PATH." |
| 72 | +else |
| 73 | +log_message "Error: package.json not found in fallback directory." |
| 74 | +echo "Error: package.json not found. Check the log file $LOG |
| 75 | +_ |
| 76 | +exit 1 |
| 77 | +FILE for details." |
| 78 | +fi |
| 79 | +fi |
| 80 | +# Navigate to the directory containing package.json |
| 81 | +WORKING |
| 82 | +_ |
| 83 | +DIR=$(dirname "$DEFAULT |
| 84 | +_PATH") |
| 85 | +log_message "Changing directory to $WORKING |
| 86 | +DIR" |
| 87 | +_ |
| 88 | +cd "$WORKING |
| 89 | +_DIR" || { log_message "Failed to change directory to $WORKING |
| 90 | +_DIR."; echo |
| 91 | +"Failed to change directory. Check the log file $LOG |
| 92 | +_FILE for details."; exit 1; } |
| 93 | +# Run npm install |
| 94 | +log_message "Running npm install..." |
| 95 | +npm install >> "$LOG |
| 96 | +FILE" 2>&1 |
| 97 | +_ |
| 98 | +# Check if npm install was successful |
| 99 | +if [ $? -eq 0 ]; then |
| 100 | +log_message "npm install completed successfully." |
| 101 | +else |
| 102 | +log_message "Error: npm install failed." |
| 103 | +echo "Error: npm install failed. Check the log file $LOG |
| 104 | +_ |
| 105 | +exit 1 |
| 106 | +FILE for details." |
| 107 | +fi |
0 commit comments