run.sh 2.59 KB
Newer Older
1
#!/bin/bash
David Trattnig's avatar
David Trattnig committed
2
mode="engine"
David Trattnig's avatar
David Trattnig committed
3
docker="false"
David Trattnig's avatar
David Trattnig committed
4

David Trattnig's avatar
David Trattnig committed
5
6
7
8
9
#
# Run Script for AURA Engine
#
# Call with one of these parameters:
#
David Trattnig's avatar
David Trattnig committed
10
# - dev
David Trattnig's avatar
David Trattnig committed
11
# - engine
12
# - test
David Trattnig's avatar
David Trattnig committed
13
14
# - recreate-database

David Trattnig's avatar
David Trattnig committed
15
16
# - docker:engine
# - docker:build
17
# - docker:push
David Trattnig's avatar
David Trattnig committed
18
#
David Trattnig's avatar
David Trattnig committed
19

David Trattnig's avatar
David Trattnig committed
20
21
if [[ $* =~ ^(dev|engine|test|recreate-database)$ ]]; then
	mode=$1
David Trattnig's avatar
David Trattnig committed
22
23
fi

David Trattnig's avatar
David Trattnig committed
24
if [[ "$1" == *"docker:"* ]]; then
David Trattnig's avatar
David Trattnig committed
25
	docker="true"
David Trattnig's avatar
David Trattnig committed
26
	mode=${1#*:}
David Trattnig's avatar
David Trattnig committed
27
28
fi

David Trattnig's avatar
David Trattnig committed
29

David Trattnig's avatar
David Trattnig committed
30
echo "[ Run mode=$mode ]"
David Trattnig's avatar
David Trattnig committed
31
echo "[ Docker=$docker ]"
David Trattnig's avatar
David Trattnig committed
32

33

34
35
36
# Check for the correct Python version (3.8+)
PYTHON_EXEC="python3"
echo "[ Using $(python3 -V) ]"
37

David Trattnig's avatar
David Trattnig committed
38

David Trattnig's avatar
David Trattnig committed
39
# +++ DEFAULT COMMANDS +++ #
40

David Trattnig's avatar
David Trattnig committed
41
if [[ $docker == "false" ]]; then
42

David Trattnig's avatar
David Trattnig committed
43
44
45
46
47
48
49
50
	### Runs Engine in development mode (Virtualenv) ###

	if [[ $mode == "dev" ]]; then
		source python/bin/activate
		echo "Running Engine in Python Environment ($(python3 -V))"
		python run.py
	fi

51
	### Runs Engine ###
52

David Trattnig's avatar
David Trattnig committed
53
	if [[ $mode == "engine" ]]; then
54
		/usr/bin/env $PYTHON_EXEC run.py
David Trattnig's avatar
David Trattnig committed
55
	fi
David Trattnig's avatar
David Trattnig committed
56

57
58
59
60
61
62
	### Runs Tests ###

	if [[ $mode == "test" ]]; then
		/usr/bin/env $PYTHON_EXEC -m unittest discover tests
	fi

David Trattnig's avatar
David Trattnig committed
63
64
65
	### CAUTION: This deletes everything in your database ###

	if [[ $mode == "recreate-database" ]]; then
66
		/usr/bin/env $PYTHON_EXEC run.py --recreate-database
David Trattnig's avatar
David Trattnig committed
67
68
	fi

69
70
fi

71

David Trattnig's avatar
David Trattnig committed
72
73
74
# +++ DOCKER COMMANDS +++ #

if [[ $docker == "true" ]]; then
75
76
	BASE_DIR=$(readlink -f .)
	echo "Absolute base dir: " $BASE_DIR
David Trattnig's avatar
David Trattnig committed
77

78
	### Runs Engine Docker Container ###
David Trattnig's avatar
David Trattnig committed
79
80

	if [[ $mode == "engine" ]]; then
81
82
83
84
85
86
87
88
89

		if [[ -z "${AURA_ENGINE_CONFIG_PATH}" ]]; then
			AURA_ENGINE_CONFIG_PATH="$BASE_DIR/config/engine.docker.ini"
		fi

		if [[ -z "${AURA_ENGINE_SOCKET_DIR}" ]]; then
			AURA_ENGINE_SOCKET_DIR="$BASE_DIR/../engine-core/socket"
		fi

90
91
92
93
		if [[ -z "${AURA_ENGINE_CONTROL_CHANNEL}" ]]; then
			AURA_ENGINE_CONTROL_CHANNEL="127.0.0.1:1337"
		fi

94
95
96
97
98
99
100
101
		if [[ -z "${AURA_ENGINE_AUDIO_SOURCE_DIR}" ]]; then
			AURA_ENGINE_AUDIO_SOURCE_DIR="$BASE_DIR/audio/source"
		fi

		if [[ -z "${AURA_ENGINE_AUDIO_PLAYLIST_DIR}" ]]; then
			AURA_ENGINE_AUDIO_PLAYLIST_DIR="$BASE_DIR/audio/playlist"
		fi

102
103
104
		exec sudo docker run \
			--network="host" \
			--name aura-engine \
105
			--rm \
David Trattnig's avatar
David Trattnig committed
106
			-u $UID:$GID \
107
			-p $AURA_ENGINE_CONTROL_CHANNEL:1337/tcp \
108
109
110
111
112
			-v "$AURA_ENGINE_CONFIG_PATH":"/srv/config/engine.ini":ro \
			-v "$AURA_ENGINE_SOCKET_DIR":"/srv/socket" \
			-v "$AURA_ENGINE_AUDIO_SOURCE_DIR":"/var/audio/source":ro \
			-v "$AURA_ENGINE_AUDIO_PLAYLIST_DIR":"/var/audio/playlist" \
			-v "$BASE_DIR/logs":"/srv/logs" \
113
			autoradio/engine
David Trattnig's avatar
David Trattnig committed
114
115
	fi

David Trattnig's avatar
David Trattnig committed
116
117
118
	### Create Docker Image from local project ###

	if [[ $mode == "build" ]]; then
David Trattnig's avatar
David Trattnig committed
119
		exec sudo docker build -t autoradio/engine .
David Trattnig's avatar
David Trattnig committed
120
121
	fi

David Trattnig's avatar
David Trattnig committed
122
123
124
125
126
	### Pushes the latest Docker Image to Docker Hub ###

	if [[ $mode == "push" ]]; then
		exec sudo docker push autoradio/engine
	fi
David Trattnig's avatar
David Trattnig committed
127
fi