# ubuntu2004-erpnext.sh -rw-r--r-- 7.7 KiB View raw
                                                                                
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
#!/bin/sh
set -x
#
#
# This sets up ubuntu Focal (20.04) to run bench and erpnext.
# This does all the setup and then puts a file in /opt/bench/newsite.sh
# you will need to edit this file, before running it as the bench user.
# You will almost certainly want to edit *THIS* file, where password is
# you will want to change those.
# also, you probably want to reset the ssh-key down below.
#
#
echo "setup SSH root key"
mkdir -p /root/.ssh
chmod 600 /root/.ssh
echo "ssh-ed25519 ... user@local" > /root/.ssh/authorized_keys
chmod 700 /root/.ssh/authorized_keys
echo "vim as editor"
update-alternatives --set editor /usr/bin/vim.tiny
echo "1G swap"
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

echo "setup erpnext"
adduser bench --home /opt/bench --disabled-password
echo "PATH=$PATH:~/.local/bin/" >> ~bench/.bashrc
echo "alias python=python3" >> ~bench/.bashrc
echo "alias pip=pip3" >> ~bench/.bashrc
# apply to local shell process too.
export PATH=$PATH:~/.local/bin/
alias python=python3
alias pip=pip3

echo "installing python dependencies"
apt-get -y install git python3-dev python3-setuptools python3-pip virtualenv build-essential libffi-dev libssl-dev supervisor
echo "installing mariaDB & Redis"
apt -y install software-properties-common mariadb-server mariadb-client libmysqlclient-dev redis-server
cat << EOF > /etc/mysql/mariadb.conf.d/50-server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
character-set-client-handshake = FALSE
#
# * Basic Settings
#
user                    = mysql
pid-file                = /run/mysqld/mysqld.pid
socket                  = /run/mysqld/mysqld.sock
#port                   = 3306
basedir                 = /usr
datadir                 = /var/lib/mysql
tmpdir                  = /tmp
lc-messages-dir         = /usr/share/mysql
#skip-external-locking

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1

#
# * Fine Tuning
#
#key_buffer_size        = 16M
#max_allowed_packet     = 16M
#thread_stack           = 192K
#thread_cache_size      = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
#myisam_recover_options = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10

#
# * Query Cache Configuration
#
#query_cache_limit      = 1M
query_cache_size        = 16M

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file       = /var/log/mysql/mysql.log
#general_log            = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log_file    = /var/log/mysql/mariadb-slow.log
#long_query_time        = 10
#log_slow_rate_limit    = 1000
#log_slow_verbosity     = query_plan
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
#max_binlog_size        = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = exclude_database_name

#
# * Security Features
#
# Read the manual, too, if you want chroot!
#chroot = /var/lib/mysql/
#
# For generating SSL certificates you can use for example the GUI tool "tinyca".
#
#ssl-ca = /etc/mysql/cacert.pem
#ssl-cert = /etc/mysql/server-cert.pem
#ssl-key = /etc/mysql/server-key.pem
#
# Accept only connections using the latest and most secure TLS protocol version.
# ..when MariaDB is compiled with OpenSSL:
#ssl-cipher = TLSv1.2
# ..when MariaDB is compiled with YaSSL (default in Debian):
#ssl = on

#
# * Character sets
#
# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf
#
character-set-server  = utf8mb4
#collation-server      = utf8mb4_general_ci
collation-server = utf8mb4_unicode_ci
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!

#
# * Unix socket authentication plugin is built-in since 10.0.22-6
#
# Needed so the root database user can authenticate without a password but
# only when running as the unix root user.
#
# Also available for other users if required.
# See https://mariadb.com/kb/en/unix_socket-authentication-plugin/

[mysql]
default-character-set = utf8mb4
 

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.3 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.3]

EOF
service mysql restart
sleep 1
cat <<EOF | mysql -uroot
create user bench@localhost identified by '';
GRANT all privileges on *.* to 'bench'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT all privileges on *.* to 'bench'@'127.%.%.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT all privileges on *.* to 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT all privileges on *.* to 'root'@'127.%.%.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EOF
echo "setting up redis"
sed -i -e 's/^supervised no/supervised systemd/' /etc/redis/redis.conf
systemctl restart redis.service
echo "nodejs, yarn & wkhtmltopdf"
apt -y install curl
curl -sL https://deb.nodesource.com/setup_12.x 1 | sudo -E bash -
apt -y install nodejs
apt -y install nodejs && apt-get install -y gcc g++ make
npm install -g yarn
apt -y install wkhtmltopdf
wkhtmltopdf --version
wkhtmltoimage --version
echo "install and setup nginx"
apt -y install nginx
rm -f /etc/nginx/sites-enabled/*
ln -s /opt/bench/frappe-bench/config/nginx.conf /etc/nginx/sites-enabled/frappe.conf
service nginx restart
echo "installing bench"
cd /opt/bench
sudo -u bench -H git clone -b master https://github.com/frappe/bench.git ~bench/.bench
sudo -u bench -H pip3 install ~bench/.bench
sudo -u bench -H ~bench/.local/bin/bench init --frappe-branch version-12 --python /usr/bin/python3 /opt/bench/frappe-bench
sudo -u bench -H ~bench/.local/bin/bench setup supervisor
ln -s /opt/bench/frappe-bench/config/supervisor.conf /etc/supervisor/conf.d/frappe-bench.conf
cd /opt/bench/frappe-bench
echo "installed bench"
cat <<EOF > /opt/bench/newsite.sh
export NODE_OPTIONS="--max-old-space-size=4096"
cd /opt/bench/frappe-bench
bench new-site --db-password password test.site
bench --site test.site enable-scheduler 
bench setup socketio
bench update --requirements
bench build
bench setup nginx
bench setup redis
bench setup procfile
bench update
bench get-app --branch version-12 erpnext
bench --site test.site install-app erpnext
echo "to start as root: service supervisor restart"
echo "if you get a setting up refresh again message, set maintenance_mode = 0 in file: ~bench/frappe-bench/sites/common_site_config.json"
EOF
chmod 0700 /opt/bench/newsite.sh
chown bench /opt/bench/newsite.sh
echo "newsite stuff not run, be sure to run it as bench user file: ~bench/newsite.sh"
echo "cleanup unneeded packages"
apt -y autoremove
reboot