-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·75 lines (62 loc) · 1.86 KB
/
start.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
75
#!/bin/bash
# Welcome message
echo "Welcome! Launching GitSync..."
# Ensure 'data' directory exists
if [[ ! -d "data" ]]; then
mkdir data
fi
# Ensure required files exist in the 'data' directory
for file in token.json repos.json config.json; do
if [[ ! -f "data/$file" ]]; then
case $file in
token.json) echo '{"token":""}' > "data/$file" ;;
repos.json) echo '{"repos":[]}' > "data/$file" ;;
config.json) echo '{"scanpath":""}' > "data/$file" ;;
esac
fi
done
# Check for the presence of required commands
for cmd in docker docker-compose python3 pip3; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is not installed."
exit 1
fi
done
# Install GitSync engine dependencies
echo -n "Installing GitSync engine dependencies..."
echo " "
pip3 install -r scripts/requirements.txt > /dev/null
echo "Done!"
# Build the Docker image for the web service
echo -n "Building Docker image for the web service... "
echo " "
docker build -f dockerfile.web -t gitsync_web . > /dev/null
echo "Done!"
# Function to tail logs of docker-compose
tail_docker_logs() {
docker-compose logs -f &
docker_compose_pid=$!
}
# Function to stop services and script
cleanup() {
echo "Stopping services..."
docker-compose down
[[ -n "$python_pid" ]] && kill $python_pid
[[ -n "$docker_compose_pid" ]] && kill $docker_compose_pid
echo "Services stopped. Exiting."
exit 0
}
# Set up trap for SIGINT
trap cleanup SIGINT
# Start services and capture their logs
echo "Starting services..."
docker-compose up -d
tail_docker_logs
# Run the Python script
cd scripts && python3 gitsync.py &
python_pid=$!
# Wait for both background processes to complete
wait $python_pid $docker_compose_pid
# End message with access link
echo "GitSync is ready to be used."
echo "Access at: http://localhost:9002"