-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.sh
74 lines (61 loc) · 1.96 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Function to log messages
log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1"
}
# Function to clean up and exit
cleanup() {
log "INFO: Cleaning up and exiting..."
# Kill the PHP development server process and all its child processes
if [[ -n "$server_pid" ]]; then
# Kill the PHP server process group
kill -- -"$server_pid"
fi
exit 0
}
# Trap SIGINT signal (Ctrl+C) and call the cleanup function
trap cleanup SIGINT
# Check if PHP is installed
if ! command -v php &>/dev/null; then
log "ERROR: PHP is not installed. Please install PHP before running this script."
exit 1
fi
# Check if Ollama is installed
if ! command -v ollama &>/dev/null; then
log "ERROR: Ollama is not installed. Please install Ollama before running this script."
exit 1
fi
# Navigate to the directory of the script
cd "$(dirname "$0")" || exit
log "INFO: Script directory: $(pwd)"
# Fetch updates from the Git repository
log "INFO: Fetching updates from the Git repository..."
git fetch
# Check if updates are available
if [[ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]]; then
# Pull updates from the Git repository if available
log "INFO: Updates available. Pulling..."
git pull
else
# No updates available
log "INFO: Already up to date."
fi
# Clear the terminal screen
clear
# Start the PHP development server in the background
log "INFO: Starting PHP development server..."
php -S localhost:8000 &
# Store the process ID (PID) of the server
server_pid=$!
# Log the server start
log "INFO: PHP development server started on http://localhost:8000"
# Open the URL in the default browser
log "INFO: Opening URL in default browser..."
case "$(uname -s)" in
Darwin) open http://localhost:8000 ;;
Linux) xdg-open http://localhost:8000 ;;
CYGWIN* | MINGW32* | MSYS* | MINGW*) start http://localhost:8000 ;;
*) log "ERROR: Unsupported operating system." ;;
esac
# Wait for the PHP development server process to finish
wait "$server_pid"