-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·96 lines (71 loc) · 2.93 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
#!/bin/bash
# Base install script for Trunk-Player
# https://github.com/ScanOC/trunk-player
# Dylan Reinhold
#----------------------------------------
user=$1
if [ -z $user ]
then
user="radio"
fi
echo "`date` Started" > /root/INSTALL_STARTED
cd /root/
export DEBIAN_FRONTEND=noninteractive;
apt-get -y update
apt-get -y upgrade
apt-get -y install python3-dev virtualenv redis-server python3-pip postgresql libpq-dev postgresql-client postgresql-client-common git nginx bc supervisor
#!/bin/bash
USER="radio" # Change this to the user you want created
cd /root/
echo "`date` Start install" >> /root/install.log
# Add digital ocean monitoring
curl -sSL https://agent.digitalocean.com/install.sh | sh
adduser $user --gecos "" --disabled-password
db_pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#+' | fold -w 12 | head -n 1)
django_secret_key=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#+' | fold -w 64 | head -n 1)
curl https://raw.githubusercontent.com/ScanOC/cloud-init/master/postgres_setup.sql -o postgres_setup.sql
sed "s/__DB_PASS__/$db_pass/g" < postgres_setup.sql > ~postgres/postgres_setup.sql
chown postgres ~postgres/postgres_setup.sql
su - postgres -c "psql < ~postgres/postgres_setup.sql"
rm -f ~postgres/postgres_setup.sql
curl https://raw.githubusercontent.com/ScanOC/cloud-init/master/tp-settings.tmpl -o tp-settings.tmpl
sed -e "s/__DB_PASS__/$db_pass/g" \
-e "s/__SECRET_KEY__/$django_secret_key/g" < tp-settings.tmpl > /home/$user/tp-settings.tmpl
chown $user /home/$user/tp-settings.tmpl
curl https://raw.githubusercontent.com/ScanOC/cloud-init/master/tp-setup.sh -o tp-setup.sh
cp tp-setup.sh /home/$user/tp-setup.sh
chown $user /home/$user/tp-setup.sh
chmod 744 /home/$user/tp-setup.sh
su - $user -c "cd /home/$user && ./tp-setup.sh"
rm -f /etc/nginx/sites-enabled/default
ln -s /home/$user/trunk-player/trunk_player/nginx.conf /etc/nginx/sites-enabled/001-trunkplayer.conf
ln /home/$user/trunk-player/trunk_player/supervisor.conf /etc/supervisor/conf.d/trunk_player.conf
supervisorctl reread
supervisorctl update
kill -HUP `cat /var/run/nginx.pid`
# Copy ssh keys from root install to new user
if [ -f /root/.ssh/authorized_keys ]
then
mkdir /home/$user/.ssh
chown $user:$user /home/$user/.ssh
chmod 700 /home/$user/.ssh
cp /root/.ssh/authorized_keys /home/$user/.ssh/authorized_keys
chown $user:$user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys
fi
# Amazon EC2 has a non usable root key, try ubuntu
if [ -f /home/ubuntu/.ssh/authorized_keys ]
then
if [ ! -d /home/$user/.ssh ]
then
mkdir /home/$user/.ssh
fi
chown $user:$user /home/$user/.ssh
chmod 700 /home/$user/.ssh
cp /home/ubuntu/.ssh/authorized_keys /home/$user/.ssh/authorized_keys
chown $user:$user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys
fi
echo "Complete"
echo "`date` Complete" >> /root/INSTALL_STARTED
mv /root/INSTALL_STARTED /root/INSTALL_COMPLETE