Skip to content

Commit a451ad7

Browse files
authored
Create enhanced_fix_paths_and_install.sh
#!/bin/bash # Default values DEFAULT _PATH="/home/runner/work/OpenAI-API-dotnet/OpenAI-API-dotnet/package.json" FALLBACK _DIR="/home/runner/work/OpenAI-API-dotnet/OpenAI-API-dotnet/" LOG FILE="install _ _log.txt" # Function to log messages log_message() { local message="$1" echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" >> "$LOG FILE" _ } # Function to check if a file exists file _exists() { [ -f "$1" ] } # Function to find package.json in a directory find _package_json() { local search dir="$1" _ find "$search _dir" -name "package.json" -print -quit } # Main script log_message "Starting path correction and installation process..." # Check if package.json exists at the default path if file exists "$DEFAULT _ _PATH"; then log_message "package.json found at $DEFAULT _ PATH." else log_message "package.json not found at $DEFAULT _ PATH." # Attempt to locate package.json in the fallback directory log_message "Searching for package.json in fallback directory $FALLBACK _ PACKAGE JSON _ _ PATH=$(find_package_json "$FALLBACK _DIR") DIR..." if [ -n "$PACKAGE JSON _ _PATH" ]; then log_message "package.json found at $PACKAGE JSON _ _ DEFAULT PATH="$PACKAGE JSON PATH" _ _ _ PATH." else log_message "Error: package.json not found in fallback directory." echo "Error: package.json not found. Check the log file $LOG _ exit 1 FILE for details." fi fi # Navigate to the directory containing package.json WORKING _ DIR=$(dirname "$DEFAULT _PATH") log_message "Changing directory to $WORKING DIR" _ cd "$WORKING _DIR" || { log_message "Failed to change directory to $WORKING _DIR."; echo "Failed to change directory. Check the log file $LOG _FILE for details."; exit 1; } # Run npm install log_message "Running npm install..." npm install >> "$LOG FILE" 2>&1 _ # Check if npm install was successful if [ $? -eq 0 ]; then log_message "npm install completed successfully." else log_message "Error: npm install failed." echo "Error: npm install failed. Check the log file $LOG _ exit 1 FILE for details." fi
1 parent bd38052 commit a451ad7

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

enhanced_fix_paths_and_install.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

Comments
 (0)