-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathubuntu-setup.sh
More file actions
164 lines (132 loc) · 5.24 KB
/
ubuntu-setup.sh
File metadata and controls
164 lines (132 loc) · 5.24 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
# user variables
#---------------------------------------------------------------
# gems to be installed
gems="rails capistrano"
# script variables
#---------------------------------------------------------------
mainTitle="Ubuntu Server Setup"
tmpFile=`tempfile`
# functions
#---------------------------------------------------------------
installServerUpdates()
{
sudo aptitude -y update
sudo aptitude -y safe-upgrade
sudo aptitude -y full-upgrade
return
}
installBuildTools()
{
sudo aptitude -y install build-essential libssl-dev libreadline5-dev zlib1g-dev curl openssh-server libyaml-dev
return
}
# First, install dialog
#---------------------------------------------------------------
sudo aptitude install dialog
# Then show welcome screen
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Welcome" \
--yesno "Hi. This script will setup your Ubuntu Server for Rails apps. Before starting, make sure you're running a fresh Ubuntu install.\n\nThere's no input validation, so be sure of what you're typing.\n\nDo you want to continue?" \
13 50 2> $tmpFile
input=$?
exitIfCancelOrESC $input
clear
# Ask for username
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Creating user account" \
--inputbox "An user will be created to hold all configuration files and your application.\n\nType the username below." \
12 50 app 2> $tmpFile
input=$?
exitIfCancelOrESC $input
username=`cat $tmpFile`
clear
# Ask for SSH port
#---------------------------------------------------------------
# TODO: check if the chosen port is being used
# nc -zv 127.0.0.1 $ssh_port 2>&1
dialog --backtitle "$mainTitle" --title "SSH port" \
--inputbox "Is recommended that you change your SSH port to avoid brute force attack. The default port is 22.\n\nWhat port do you want to use? Choose one over port 2000." \
13 50 22 2> $tmpFile
input=$?
exitIfCancelOrESC $input
ssh_port=`cat $tmpFile`
clear
# Ask for domain
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Domain name" \
--inputbox "What's the domain you're setting up? Can be an IP address." \
8 50 "domain.com" 2> $tmpFile
input=$?
exitIfCancelOrESC $input
domain=`cat $tmpFile`
clear
# Ask for admin email
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Administrator e-mail" \
--inputbox "What's the admin e-mail?" \
8 50 "admin@$domain" 2> $tmpFile
input=$?
exitIfCancelOrESC $input
admin_email=`cat $tmpFile`
clear
# Ask for thin instances
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Thin instances" \
--inputbox "How many thin instances do you want to run?" \
7 50 3 2> $tmpFile
input=$?
exitIfCancelOrESC $input
thin_instances=`cat $tmpFile`
clear
# Ask for thin port
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Thin port" \
--inputbox "What's the starting port number you want your thin instances to use?" \
8 50 5000 2> $tmpFile
input=$?
exitIfCancelOrESC $input
thin_port_start=`cat $tmpFile`
clear
# Ask for memcache port
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Memcache port" \
--inputbox "What port do you want to run Memcache? The default is 11211." \
8 50 11211 2> $tmpFile
input=$?
exitIfCancelOrESC $input
memcache_port=`cat $tmpFile`
clear
# Ask for memcache maximum memory usage
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Memcache memory usage" \
--inputbox "How much memory do you want Memcached to use? Please set this value in MB." \
8 50 30 2> $tmpFile
input=$?
exitIfCancelOrESC $input
memcache_memory=`cat $tmpFile`
clear
# Ask for MySQL password
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "MySQL user account" \
--inputbox "An user '$username' will be added to the MySQL. Additionally, a database '${username}_production' will be also created.\n\nPlease type a password for this new MySQL user." \
13 50 2> $tmpFile
input=$?
exitIfCancelOrESC $input
mysql_password=`cat $tmpFile`
clear
# Disclaimer
#---------------------------------------------------------------
dialog --backtitle "$mainTitle" --title "Disclaimer" \
--yesno "I'll start setting up the server now. After this process, I'll restart the SSH service, which means that you'll be disconnected. To reconnect, please use the port $ssh_port as in \"ssh $username@<ip or domain> -p $ssh_port\".\n\nDo you want to continue?" \
12 50 2> $tmpFile
input=$?
exitIfCancelOrESC $input
clear
# Start the process
#---------------------------------------------------------------
installServerUpdates
installBuildTools
dialog --backtitle "$mainTitle" --title "Ubuntu Server Setup Completed" \
--msgbox "The server has been setup (I hope) and you can access a sample application at http://$domain/home after the domain has been propagated." 8 50
clear
exit 0