[SDC] update configuration template in chef os
[sdc.git] / catalog-fe / src / test / resources / CI / originalResources / scripts / install_apache.sh
1 #!/bin/bash
2
3 echo "Using apt-get. Installing apache2 on one of the following : Debian, Ubuntu, Mint"
4 LOCK="/tmp/lockaptget"
5 DEFAULT_PORT=80
6
7 while true; do
8   if mkdir "${LOCK}" &>/dev/null; then
9     echo "Apache take the lock"
10     break;
11   fi
12   echo "Waiting the end of one of our recipes..."
13   sleep 0.5
14 done
15
16 while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
17   echo "Waiting for other software managers to finish..."
18   sleep 0.5
19 done
20
21 sudo rm -f /var/lib/dpkg/lock
22 sudo apt-get update || (sleep 15; sudo apt-get update || exit ${1})
23 sudo apt-get install -y -q apache2 || exit ${1}
24 rm -rf "${LOCK}"
25
26 sudo /etc/init.d/apache2 stop
27 if [ ! -d $DOC_ROOT ]; then
28   eval "sudo mkdir -p $DOC_ROOT"
29 fi
30 eval "sudo chown -R www-data:www-data $DOC_ROOT"
31
32 if [[ ("$PORT" == "$DEFAULT_PORT") ]]; then
33   echo "Use default port for Apache : $DEFAULT_PORT"
34 else
35   echo "Replacing port $DEFAULT_PORT with $PORT..."
36   sudo sed -i -e "s/$DEFAULT_PORT/$PORT/g" /etc/apache2/ports.conf || exit ${1}
37 fi
38
39 echo "Change config of apache2"
40 if sudo test -f "/etc/apache2/sites-available/default"; then
41   echo "Change the DocumentRoot of apache2 on Ubuntu < 14.04"
42   sudo sed -i -e "s#DocumentRoot /var/www#DocumentRoot $DOC_ROOT#g" /etc/apache2/sites-available/default
43 fi
44 if sudo test -f "/etc/apache2/sites-available/000-default.conf"; then
45   echo "Change the DocumentRoot of Apache2 on Ubuntu >= 14.04"
46   sudo sed -i -e "s#DocumentRoot /var/www/html#DocumentRoot $DOC_ROOT#g" /etc/apache2/sites-available/000-default.conf
47 fi
48
49 sudo bash -c "echo ServerName localhost >> /etc/apache2/apache2.conf"
50
51 echo "Start apache2 whith new conf"
52 sudo /etc/init.d/apache2 start
53 echo "End of $0"