-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·146 lines (118 loc) · 4.16 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
set -evu
if [ -z $1 ]; then
echo "USAGE: $0 hostname"
exit 1
fi
# Set the hostname
hostname=$1
hostname $hostname
echo "$hostname" > /etc/hostname
# Updating apt packages...
apt-get update
# Installing git...
apt-get install -y git-core
# Installing node...
apt-get install -y python-software-properties python g++ make
add-apt-repository -y ppa:chris-lea/node.js
apt-get update
apt-get install -y nodejs
# Setting NODE_ENV=production...
echo "export NODE_ENV=production" > /etc/profile.d/NODE_ENV.sh
echo "export PORT=80" >> /etc/profile.d/NODE_ENV.sh
# Setting up the root user .ssh/ dir...
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys ~/.ssh/known_hosts
chmod 600 ~/.ssh/authorized_keys ~/.ssh/known_hosts
# Adding github.com to ~/.ssh/known_hosts...
cat <<EOS >> ~/.ssh/known_hosts
github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
EOS
# Setting up the deploy user...
id deploy || useradd -U -m -s /bin/bash deploy
# Setting up the deploy user .ssh/ dir...
deploy_home=/home/deploy
cp -r ~/.ssh $deploy_home/.ssh
chown -R deploy $deploy_home/.ssh
# Setting up repository...
git clone git@github.com:fork-n-roll/fork-n-roll.git $deploy_home/source
# Setting up database path...
echo "export GIT_PATH=$deploy_home/source/db/production.git" >> /etc/profile.d/NODE_ENV.sh
# Setting up runit...
apt-get install -y runit
# Setting runit to run server.js...
serverjs_etc=/etc/service/serverjs
mkdir -p $serverjs_etc/log
cat <<EOS > $serverjs_etc/run
#!/bin/sh
exec 2>&1
. /etc/profile
. $deploy_home/.profile
exec node $deploy_home/current/server.js
EOS
chmod +x $serverjs_etc/run
# Setting up runit logging...
mkdir -p $deploy_home/shared/logs/server
cat <<EOS > $serverjs_etc/log/run
#!/bin/sh
exec svlogd -tt $deploy_home/shared/logs/server
EOS
chmod +x $serverjs_etc/log/run
# Waiting for runit to recognize the new service...
while [ ! -d $serverjs_etc/supervise ]; do
sleep 5 && echo "waiting..."
done
sleep 1
# Turning off the server until the first deploy...
sv stop serverjs
> $deploy_home/shared/logs/server/current
# Giving the deploy user the ability to control the service...
chown -R deploy $serverjs_etc/supervise
chown -R deploy $deploy_home/shared
# Install ffmpeg
# Prepare the environment
sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev \
libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev \
libxfixes-dev texi2html yasm zlib1g-dev
# Install x264
cd ~/tmp/
git clone git://git.videolan.org/x264
cd x264
./configure --enable-static --disable-asm
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
--fstrans=no --default
# Install ffmpeg
cd ~/tmp/
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libtheora --enable-libvorbis \
--enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no \
--deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe
# Setting runit to run worker.js...
workerjs_etc=/etc/service/workerjs
mkdir -p $workerjs_etc/log
cat <<EOS > $workerjs_etc/run
#!/bin/sh
exec 2>&1
. /etc/profile
. $deploy_home/.profile
exec node $deploy_home/current/worker.js
EOS
chmod +x $workerjs_etc/run
# Setting up runit logging...
mkdir -p $deploy_home/shared/logs/worker
cat <<EOS > $workerjs_etc/log/run
#!/bin/sh
exec svlogd -tt $deploy_home/shared/logs/worker
EOS
chmod +x $workerjs_etc/log/run
# Giving the deploy user the ability to control the service...
chown -R deploy $workerjs_etc/supervise
chown -R deploy $deploy_home/shared