-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·279 lines (219 loc) · 7.02 KB
/
setup.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
#!/bin/bash
currentUser=$(whoami)
if [ "${currentUser}" == 'root' ]
then
echo 'Run without sudo.'
exit 0
fi
# prevent running if log file already exists, no need for running this twice
if [ -f "$HOME/.ubuntu-setup" ]; then
echo "Setup already run."
exit 1
fi
echo "Setup run at $(date +"%Y-%m-%d %T")" > "$HOME/.ubuntu-setup"
# get user inputs
echo "Setting up your default user config for GIT."
echo "Your name:"
read namevar
echo "Your email:"
read emailvar
echo "Do you want Composer installed? (y/n)"
read composer
echo "Do you want to install WP-CLI? (y/n)"
read wpCli
echo "Do you want to install NVM, Node.js, NPM and Gulp globally? (y/n)"
read node
echo "Do you want to install Sublime Text (y/n)"
read sublime
echo "Do you want to install VSCode (y/n)"
read vscode
echo "Do you want to install PHPStorm (y/n)"
read phpstorm
# ########
# Add repositories
# ########
sudo add-apt-repository -y ppa:ondrej/php
sudo add-apt-repository -y ppa:phpmyadmin/ppa
sudo apt-get update
sudo apt-get upgrade -y
# install general requirements
sudo apt-get install -y software-properties-common gdebi curl git libfreetype6-dev libjpeg-dev libmagickwand-dev libpng-dev libzip-dev default-jre xbindkeys
# ########
# Setup Apache, PHP, MySQL
# ########
# install apache2
sudo apt-get install -y apache2
sudo systemctl start apache2
sudo systemctl enable apache2
# setup permissions for /var/www
sudo gpasswd -a "${currentUser}" www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R 1775 /var/www
sudo setfacl -Rdm g:www-data:rwx /var/www
sudo setfacl -Rdm u:www-data:rwx /var/www
sudo setfacl -Rdm "u:${currentUser}:rwx" /var/www
# set root for 'localhost' to /var/www
sudo sed -i "s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www/g" /etc/apache2/sites-available/000-default.conf
sudo systemctl restart apache2
# setup vhost script
wget https://raw.githubusercontent.com/djboris88/ubuntu-setup/master/virtualhost.sh
sudo mv virtualhost.sh /usr/bin/vhost
sudo chmod +x /usr/bin/vhost
# install php 7.3
sudo apt-get install -y php7.3-fpm php7.3-common php7.3-zip php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-json php7.3-mysql php7.3-pdo php7.3-gd php7.3-imagick php7.3-ldap php7.3-imap php7.3-mbstring php7.3-intl php7.3-cli php7.3-recode php7.3-tidy php7.3-bcmath php7.3-opcache php7.3-xdebug
# configure php
declare -A confs=(
[max_execution_time]=180
[max_input_time]=360
[max_input_vars]=5000
[memory_limit]=256M
[upload_max_filesize]=128M
[post_max_size]=128M
[file_uploads]=On
[allow_url_fopen]=On
[cgi.fix_pathinfo]=0
)
for i in "${!confs[@]}"; do
search=$i
replace=${confs[$i]}
sudo sed -i -E "s/.?(${search}).+/\1 = ${replace}/g" /etc/php/7.3/fpm/php.ini
done
# configure opcache
opcacheSettings="opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
opcache.revalidate_freq = 2
opcache.fast_shutdown = 1"
! grep "${opcacheSettings}" -q /etc/php/7.3/mods-available/opcache.ini && echo "${opcacheSettings}" | sudo tee -a /etc/php/7.3/mods-available/opcache.ini
# configure xdebug
xdebugSettings="xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_log = /tmp/xdebug_remote.log
xdebug.remote_mode = req
xdebug.remote_port = 9000"
! grep "${xdebugSettings}" -q /etc/php/7.3/mods-available/xdebug.ini && echo "${xdebugSettings}" | sudo tee -a /etc/php/7.3/mods-available/xdebug.ini
# enable everything and restart apache
sudo a2enmod proxy_fcgi setenvif rewrite
sudo a2enconf php7.3-fpm
sudo systemctl restart apache2
sudo systemctl restart php7.3-fpm
# setup mysql and phpmyadmin
sudo apt-get install -y mariadb-server mariadb-client
sudo apt-get install -y phpmyadmin
# create dev:dev user for phpmyadmin
sudo mysql --user=root mysql --execute="CREATE USER 'dev'@'%' IDENTIFIED BY 'dev';
GRANT ALL PRIVILEGES ON *.* TO 'dev'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;"
sudo systemctl restart apache2
# ########
# Setup DevTools
# ########
# install Composer
if [[ ${composer,,} == "y" ]]
then
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
fi
# install WP-CLI
if [[ ${wpCli,,} == "y" ]]
then
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
fi
# install NVM
if [[ ${node,,} == "y" ]]
then
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# setup Node.js and global npm modules
nvm install 10.15.3
npm i -g gulp-cli yarn
fi
# ########
# Install basic software
# ########
# code editors/IDEs
if [[ ${sublime,,} == "y" ]]
then
sudo snap install sublime-text --classic
fi
if [[ ${vscode,,} == "y" ]]
then
sudo snap install code --classic
fi
if [[ ${phpstorm,,} == "y" ]]
then
sudo snap install phpstorm --classic
fi
# Skype
sudo snap install skype --classic
# Clipboard manager
sudo apt-get install -y copyq
# Screenshot tool
sudo apt-get install -y flameshot
# Chrome
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
wget -qO - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y google-chrome-stable
# git client GitEye
wget -O giteye.zip https://www.collab.net/sites/default/files/downloads/GitEye-2.2.0-linux.x86_64.zip
sudo unzip -o giteye.zip -d /opt/giteye
rm -f giteye.zip
sudo ln -sf /opt/giteye/GitEye /usr/bin/GitEye
echo "[Desktop Entry]
Version=2.2.0
Name=GitEye
Comment=GitEye
Type=Application
Categories=Development;IDE;
Exec=/usr/bin/GitEye
Terminal=false
StartupNotify=true
Icon=/opt/giteye/icon.xpm
Name[en_US]=GitEye" | sudo tee /usr/share/applications/giteye.desktop
# keybindings
gsettings set org.gnome.settings-daemon.plugins.media-keys screenshot ['']
echo '"flameshot gui"
Mod2 + Print' >> "$HOME/.xbindkeysrc"
echo '"copyq menu"
Control+Mod2 + grave' >> "$HOME/.xbindkeysrc"
# autostart
mkdir "$HOME/.config/autostart"
echo "[Desktop Entry]
Name=flameshot
Icon=flameshot
Exec=flameshot
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true" > "$HOME/.config/autostart/flameshot.desktop"
echo "[Desktop Entry]
Name=CopyQ
Icon=copyq
Exec=copyq
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true" > "$HOME/.config/autostart/copyq.desktop"
echo "[Desktop Entry]
Name=skype
Icon=skype
Exec=skype
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true" > "$HOME/.config/autostart/skype.desktop"
# setup GIT
git config --global user.name "${namevar}"
git config --global user.email "${emailvar}"
echo "Setup completed at $(date +"%Y-%m-%d %T")" > "$HOME/.ubuntu-setup"
echo "Some of the settings (key bindings) will not work until you reboot."
echo "Do you want to reboot right now? (yes/no)"
read rebootvar
if [[ ${rebootvar,,} == "yes" ]]
then
sudo reboot
fi