22
33# Tech and Me - ©2017, https://www.techandme.se/
44
5+ # Check for errors + debug code and abort if something isn't right
6+ # 1 = ON
7+ # 0 = OFF
8+ DEBUG=0
9+
510WWW_ROOT=/var/www/html
611WPATH=$WWW_ROOT /wordpress
712SCRIPTS=/var/scripts
@@ -13,44 +18,61 @@ PHPMYADMIN_CONF="/etc/apache2/conf-available/phpmyadmin.conf"
1318STATIC=" https://raw.githubusercontent.com/techandme/wordpress-vm/master/static"
1419LETS_ENC=" https://raw.githubusercontent.com/techandme/wordpress-vm/master/lets-encrypt"
1520
21+ # DEBUG mode
22+ if [ $DEBUG -eq 1 ]
23+ then
24+ set -e
25+ set -x
26+ else
27+ sleep 1
28+ fi
29+
1630# Check if root
17- if [ " $( whoami) " != " root" ]; then
18- echo
19- echo -e " \e[31mSorry, you are not root.\n\e[0mYou must type: \e[36msudo \e[0mbash $SCRIPTS /wordpress-startup-script.sh"
20- echo
21- exit 1
22- fi
31+ if [ " $( whoami) " != " root" ]
32+ then
33+ echo
34+ echo -e " \e[31mSorry, you are not root.\n\e[0mYou must type: \e[36msudo \e[0mbash $SCRIPTS /wordpress-startup-script.sh"
35+ echo
36+ exit 1
37+ fi
2338
39+ # Check network
40+ echo " Testing if network is OK..."
41+ service networking restart
42+ curl -s http://github.com > /dev/null
43+ if [ $? -eq 0 ]
44+ then
45+ echo -e " \e[32mOnline!\e[0m"
46+ else
47+ echo " Setting correct interface..."
2448# Set correct interface
2549{ sed ' /# The primary network interface/q' /etc/network/interfaces; printf ' auto %s\niface %s inet dhcp\n# This is an autoconfigured IPv6 interface\niface %s inet6 auto\n' " $IFACE " " $IFACE " " $IFACE " ; } > /etc/network/interfaces.new
2650mv /etc/network/interfaces.new /etc/network/interfaces
2751service networking restart
52+ fi
2853
2954# Check network
3055echo " Testing if network is OK..."
31- sleep 2
32- sudo ifdown $IFACE && sudo ifup $IFACE
33- wget -q --spider http://github.com
34- if [ $? -eq 0 ] ; then
35- echo -e " \e[32mOnline!\e[0m"
36- else
37- echo
38- echo " Network NOT OK. You must have a working Network connection to run this script."
39- echo " Please report this to : https://github.com/techandme/wordpress-vm/issues/new"
40- exit 1
41- fi
56+ service networking restart
57+ curl -s http://github.com > /dev/null
58+ if [ $? -eq 0 ]
59+ then
60+ echo -e " \e[32mOnline!\e[0m"
61+ else
62+ echo
63+ echo " Network NOT OK. You must have a working Network connection to run this script."
64+ echo " Please report this issue here : https://github.com/techandme/wordpress-vm/issues/new"
65+ exit 1
66+ fi
4267
43- # Locate the best mirrors
68+ # Get the best mirrors for Ubuntu based on location
4469echo " Locating the best mirrors..."
45- apt update -q2
46- apt install python-pip -y
47- pip install \
48- --upgrade pip \
49- apt-select
5070apt-select
5171sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
72+ if [ -f sources.list ]
73+ then
5274sudo mv sources.list /etc/apt/
53- clear
75+ fi
5476
5577ADDRESS=$( hostname -I | cut -d ' ' -f 1)
5678
@@ -168,6 +190,117 @@ EOMSTART
168190echo -e " \e[32m"
169191read -p " Press any key to start the script..." -n1 -s
170192echo -e " \e[0m"
193+ clear
194+
195+ # Set hostname and ServerName
196+ echo " Setting hostname..."
197+ FQN=$( host -TtA $( hostname -s) | grep " has address" | awk ' {print $1}' ) ; \
198+ if [[ " $FQN " == " " ]]
199+ then
200+ FQN=$( hostname -s)
201+ fi
202+ sudo sh -c " echo 'ServerName $FQN ' >> /etc/apache2/apache2.conf"
203+ sudo hostnamectl set-hostname $FQN
204+ service apache2 restart
205+ cat << ETCHOSTS > "/etc/hosts"
206+ 127.0.1.1 $FQN .localdomain $FQN
207+ 127.0.0.1 localhost
208+
209+ # The following lines are desirable for IPv6 capable hosts
210+ ::1 localhost ip6-localhost ip6-loopback
211+ ff02::1 ip6-allnodes
212+ ff02::2 ip6-allrouters
213+ ETCHOSTS
214+
215+ # VPS?
216+ function ask_yes_or_no() {
217+ read -p " $1 ([y]es or [N]o): "
218+ case $( echo $REPLY | tr ' [A-Z]' ' [a-z]' ) in
219+ y|yes) echo " yes" ;;
220+ * ) echo " no" ;;
221+ esac
222+ }
223+
224+ if [[ " no" == $( ask_yes_or_no " Do you run this script on a *remote* VPS like DigitalOcean, HostGator or similar?" ) ]]
225+ then
226+ # Change IP
227+ echo -e " \e[0m"
228+ echo " OK, we assume you run this locally and we will now configure your IP to be static."
229+ echo -e " \e[1m"
230+ echo " Your internal IP is: $ADDRESS "
231+ echo -e " \e[0m"
232+ echo -e " Write this down, you will need it to set static IP"
233+ echo -e " in your router later. It's included in this guide:"
234+ echo -e " https://www.techandme.se/open-port-80-443/ (step 1 - 5)"
235+ echo -e " \e[32m"
236+ read -p " Press any key to set static IP..." -n1 -s
237+ echo -e " \e[0m"
238+ ifdown $IFACE
239+ sleep 1
240+ ifup $IFACE
241+ sleep 1
242+ bash $SCRIPTS /ip.sh
243+ if [ " $IFACE " = " " ]
244+ then
245+ echo " IFACE is an emtpy value. Trying to set IFACE with another method..."
246+ wget -q $STATIC /ip2.sh -P $SCRIPTS
247+ bash $SCRIPTS /ip2.sh
248+ rm $SCRIPTS /ip2.sh
249+ fi
250+ ifdown $IFACE
251+ sleep 1
252+ ifup $IFACE
253+ sleep 1
254+ echo
255+ echo " Testing if network is OK..."
256+ sleep 1
257+ echo
258+ CONTEST=$( bash $SCRIPTS /test_connection.sh)
259+ if [ " $CONTEST " == " Connected!" ]
260+ then
261+ # Connected!
262+ echo -e " \e[32mConnected!\e[0m"
263+ echo
264+ echo -e " We will use the DHCP IP: \e[32m$ADDRESS \e[0m. If you want to change it later then just edit the interfaces file:"
265+ echo " sudo nano /etc/network/interfaces"
266+ echo
267+ echo " If you experience any bugs, please report it here:"
268+ echo " https://github.com/techandme/wordpress-vm/issues/new"
269+ echo -e " \e[32m"
270+ read -p " Press any key to continue..." -n1 -s
271+ echo -e " \e[0m"
272+ else
273+ # Not connected!
274+ echo -e " \e[31mNot Connected\e[0m\nYou should change your settings manually in the next step."
275+ echo -e " \e[32m"
276+ read -p " Press any key to open /etc/network/interfaces..." -n1 -s
277+ echo -e " \e[0m"
278+ nano /etc/network/interfaces
279+ service networking restart
280+ clear
281+ echo " Testing if network is OK..."
282+ ifdown $IFACE
283+ sleep 1
284+ ifup $IFACE
285+ sleep 1
286+ bash $SCRIPTS /test_connection.sh
287+ sleep 1
288+ fi
289+ else
290+ echo " OK, then we will not set a static IP as your VPS provider already have setup the network for you..."
291+ sleep 5
292+ fi
293+ clear
294+
295+ # Set keyboard layout
296+ echo " Current keyboard layout is $( localectl status | grep " Layout" | awk ' {print $3}' ) "
297+ echo " You must change keyboard layout to your language"
298+ echo -e " \e[32m"
299+ read -p " Press any key to change keyboard layout... " -n1 -s
300+ echo -e " \e[0m"
301+ dpkg-reconfigure keyboard-configuration
302+ echo
303+ clear
171304
172305# Get new server keys
173306rm -v /etc/ssh/ssh_host_*
0 commit comments