forked from flexcomng/erpnext_quick_install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherpnext_install.sh
executable file
·423 lines (352 loc) · 13.8 KB
/
erpnext_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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/usr/bin/env bash
# Setting error handler
handle_error() {
local line=$1
local exit_code=$?
echo "An error occurred on line $line with exit status $exit_code"
exit $exit_code
}
trap 'handle_error $LINENO' ERR
set -e
# Retrieve server IP
server_ip=$(hostname -I | awk '{print $1}')
# Setting up colors for echo commands
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
LIGHT_BLUE='\033[1;34m'
NC='\033[0m' # No Color
# Checking Supported OS and distribution
SUPPORTED_DISTRIBUTIONS=("Ubuntu" "Debian")
SUPPORTED_VERSIONS=("22.04" "20.04" "11" "10" "9" "8")
check_os() {
local os_name=$(lsb_release -is)
local os_version=$(lsb_release -rs)
local os_supported=false
local version_supported=false
for i in "${SUPPORTED_DISTRIBUTIONS[@]}"; do
if [[ "$i" = "$os_name" ]]; then
os_supported=true
break
fi
done
for i in "${SUPPORTED_VERSIONS[@]}"; do
if [[ "$i" = "$os_version" ]]; then
version_supported=true
break
fi
done
if [[ "$os_supported" = false ]] || [[ "$version_supported" = false ]]; then
echo -e "${RED}This script is not compatible with your operating system or its version.${NC}"
exit 1
fi
}
check_os
# Detect the platform (similar to $OSTYPE)
OS="`uname`"
case $OS in
'Linux')
OS='Linux'
if [ -f /etc/redhat-release ] ; then
DISTRO='CentOS'
elif [ -f /etc/debian_version ] ; then
if [ "$(lsb_release -si)" == "Ubuntu" ]; then
DISTRO='Ubuntu'
else
DISTRO='Debian'
fi
fi
;;
*) ;;
esac
ask_twice() {
local prompt="$1"
local secret="$2"
local val1 val2
while true; do
if [ "$secret" = "true" ]; then
read -rsp "$prompt: " val1
echo >&2
else
read -rp "$prompt: " val1
echo >&2
fi
if [ "$secret" = "true" ]; then
read -rsp "Confirm password: " val2
echo >&2
else
read -rp "Confirm password: " val2
echo >&2
fi
if [ "$val1" = "$val2" ]; then
printf "${GREEN}Password confirmed${NC}" >&2
echo "$val1"
break
else
printf "${RED}Inputs do not match. Please try again${NC}\n" >&2
echo -e "\n"
fi
done
}
echo -e "\n"
echo -e "${LIGHT_BLUE}Welcome to the ERPNext Installer...${NC}"
echo -e "\n"
sleep 3
#First Let's take you home
cd $(sudo -u $USER echo $HOME)
#Next let's set some important parameters.
#We will need your required SQL root passwords
echo -e "${YELLOW}First let's set some important parameters...${NC}"
sleep 1
echo -e "${YELLOW}We will need your required SQL root password${NC}"
sleep 1
sqlpasswrd=$(ask_twice "What is your required SQL root password" "true")
sleep 1
echo -e "\n"
#Now let's make sure your instance has the most updated packages
echo -e "${YELLOW}Updating system packages...${NC}"
sleep 2
sudo apt update
sudo apt upgrade -y
echo -e "${GREEN}System packages updated.${NC}"
sleep 2
#Now let's install a couple of requirements: git, curl and pip
echo -e "${YELLOW}Installing preliminary package requirements${NC}"
sleep 3
sudo apt -qq install software-properties-common git curl -y
#Next we'll install the python environment manager...
echo -e "${YELLOW}Installing python environment manager and other requirements...${NC}"
sleep 2
# Install Python 3.10 if not already installed or version is less than 3.10
py_version=$(python3 --version 2>&1 | awk '{print $2}')
py_major=$(echo "$py_version" | cut -d '.' -f 1)
py_minor=$(echo "$py_version" | cut -d '.' -f 2)
if [ -z "$py_version" ] || [ "$py_major" -lt 3 ] || [ "$py_major" -eq 3 -a "$py_minor" -lt 10 ]; then
echo -e "${LIGHT_BLUE}It appears this instance does not meet the minimum Python version required for ERPNext 14 (Python3.10)...${NC}"
sleep 2
echo -e "${YELLOW}Not to worry, we will sort it out for you${NC}"
sleep 4
echo -e "${YELLOW}Installing Python 3.10+...${NC}"
sleep 2
sudo apt -qq install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev -y && \
wget https://www.python.org/ftp/python/3.10.11/Python-3.10.11.tgz && \
tar -xf Python-3.10.11.tgz && \
cd Python-3.10.11 && \
./configure --prefix=/usr/local --enable-optimizations --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" && \
make -j $(nproc) && \
sudo make altinstall && \
cd .. && \
sudo rm -rf Python-3.10.11 && \
sudo rm Python-3.10.11.tgz && \
pip3.10 install --user --upgrade pip && \
echo -e "${GREEN}Python3.10 installation successful!${NC}"
sleep 2
fi
echo -e "\n"
echo -e "${YELLOW}Installing additional Python packages and Redis Server${NC}"
sleep 2
sudo apt -qq install git python3-dev python3-setuptools python3-venv python3-pip python3-distutils wkhtmltopdf redis-server -y
echo -e "${GREEN}Done!${NC}"
sleep 1
echo -e "\n"
#... And mariadb with some extra needed applications.
echo -e "${YELLOW}Now installing MariaDB and other necessary packages...${NC}"
sleep 2
sudo apt -qq install mariadb-server mariadb-client xvfb libfontconfig xfonts-75dpi fontconfig libxrender1 -y
echo -e "${GREEN}MariaDB and other packages have been installed successfully.${NC}"
sleep 2
# Use a hidden marker file to determine if this section of the script has run before.
MARKER_FILE=~/.mysql_configured.marker
if [ ! -f "$MARKER_FILE" ]; then
#Now we'll go through the required settings of the mysql_secure_installation...
echo -e ${YELLOW}"Now we'll go ahead to apply MariaDB security settings...${NC}"
sleep 2
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$sqlpasswrd';"
sudo mysql -u root -p"$sqlpasswrd" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$sqlpasswrd';"
sudo mysql -u root -p"$sqlpasswrd" -e "DELETE FROM mysql.user WHERE User='';"
sudo mysql -u root -p"$sqlpasswrd" -e "DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';"
sudo mysql -u root -p"$sqlpasswrd" -e "FLUSH PRIVILEGES;"
echo -e "${YELLOW}...And add some settings to /etc/mysql/my.cnf:${NC}"
sleep 2
sudo bash -c 'cat << EOF >> /etc/mysql/my.cnf
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
EOF'
sudo service mysql restart
# Create the hidden marker file to indicate this section of the script has run.
touch "$MARKER_FILE"
echo -e "${GREEN}MariaDB settings done!${NC}"
echo -e "\n"
sleep 1
fi
#Install NVM, Node, npm and yarn
echo -e ${YELLOW}"Now to install NVM, Node, npm and yarn${NC}"
sleep 2
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
# Add environment variables to .profile
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.profile
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >> ~/.profile
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> ~/.profile
# Source .profile to load the new environment variables in the current session
source ~/.profile
nvm install 16
sudo apt-get -qq install npm -y
sudo npm install -g yarn
echo -e "${GREEN}Package installation complete!${NC}"
sleep 2
# Now let's reactivate virtual environment
if [ "$DISTRO" == "Debian" ]; then
python3.10 -m venv $USER && \
source $USER/bin/activate
nvm use 16
fi
#Install bench
echo -e "${YELLOW}Now let's install bench${NC}"
sleep 2
sudo pip3 install frappe-bench
#Initiate bench in frappe-bench folder, but get a supervisor can't restart bench error...
echo -e "${YELLOW}Initialising bench in frappe-bench folder.${NC}"
echo -e "${LIGHT_BLUE}If you get a restart failed, don't worry, we will resolve that later.${NC}"
bench init frappe-bench --version version-14 --verbose --install-app erpnext --version version-14
echo -e "${GREEN}Bench installation complete!${NC}"
sleep 1
# Prompt user for site name
echo -e "${YELLOW}Preparing for Production installation. This could take a minute... or two so please be patient.${NC}"
read -p "Enter the site name (If you wish to install SSL later, please enter a FQDN): " site_name
sleep 1
adminpasswrd=$(ask_twice "Enter the Administrator password" "true")
echo -e "\n"
sleep 2
# Install expect tool only if needed
echo $passwrd | sudo -S apt -qq install expect -y
echo -e "${YELLOW}Now setting up your site. Please wait...${NC}"
sleep 1
# Change directory to frappe-bench
cd frappe-bench && \
sudo sed -i '/port 6379/a port 11000' /etc/redis/redis.conf
sudo service redis-server restart
# Create new site using expect
export SITE_NAME=$site_name
export SQL_PASSWD=$sqlpasswrd
export ADMIN_PASSWD=$adminpasswrd
#Set Administrator password.
SITE_SETUP=$(expect -c "
set timeout 300
set sitename \$env(SITE_NAME)
set sqlpwd \$env(SQL_PASSWD)
set adminpwd \$env(ADMIN_PASSWD)
spawn bench new-site \$sitename --install-app erpnext
expect \"MySQL root password:\"
send \"\$sqlpwd\r\"
expect \"Set Administrator password:\"
sleep 20
send \"\$adminpwd\r\"
expect \"Re-enter Administrator password:\"
sleep 20
send \"\$adminpwd\r\"
expect eof
")
echo "$SITE_SETUP"
sudo sed -i '/port 11000/d' /etc/redis/redis.conf
sudo service redis-server restart
echo -e "${LIGHT_BLUE}Would you like to continue with production install? (yes/no)${NC}"
read -p "Response: " continue_prod
continue_prod=$(echo "$continue_prod" | tr '[:upper:]' '[:lower:]') # Convert to lowercase
case "$continue_prod" in
"yes" | "y")
echo -e "${YELLOW}Installing packages and dependencies for Production...${NC}"
sleep 2
# Setup supervisor and nginx config
yes | sudo bench setup production $USER && \
echo -e "${YELLOW}Applying necessary permissions to supervisor...${NC}"
sleep 1
# Change ownership of supervisord.conf
sudo sed -i '6i chown='"$USER"':'"$USER"'' /etc/supervisor/supervisord.conf && \
# Restart supervisor
sudo service supervisor restart && \
# Setup production again to reflect the new site
yes | sudo bench setup production $USER && \
echo -e "${YELLOW}Enabling Scheduler...${NC}"
sleep 1
# Enable and resume the scheduler for the site
bench --site $site_name scheduler enable && \
bench --site $site_name scheduler resume && \
echo -e "${YELLOW}Restarting bench to apply all changes and optimizing environment pernissions.${NC}"
sleep 1
# Restart bench
bench restart && \
#Now to make sure the environment is fully setup
sudo chmod 755 /home/$(echo $USER)
sleep 3
printf "${GREEN}Production setup complete! "
printf '\xF0\x9F\x8E\x86'
printf "${NC}\n"
sleep 3
echo -e "${YELLOW}Would you like to install SSL? (yes/no)${NC}"
read -p "Response: " continue_ssl
continue_ssl=$(echo "$continue_ssl" | tr '[:upper:]' '[:lower:]') # Convert to lowercase
case "$continue_ssl" in
"yes" | "y")
echo -e "${YELLOW}Make sure your domain name is pointed to the IP of this instance and is reachable before your proceed.${NC}"
sleep 3
# Prompt user for email
read -p "Enter your email address: " email_address
# Install Certbot
echo -e "${YELLOW}Installing Certbot...${NC}"
sleep 1
if [ "$DISTRO" == "Debian" ]; then
echo -e "${YELLOW}Fixing openssl package on Debian...${NC}"
sleep 4
sudo pip3 uninstall cryptography -y
yes | sudo pip3 install pyopenssl==22.0.0 cryptography==36.0.0
echo -e "${GREEN}Package fixed${NC}"
sleep 2
fi
# Install Certbot
sudo apt -qq install certbot python3-certbot-nginx -y
# Obtain and Install the certificate
echo -e "${YELLOW}Obtaining and installing SSL certificate...${NC}"
sleep 2
sudo certbot --nginx --non-interactive --agree-tos --email $email_address -d $site_name
echo -e "${GREEN}SSL certificate installed successfully.${NC}"
sleep 2
;;
*)
echo -e "${RED}Skipping SSL installation...${NC}"
sleep 3
;;
esac
# Now let's reactivate virtual environment
if [ "$DISTRO" == "Debian" ]; then
deactivate
fi
echo -e "${GREEN}--------------------------------------------------------------------------------"
echo -e "Congratulations! You have successfully installed ERPNext version 14."
echo -e "You can start using your new ERPNext installation by visiting https://$site_name"
echo -e "(if you have enabled SSL and used a Fully Qualified Domain Name"
echo -e "during installation) or http://$server_ip to begin."
echo -e "Install additional apps as required. Visit https://docs.erpnext.com for Documentation."
echo -e "Enjoy using ERPNext!"
echo -e "--------------------------------------------------------------------------------${NC}"
;;
*)
echo -e "${YELLOW}Getting your site ready for development...${NC}"
sleep 2
source ~/.profile
nvm alias default 16
bench use $site_name
bench build
echo -e "${GREEN}Done!"
sleep 5
echo -e "${GREEN}-----------------------------------------------------------------------------------------------"
echo -e "Congratulations! You have successfully installed Frappe and ERPNext version 14 Development Enviromment."
echo -e "Start your instance by running bench start to start your server and visiting http://$server_ip:8000"
echo -e "Install additional apps as required. Visit https://frappeframework.com for Developer Documentation."
echo -e "Enjoy development with Frappe!"
echo -e "-----------------------------------------------------------------------------------------------${NC}"
;;
esac