1
1
#! /bin/bash
2
2
3
- # Strict mode, exit on error, undefined variables, and pipe failures
4
- set -euo pipefail
5
-
6
3
# Print some information about the environment to aid in case of troubleshooting
7
4
8
5
echo " node version:"
@@ -30,63 +27,60 @@ if (( CURRENT_NODE_VERSION < REQUIRED_NODE_VERSION )); then
30
27
fi
31
28
32
29
# Autodetect project directory relative to this script's path
33
- PROJECT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd) "
30
+ PROJECT_DIR=" $0 "
31
+ while [ -h " $PROJECT_DIR " ]; do
32
+ ls=$( ls -ld " $PROJECT_DIR " )
33
+ link=$( expr " $ls " : ' .*-> \(.*\)$' )
34
+ if expr " $link " : ' /.*' > /dev/null; then
35
+ PROJECT_DIR=" $link "
36
+ else
37
+ PROJECT_DIR=" $( dirname " $PROJECT_DIR " ) /$link "
38
+ fi
39
+ done
40
+ PROJECT_DIR=" $( dirname " $PROJECT_DIR " ) /.."
41
+ PROJECT_DIR=" $( cd " $PROJECT_DIR " ; pwd) "
34
42
35
- cd " $PROJECT_DIR "
43
+ cd $PROJECT_DIR
36
44
37
45
cp .env.example .env
38
46
39
47
pnpm install -r
40
48
41
49
pnpm build
42
50
43
- # Create temp file and ensure cleanup
44
51
OUTFILE=" $( mktemp) "
45
- trap ' rm -f "$OUTFILE"' EXIT
46
- echo " Using temporary output file: $OUTFILE "
47
-
48
- # Add timeout configuration
49
- TIMEOUT=30
50
- INTERVAL=0.5
51
- TIMER=0
52
-
52
+ echo $OUTFILE
53
53
(
54
- # Wait for the ready message with timeout
54
+ # Wait for the ready message
55
55
while true ; do
56
- if [[ $TIMER -ge $TIMEOUT ]]; then
57
- echo " Error: Timeout waiting for application to start after $TIMEOUT seconds"
58
- kill $$
59
- exit 1
60
- fi
61
-
62
56
if grep -q " Chat started" " $OUTFILE " ; then
63
57
echo " exit" ; sleep 2
64
58
break
65
59
fi
66
-
67
- sleep $INTERVAL
68
- TIMER=$( echo " $TIMER + $INTERVAL " | bc)
60
+ sleep 0.5
69
61
done
70
62
) | pnpm start --character=characters/trump.character.json > " $OUTFILE " &
71
63
72
64
# Wait for process to finish
73
65
wait $!
74
66
RESULT=$?
75
-
76
67
echo " ----- OUTPUT START -----"
77
68
cat " $OUTFILE "
78
69
echo " ----- OUTPUT END -----"
79
70
80
71
# Check the exit code of the last command
81
72
if [[ $RESULT -ne 0 ]]; then
82
- echo " Error: 'start' command exited with an error (code: $RESULT ) "
73
+ echo " Error: 'start' command exited with an error. "
83
74
exit 1
84
75
fi
85
76
86
- # Check if output contains expected termination message
77
+ # Check if output.txt contains "Terminating and cleaning up resources..."
87
78
if grep -q " Terminating and cleaning up resources..." " $OUTFILE " ; then
88
79
echo " Script completed successfully."
89
80
else
90
- echo " Error: The output does not contain the expected termination message ."
81
+ echo " Error: The output does not contain the expected string ."
91
82
exit 1
92
- fi
83
+ fi
84
+
85
+ # Clean up
86
+ rm " $OUTFILE "
0 commit comments