-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathubuntu22.sh
More file actions
executable file
·250 lines (207 loc) · 6.37 KB
/
Copy pathubuntu22.sh
File metadata and controls
executable file
·250 lines (207 loc) · 6.37 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
242
243
244
245
246
247
248
249
250
#!/bin/bash
set -e
echo ""
echo "-----------------------------------------------"
echo "Script tested on ubuntu 22 and 23. Possible errors if you have ruby o node installed without rvm and nvm"
echo "sudo privileges required to install dependencies"
echo ""
echo "-----------------------------------------------"
echo ""
sudo echo "sudo privileges granted"
# check if rvm is installed
if ! command -v rvm &>/dev/null; then
echo ""
echo "-----------------------------------------------"
echo "updating apt-get"
echo ""
echo "-----------------------------------------------"
echo ""
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sleep 1
echo ""
echo "-----------------------------------------------"
echo "installing base dependency (rvm, libssl, ...)"
echo ""
echo "-----------------------------------------------"
echo ""
sudo apt-get install -y software-properties-common rvm
sleep 1
echo ""
echo "-----------------------------------------------"
echo "add user to rvm group and source rvm"
echo ""
echo "-----------------------------------------------"
echo ""
sudo usermod -a -G rvm "$USER"
source /etc/profile.d/rvm.sh
echo ""
echo "-----------------------------------------------"
echo "reload user profile and terminal"
echo ""
echo "-----------------------------------------------"
echo ""
source ~/.profile
source ~/.bashrc
echo -e "\033[0;31m"
echo "-----------------------------------------------"
echo ""
echo "rvm is installed, logout, relogin and run script again to continue\033[0m"
echo ""
echo "-----------------------------------------------"
echo -e "\033[0m"
sleep 2
logout
exit 1
fi
echo ""
echo "-----------------------------------------------"
echo "installing ruby 3.3.6"
echo ""
echo "-----------------------------------------------"
echo ""
rvm autolibs disable
rvm requirements
sudo apt install -y libssl1.0-dev openssl1.0
rvm install 3.3.6 --with-openssl-dir="$HOME"/.rvm/usr
source /etc/profile.d/rvm.sh
sleep 1
echo ""
echo "-----------------------------------------------"
echo "installing bundler"
echo ""
echo "-----------------------------------------------"
echo ""
gem install bundler
echo ""
echo "-----------------------------------------------"
echo "installing postgresql version 14"
echo ""
echo "-----------------------------------------------"
echo ""
sudo apt-get install -y libpq-dev postgresql-14 postgresql-client-14
sleep 1
echo ""
echo "-----------------------------------------------"
echo "installing nodejs"
echo ""
echo "-----------------------------------------------"
echo ""
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
export NVM_DIR=${HOME}/.nvm
source "$NVM_DIR"/nvm.sh
nvm install 20
sleep 1
echo "-----------------------------------------------"
echo "create smlink for nodejs"
echo "-----------------------------------------------"
sudo ln -s "$(which node)" /usr/local/bin/node
echo ""
echo "-----------------------------------------------"
echo "installing yarn"
echo ""
echo "-----------------------------------------------"
echo ""
npm install --global yarn
echo ""
echo "-----------------------------------------------"
echo "installing yarn dependencies"
echo ""
echo "-----------------------------------------------"
echo ""
yarn install
echo ""
echo "-----------------------------------------------"
echo "change git config to store crédentials"
echo ""
echo "-----------------------------------------------"
echo ""
git config --global credential.helper store
echo ""
echo "------------------------------------------------------------"
echo "credentials now stored, use github token when password is asked"
echo ""
echo "------------------------------------------------------------"
echo ""
sleep 1
echo ""
echo "-----------------------------------------------"
echo "installing ruby dependencies"
echo ""
echo "-----------------------------------------------"
echo ""
bundle install
sleep 1
# create variable password with params value or default value
PASSWORD=${1:-"dev-1234"}
echo ""
echo "-----------------------------------------------"
echo "configuring postgres"
echo ""
echo "-----------------------------------------------"
echo ""
sudo -u postgres psql -c "CREATE ROLE $USER WITH LOGIN SUPERUSER PASSWORD '$PASSWORD';" || true
echo ""
echo "-----------------------------------------------"
echo "editing database.yml in config folder"
echo ""
echo "-----------------------------------------------"
echo ""
# if current directory is not root directory, change to root directory
if [ ! -f "config/database.yml" ]; then
cd ..
fi
# replace password ans username in database.yml
sed -i "s/username: .*/username: $USER/g" config/database.yml
sed -i "s/password: .*/password: $PASSWORD/g" config/database.yml
sleep 1
echo ""
echo "-----------------------------------------------"
echo "creating database"
echo ""
echo "-----------------------------------------------"
echo ""
rails db:prepare
echo ""
echo "-----------------------------------------------"
echo "installing foreman"
echo ""
echo "-----------------------------------------------"
echo ""
gem install foreman
echo ""
echo "-----------------------------------------------"
echo "installing dependencies finished, now configuring"
echo ""
echo "-----------------------------------------------"
echo ""
sleep 1
echo ""
echo "-----------------------------------------------"
echo "create default admin user"
echo ""
echo "-----------------------------------------------"
echo ""
# get email from environment variable or default value
EMAIL=${2:-"johndoe@gmail.com"}
FIRST_NAME=${3:-"John"}
LAST_NAME=${4:-"Doe"}
USER_PASSWORD=${5:-"test1234"}
rails console <<EOF
if User.find_by(email: '$EMAIL', first_name: "$FIRST_NAME", last_name: "$LAST_NAME").nil?
u = User.new email: "$EMAIL", is_admin: true, first_name: "$FIRST_NAME", last_name: "$LAST_NAME", current_sign_in_at: DateTime.now, last_sign_in_at: DateTime.now, sign_in_count: 1
u.password = "$USER_PASSWORD"
u.password_confirmation = "$USER_PASSWORD"
u.save!
end
EOF
echo "admin user created with email: $EMAIL, password: $USER_PASSWORD"
sleep 1
echo ""
echo "------------------------------------------------------------------"
echo "configuring finished, you can now run application with foreman start"
echo ""
echo "------------------------------------------------------------------"
echo ""
# wait for user input
read -p "Press enter to exit"