-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall_decidim.bash
More file actions
executable file
·241 lines (204 loc) · 8.05 KB
/
Copy pathinstall_decidim.bash
File metadata and controls
executable file
·241 lines (204 loc) · 8.05 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
#
# Decidim installation script on Ubuntu 16.04 LTS and macos sierra 10.2
#
# This is a BETA and as such you should be aware that this could break your environment (if you have any)
# This will install rbenv, postgresql, nodejs and install decidim on this directory
# It'll take 15 minutes depending on your network connection
#
set -e
set -x
DB_USER=decidim_app
DB_PASS=$( openssl rand -base64 32 )
DECIDIM_DIR=decidim_application
RUBY_VERSION=2.3.1
function ascii_banner {
echo "************************************************************************************************"
echo " █████████▓▌▄, ╦╦⌐ ]╫Ñ .╦╦ j╫Ñ"
echo " ████████▀█████▌ ╫╫∩ .╫╫ "
echo " ███████▌╫╫██████p ╔NN╦╫╫∩ ,╦NN╦≈ ╔╦NN╦ j╫Ñ .╦NN╦╫╫ jNN jNu╦NN╦╔╦DN≈"
echo " █████▓╫╫╫╫╫▒▓████ j╫Ñ ╫╫∩ :╫Ñ ╫╫⌐ 1╫H ]╫H j╫Ñ ╫╫H :╫╫ j╫Ñ ]╫Ñ ╫╫H :╫╫"
echo " ████▒╫╫╫╫╫╫╫▒▓███ ]╫N ╫╫∩ j╫Ñ≈≈╫╫⌐ ╫╫H j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫"
echo " ███████╫╫╫▒█████▌ ]╫N ╫╫∩ j╫Ñ'''' ╫╫H j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫"
echo " ████████▒▓█████▀ ]╫N ╫╫∩ j╫Ñ j╦¬ ╠╫H j╦r j╫Ñ ╫╫░ :╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫"
echo " ████████████▓▀ 'Ñ╫NN╬╫∩ ╚╫N╦╫M ╩╫NÑÑ j╫Ñ ╙ÑÑ╦Ñ╫╫ j╫Ñ ]╫Ñ ╫╫∩ :╫╫"
echo "************************************************************************************************"
}
function start_banner {
ascii_banner
echo " Welcome to Decidim installation"
echo " This is a BETA"
echo " You should be aware that this could break your environment (if you have any)"
echo " This will install rbenv, postgresql, nodejs and install decidim on this directory"
echo " It'll take from 10 to 30 minutes depending on your network connection"
echo "************************************************************************************************"
echo "Starting on 60 seconds. Press CTRL+C to cancel"
sleep 60
}
function end_banner {
ascii_banner
echo " Decidim installation process finished. All is OK!"
echo "************************************************************************************************"
echo " You can go to http://localhost:3000 and see the website."
echo " It'll take a few minutes to start up the first time. Be patient. "
echo "************************************************************************************************"
echo " ------------------------------------------------------------------------------------------"
echo " | Email | Password | URL | Role |"
echo " ------------------------------------------------------------------------------------------"
echo " | user@example.org | decidim123456 | http://localhost:3000/session/new | Regular user |"
echo " | admin@example.org | decidim123456 | http://localhost:3000/admin | Admin user |"
echo " ------------------------------------------------------------------------------------------"
echo "************************************************************************************************"
read -p "Press any key to continue: " -n 1 -r
}
function check_root {
if [ "$(id -u)" == "0" ] ; then
echo "This script must not be run as root" 1>&2
exit 1
fi
}
function check_git_config {
if [ $(git config -l | wc -l) == 0 ] ; then
echo "Configure git and execute again"
echo 'git config --global user.email "you@example.com"'
echo 'git config --global user.name "Your Name"'
exit 2
fi
}
### macos
function install_ruby_macos {
if [ ! -f /usr/local/bin/rbenv ] ; then
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
rbenv install $RUBY_VERSION
rbenv global $RUBY_VERSION
echo "gem: --no-document" > ~/.gemrc
gem install bundler
fi
}
### Ubuntu
function install_ruby_ubuntu {
if [ ! -d ~/.rbenv ] ; then
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install $RUBY_VERSION
rbenv global $RUBY_VERSION
echo "gem: --no-document" > ~/.gemrc
gem install bundler
fi
}
### Shared
function install_decidim {
gem install decidim
decidim ${DECIDIM_DIR}
cd ${DECIDIM_DIR}
bundle install
git init
git add .
git commit -m "Initial installation with Decidim (https://decidim.org)"
cd -
}
function configure_db {
cd ${DECIDIM_DIR}
echo "gem 'figaro'" >> Gemfile
bundle install
bundle exec figaro install
cat <<EOF > config/application.yml
DATABASE_USERNAME: ${DB_USER}
DATABASE_PASSWORD: ${DB_PASS}
EOF
cd -
}
function migrate_db {
cd ${DECIDIM_DIR}
bin/rails db:create db:migrate db:seed
cd -
}
function start_decidim {
cd ${DECIDIM_DIR}
bin/rails server
}
function cleanup {
rm -rf ${DECIDIM_DIR}
psql -c "DROP DATABASE IF EXISTS decidim_application_development;"
psql -c "DROP DATABASE IF EXISTS decidim_application_test;"
psql -c "DROP ROLE IF EXISTS decidim_app;"
}
function install_all_ubuntu {
sudo apt-get update
# Installs development tools
sudo apt-get install -y build-essential autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
# Installs Ruby
install_ruby_ubuntu
# Installs and configures PostgreSQL
sudo apt-get install -y postgresql libpq-dev
sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH CREATEROLE SUPERUSER CREATEDB;"
sudo -u postgres psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';"
# Installs nodejs
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
# Installs imagemagick library
sudo apt-get install -y imagemagick
}
function install_all_macos {
# Installs xcode
xcode-select -p 2> /dev/null || xcode-select --install 2> /dev/null
# Installs Brew
if [ ! -f /usr/local/bin/brew ] ; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
fi
# Installs Ruby
install_ruby_macos
# Installs and configures PostgreSQL
brew install postgres
sleep 5
nohup postgres -D /usr/local/var/postgres &
sleep 5
createdb $(whoami) || true
psql -c "CREATE USER ${DB_USER} WITH CREATEROLE SUPERUSER CREATEDB;"
psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';"
# Installs imagemagick library
brew install imagemagick
}
function main {
start_banner
#cleanup ${DECIDIM_DIR}
check_root
check_git_config
OS="`uname`"
case $OS in
'Linux')
echo "Installing dependencies for Ubuntu ..."
install_all_ubuntu
echo "Cloning decidim ..."
install_decidim
echo "Configuring database ..."
configure_db
migrate_db
end_banner
start_decidim
;;
'Darwin')
echo "Installing dependencies for macos ..."
install_all_macos
echo "Cloning decidim ..."
install_decidim
echo "Configuring database ..."
migrate_db
end_banner
start_decidim
;;
*)
"Operating System Not Supported"
exit 2
;;
esac
exit 0
}
main