-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
82 lines (75 loc) · 2.47 KB
/
Makefile
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
76
77
78
79
80
81
82
# Ensure we're in a Unix-like environment
ifeq (, $(shell which uname))
$(error This Makefile requires a Unix-like environment)
endif
# Install dependencies
install:
@echo "Checking for PostgreSQL Installation..."
@if command -v psql > /dev/null 2>&1; then \
echo "PostgreSQL is already installed."; \
else \
echo "Installing PostgreSQL..."; \
(sudo apt-get update && sudo apt-get -y install postgresql postgresql-contrib) || exit 1; \
echo "PostgreSQL successfully installed."; \
fi
@echo "Checking for Go installation..."
@if command -v go > /dev/null 2>&1; then \
echo "Go is already installed."; \
else \
echo "Installing Go version 1.22.2..."; \
wget https://golang.org/dl/go1.22.2.linux-amd64.tar.gz -O go1.22.2.tar.gz || exit 1; \
sudo tar -C /usr/local -xzf go1.22.2.tar.gz || exit 1; \
echo "Go version 1.22.2 installed."; \
rm go1.22.2.tar.gz; \
echo "Updating PATH to include Go binary directory..."; \
echo "export PATH=\$$PATH:/usr/local/go/bin" >> ~/.bashrc; \
. ~/.bashrc; \
fi
@echo "Checking for FFMpeg installation..."
@if command -v ffmpeg > /dev/null 2>&1; then \
echo "FFMpeg is already installed."; \
else \
echo "Installing FFMpeg..."; \
sudo apt-get update && sudo apt-get install -y ffmpeg || exit 1; \
echo "FFMpeg installed."; \
fi
@echo "Installing Go dependencies..."
go mod download || exit 1
@echo "Dependencies installed."
# Clean up directories and files
clean:
@echo "Cleaning up directories and files..."
@if [ -d "video" ]; then rm -r video; fi
@if [ -d "segments" ]; then rm -r segments; fi
@echo "Clean up complete."
# Initialize directories
init:
@echo "Initializing directories..."
@mkdir -p video
@mkdir -p segments
@echo "Initialization complete."
start-postgres:
@echo "Starting PostgreSQL service...";
@if command -v service > /dev/null 2>&1; then \
sudo service postgresql start || exit 1; \
elif command -v systemctl > /dev/null 2>&1; then \
sudo systemctl start postgresql || exit 1; \
elif command -v rc-service > /dev/null 2>&1; then \
sudo rc-service postgresql start || exit 1; \
fi
@if ps aux | grep -v grep | grep postgres > /dev/null 2>&1; then \
echo "PostgreSQL service started.";\
else \
echo "PostgreSQL service failed to start.";\
fi
# Start the Go application
start:
make start-postgres || exit 1
@echo "Starting the Go application..."
go run main.go
# Perform a clean start
cleanstart:
@echo "Performing clean start..."
make clean || exit 1
make init || exit 1
make start || exit 1