forked from nylas/sync-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·152 lines (129 loc) · 3.94 KB
/
setup.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
set -e
configure_db=true
while getopts "p" opt; do
case $opt in
p)
configure_db=false
;;
esac
done
color() {
printf '\033[%sm%s\033[m\n' "$@"
# usage color "31;5" "string"
# 0 default
# 5 blink, 1 strong, 4 underlined
# fg: 31 red, 32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
# bg: 40 black, 41 red, 44 blue, 45 purple
}
color '36;1' "
_____ _
|_ _| | |
| | _ __ | |__ _____ __
| | | '_ \| '_ \ / _ \ \/ /
_| |_| | | | |_) | (_) > <
|_____|_| |_|_.__/ \___/_/\_\\
This script installs dependencies for Inbox.
For more details, visit:
https://www.github.com/inboxapp/inbox
"
color '35;1' 'Updating packages...'
apt-get update
apt-get -y install python-software-properties
# Preconfigure MySQL root password
echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
color '35;1' 'Installing dependencies from apt-get...'
apt-get -y install git \
wget \
supervisor \
mysql-server \
mysql-client \
python \
python-dev \
python-pip \
python-setuptools \
build-essential \
libmysqlclient-dev \
gcc \
g++ \
libzmq-dev \
libxml2-dev \
libxslt-dev \
lib32z1-dev \
libffi-dev \
python-lxml \
tmux \
curl \
tnef \
color '35;1' 'Installing dependencies from pip...'
pip install --upgrade setuptools
pip install -r requirements.txt
pip install -e .
if [ -d "../inbox-eas" ]; then
pip install -r ../inbox-eas/requirements.txt
pip install -e ../inbox-eas
fi
color '35;1' 'Finished installing dependencies.'
mkdir -p /etc/inboxapp
chown $SUDO_USER /etc/inboxapp
color '35;1' 'Copying default development configuration to /etc/inboxapp'
src=./etc/config-dev.json
dest=/etc/inboxapp/config.json
if [ ! -f $dest ]; then
cp $src $dest
elif [ $src -nt $dest ]; then
set +e
diff_result=$(diff -q $src $dest)
different=$?
set -e
if [ $different -ne 0 ]; then
echo "Error: inbox config is newer and merging of configs not (yet) supported."
echo "Diffs:"
echo "src: $src dest: $dest"
diff $dest $src
exit 1
fi
fi
if $configure_db; then
# Mysql config
color '35;1' 'Copying default mysql configuration to /etc/mysql/conf.d'
src=./etc/my.cnf
dest=/etc/mysql/conf.d/inboxapp.cnf
if [ ! -f $dest ]; then
cp $src $dest
elif [ $src -nt $dest ]; then
set +e
diff_result=$(diff -q $src $dest)
different=$?
set -e
if [ $different -ne 0 ]; then
echo "Error: inbox config is newer and merging of configs not (yet) supported."
echo "Diffs:"
echo "src: $src dest: $dest"
diff $dest $src
exit 1
fi
fi
mysqld_safe &
sleep 10
db_name=`cat /etc/inboxapp/config.json | grep "MYSQL_DATABASE" | awk '{ print $2 }' | sed "s/\"\(.*\)\",/\1/"`
if ! have_dbs=$(mysql -e "show databases like '$db_name'" | grep -q $db_name); then
color '35;1' 'Creating databases...'
python bin/create-db
else
color '35;1' 'Upgrading databases...'
alembic upgrade head
fi
fi
color '35;1' 'Removing .pyc files...'
find . -name \*.pyc -delete
color '35;1' 'Cleaning up...'
apt-get -y purge build-essential
apt-get -y autoremove
mkdir -p /var/lib/inboxapp
chown $SUDO_USER /var/lib/inboxapp
mkdir -p /var/log/inboxapp
chown $SUDO_USER /var/log/inboxapp
git config branch.master.rebase true
color '35;1' 'Done!.'