-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
install.sh
executable file
·124 lines (84 loc) · 2.72 KB
/
install.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# ============================================
# RUN sudo ./install.sh
# ============================================
set -e # Exit immediately if a command exits with a non-zero status
# -------------------------------------------------------
# bash colors for log
# -------------------------------------------------------
black=`tput setaf 0`
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
reset=`tput sgr0`
# -------------------------------------------------------
# print log level
# -------------------------------------------------------
function log() {
date_now=`date '+%Y-%m-%d %H:%M:%S'`
case $1 in
debug) echo -e "${date_now} :: ${2}" ;;
warning) echo -e "${date_now} :: ${yellow}${2}${reset}" ;;
error) echo -e "${date_now} :: ${red}${2}${reset}" ;;
*) echo -e "${date_now} :: ${magenta}${1}${reset}" ;;
esac
}
# -------------------------------------------------------
# Check if Linux OS
# -------------------------------------------------------
unamestr=$(uname)
if [[ "$unamestr" != 'Linux' ]]; then
log warning "This install script is supported only on Linux OS"
exit
fi
# -------------------------------------------------------
# Check if run as root
# -------------------------------------------------------
if [ "$EUID" -ne 0 ]; then
log warning "Please run as root: sudo ./install.sh"
exit
fi
# ============================================
# Start the installation...
# ============================================
ENV=.env
if ! [ -f "$ENV" ]; then
log "Copy .env.template to .env (edit it according to your needs)"
cp .env.template $ENV
fi
printf 'Use docker (y/n)? '
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
log "Install Docker and Docker Compose"
sudo apt install -y docker.io
sudo apt install -y docker-compose
log "Add the current user to the docker group"
usermod -aG docker $USER
YAML=docker-compose.yml
if ! [ -f "$YAML" ]; then
log "Copy Docker compose yaml file"
cp docker-compose.template.yml $YAML
fi
printf 'Use official docker image (y/n)? '
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
log "Get latest official image from Docker Hub"
docker pull mirotalk/c2c:latest
else
log "Build image from source"
docker-compose build
log "Remove old and unused docker images"
docker images |grep '<none>' |awk '{print $3}' |xargs docker rmi
fi
log "Start containers"
docker-compose up #-d
else
log "Install dependencies"
npm install
log "Start the server"
npm start
fi