-
Notifications
You must be signed in to change notification settings - Fork 4
/
linode.sh
136 lines (112 loc) · 4.22 KB
/
linode.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
#!/bin/bash
# <udf name="sys_hostname" label="Hostname" />
# <udf name="project_name" label="Project Name" example="Will be used to name folders and files" />
# <udf name="deploy_password" label="Non-root Password" example="Non-root password for all services and users" />
# <udf name="my_ssh_public_key" label="Your SSH Public Key" example="REQUIRED! try `cat ~/.ssh/id_rsa.pub | pbcopy`" />
# <udf name="ruby" label="Ruby to Install" oneOf="ree,ruby-1.8.7,ruby-1.9.2,jruby,rbx" default="ruby-1.9.2" />
# <udf name="persistence" label="Persistence" manyOf="MySQL,MongoDB" default="MySQL,MongoDB" />
# <udf name="servers" label="Servers" manyOf="nginx,node.js" example="node.js is not implemented" />
function split {
echo $(echo $1 | tr "," "\n")
}
function system_install_logrotate {
apt-get -y install logrotate
}
function system_sshd_append {
# $1 configuration option
# $2 value to set
echo "$1 $2" >> /etc/ssh/sshd_config
}
function rvm_install {
# $1 - username
RVM_USER=$1
apt-get -y install build-essential bison openssl libreadline5 libreadline5-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev
AS_USER="sudo -u $RVM_USER -i --"
$AS_USER 'bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )'
$AS_USER "sed -i -e 's/^\[ -z \"\$PS1\" \] && return$/if [[ -n \"\$PS1\" ]]; then/' .bashrc && echo 'fi' >> .bashrc"
$AS_USER "echo '[[ -s \"\$HOME/.rvm/scripts/rvm\" ]] && . \"\$HOME/.rvm/scripts/rvm\"' >> .bashrc"
apt-get install -y libxslt1-dev libxslt-ruby
}
function rvm_default_ruby {
# $1 - username
# $2 - ruby
RVM_USER=$1
THE_RUBY=$2
AS_USER="sudo -u $RVM_USER -i --"
$AS_USER "rvm install $THE_RUBY"
$AS_USER "rvm --default $THE_RUBY"
}
function rvm_setup_project {
# $1 - username
# $2 - project_name
AS_USER="sudo -u $1 -i --"
PROJ=$2
echo "Installing Phusion Passenger"
$AS_USER "rvm gemset create $PROJ && rvm gemset use $PROJ && gem install --pre passenger"
$AS_USER "mkdir ~/${PROJ}"
$AS_USER "echo 'rvm gemset use $PROJ' > ~/${PROJ}/.rvmrc"
$AS_USER "rvm rvmrc trust ~/${PROJ}"
}
function rvm_setup_project_with_nginx {
# $1 - username
# $2 - project_name
USERNAME=$1
PROJ=$2
AS_USER="sudo -u $USERNAME -i --"
apt-get install -y zlib1g-dev libcurl4-openssl-dev
mkdir /opt/nginx
chown $USERNAME:$USERNAME /opt/nginx
echo "Installing Phusion Passenger for nginx"
$AS_USER "cd $PROJ && passenger-install-nginx-module --auto --prefix=/opt/nginx --auto-download --extra-configure-flags=--with-http_ssl_module"
curl http://github.com/ivanvanderbyl/rails-nginx-passenger-ubuntu/raw/master/nginx/nginx -o /etc/init.d/nginx && chmod +x /etc/init.d/nginx
/etc/init.d/nginx start
/usr/sbin/update-rc.d -f nginx defaults
}
function mongodb_install {
echo "deb http://downloads.mongodb.org/distros/ubuntu 10.4 10gen" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
aptitude update
apt-get install -y mongodb-stable
}
function user_ssh_keygen {
# $1 - username
sudo -u $1 -i -- "ssh-keygen -N '' -f ~/.ssh/id_rsa -t rsa -q"
}
exec &> /root/stackscript.log
source <ssinclude StackScriptID="1">
system_update
source <ssinclude StackScriptID="123">
system_add_user deploy $DEPLOY_PASSWORD "users,sudo"
system_user_add_ssh_key deploy "$MY_SSH_PUBLIC_KEY"
# stackscript 1
goodstuff
# stackscript 123
system_enable_universe
system_security_ufw_install
system_security_ufw_configure_basic
system_update_locale_en_US_UTF_8
system_sshd_permitrootlogin No
system_sshd_passwordauthentication No
system_sshd_pubkeyauthentication Yes
system_sshd_append ClientAliveInterval 60
/etc/init.d/ssh restart
system_update_hostname "$SYS_HOSTNAME"
user_ssh_keygen deploy
if [[ -n "$(echo $PERSISTENCE | grep 'MySQL')" ]]; then
mysql_install "$DEPLOY_PASSWORD"
mysql_tune 30
fi
if [[ -n "$(echo $PERSISTENCE | grep 'MongoDB')" ]]; then
mongodb_install
fi
system_install_logrotate
rvm_install deploy
rvm_default_ruby deploy "$RUBY"
rvm_setup_project deploy "$PROJECT_NAME"
if [[ -n "#(echo $SERVERS | grep 'nginx')" ]]; then
rvm_setup_project_with_nginx deploy "$PROJECT_NAME"
fi
echo "************************************"
echo "All done! Now, get coding"
echo ""
echo "(You'll want to set up nginx yourself)"