-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
165 lines (127 loc) · 2.83 KB
/
script.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
#!/bin/bash
set -eu
trap end_install EXIT
#
##
update_system() {
#
apt update
apt -yqq upgrade
}
#
##
install_base_system() {
apt -yqq install perl 2>&1
#
echo "UTC" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>/dev/null
}
#
##
get_passwords() {
# check if existing passwords file exists
if [ ! -f /root/passwords.txt ]; then
echo "Error: expecting /root/passwords.txt file to exist"
exit 1
else
# load existing file
set -o allexport
source /root/passwords.txt
set +o allexport
fi
}
#
##
install_wordpress() {
#
cd /var/www/html
#
rm -f index.php
rm -f index.html
# download
curl -O https://wordpress.org/latest.tar.gz
# untar
tar -zxvf latest.tar.gz
# change dir to wordpress
cd wordpress
# copy file to parent dir
cp -rf . ..
# move back to parent dir
cd ..
# remove wordpress folder
rm -R wordpress
# create wp config
cp wp-config-sample.php wp-config.php
# set database details (find and replace)
sed -i "s/database_name_here/$dbname/g" wp-config.php
sed -i "s/username_here/$dbuser/g" wp-config.php
sed -i "s/password_here/$dbpass/g" wp-config.php
# set WP salts
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
# create uploads folder and set permissions
mkdir -p wp-content/uploads
chmod 775 wp-content/uploads
# change ownership
chown www-data:www-data . -Rf
# remove zip file
rm latest.tar.gz
}
#
##
install_adminer() {
#
wget http://www.adminer.org/latest.php -O /var/www/html/adminer.php
chown www-data:www-data /var/www/html/adminer.php
}
start_install() {
#
. /etc/os-release
# check is root user
if [[ $EUID -ne 0 ]]; then
echo "You must be root user to install scripts."
sudo su
fi
# check os is ubuntu
if [[ $ID != "ubuntu" ]]; then
echo "Wrong OS! Sorry only Ubuntu is supported."
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
echo >&2 "Deploy-Script: [OS] $PRETTY_NAME"
}
end_install() {
# clean up apt
apt-get autoremove -y && apt-get autoclean -y && apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# return to dialog
export DEBIAN_FRONTEND=dialog
# remove script
rm -f script.sh
}
#
##
main() {
#
start_install
#
update_system
#
install_base_system
#
get_passwords
#
install_wordpress
#
install_adminer
#
end_install
echo >&2 "Wordpress install completed"
}
main