]> git.mxchange.org Git - friendica.git/blob - util/vagrant_provision.sh
Merge branch 'develop' into utf8mb4
[friendica.git] / util / vagrant_provision.sh
1 #!/bin/bash
2 #Script to setup the vagrant instance for running friendica
3 #
4 #DO NOT RUN on your physical machine as this won't be of any use 
5 #and f.e. deletes your /var/www/ folder!
6 echo "Friendica configuration settings"
7 sudo apt-get update
8
9 #Selfsigned cert
10 echo ">>> Installing *.xip.io self-signed SSL"
11 SSL_DIR="/etc/ssl/xip.io"
12 DOMAIN="*.xip.io"
13 PASSPHRASE="vaprobash"
14 SUBJ="
15 C=US
16 ST=Connecticut
17 O=Vaprobash
18 localityName=New Haven
19 commonName=$DOMAIN
20 organizationalUnitName=
21 emailAddress=
22 "
23 sudo mkdir -p "$SSL_DIR"
24 sudo openssl genrsa -out "$SSL_DIR/xip.io.key" 4096
25 sudo openssl req -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -key "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.csr" -passin pass:$PASSPHRASE
26 sudo openssl x509 -req -days 365 -in "$SSL_DIR/xip.io.csr" -signkey "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.crt"
27
28
29 #Install apache2
30 echo ">>> Installing Apache2 webserver"
31 sudo apt-get install -y apache2
32 sudo a2enmod rewrite actions ssl
33 sudo cp /vagrant/util/vagrant_vhost.sh /usr/local/bin/vhost
34 sudo chmod guo+x /usr/local/bin/vhost
35 if [ $( lsb_release -c | cut -f 2 ) == "trusty" ]; then
36     sudo vhost -s 192.168.22.10.xip.io -d /var/www -p /etc/ssl/xip.io -c xip.io -a friendica-trusty.dev
37     sudo a2dissite 000-default
38     sudo service apache2 restart
39 elif [ $( lsb_release -c | cut -f 2 ) == "xenial" ]; then
40     sudo vhost -s 192.168.22.11.xip.io -d /var/www -p /etc/ssl/xip.io -c xip.io -a friendica-xenial.dev
41     sudo a2dissite 000-default
42     sudo systemctl restart apache2
43 fi
44
45 #Install php
46 if [ $( lsb_release -c | cut -f 2 ) == "trusty" ]; then
47     echo ">>> Installing PHP5"
48     sudo apt-get install -y php5 libapache2-mod-php5 php5-cli php5-mysql php5-curl php5-gd
49     sudo apt-get install -y imagemagick
50     sudo apt-get install -y php5-imagick
51     sudo service apache2 restart
52 elif [ $( lsb_release -c | cut -f 2 ) == "xenial" ]; then
53     echo ">>> Installing PHP7"
54     sudo apt-get install -y php libapache2-mod-php php-cli php-mysql php-curl php-gd php-mbstring
55     sudo apt-get install -y imagemagick
56     sudo apt-get install -y php-imagick
57     sudo systemctl restart apache2
58 fi
59
60
61 #Install mysql
62 echo ">>> Installing Mysql"
63 sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password root"
64 sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password root"
65 sudo apt-get install -qq mysql-server
66 # enable remote access
67 # setting the mysql bind-address to allow connections from everywhere
68 sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
69 # adding grant privileges to mysql root user from everywhere
70 # thx to http://stackoverflow.com/questions/7528967/how-to-grant-mysql-privileges-in-a-bash-script for this
71 MYSQL=`which mysql`
72 Q1="GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;"
73 Q2="FLUSH PRIVILEGES;"
74 SQL="${Q1}${Q2}"
75 $MYSQL -uroot -proot -e "$SQL"
76 if [ $( lsb_release -c | cut -f 2 ) == "trusty" ]; then
77     service mysql restart
78 elif [ $( lsb_release -c | cut -f 2 ) == "xenial" ]; then
79     systemctl restart mysql
80 fi
81
82
83
84 #configure rudimentary mail server (local delivery only)
85 #add Friendica accounts for local user accounts, use email address like vagrant@friendica.dev, read the email with 'mail'.
86 if [ $( lsb_release -c | cut -f 2 ) == "trusty" ]; then
87     debconf-set-selections <<< "postfix postfix/mailname string friendica-trusty.dev"
88 elif [ $( lsb_release -c | cut -f 2 ) == "xenial" ]; then
89     debconf-set-selections <<< "postfix postfix/mailname string friendica-xenial.dev"
90 fi
91 debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local Only'"
92 sudo apt-get install -y postfix mailutils libmailutils-dev
93 sudo echo -e "friendica1:       vagrant\nfriendica2:    vagrant\nfriendica3:    vagrant\nfriendica4:    vagrant\nfriendica5:    vagrant" >> /etc/aliases && sudo newaliases
94
95 #make the vagrant directory the docroot
96 sudo rm -rf /var/www/
97 sudo ln -fs /vagrant /var/www
98
99 # initial config file for friendica in vagrant
100 cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php
101
102 # create the friendica database
103 echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | mysql -u root -proot
104 # import test database
105 $MYSQL -uroot -proot friendica < /vagrant/friendica_test_data.sql
106
107 #create cronjob
108 echo "*/10 * * * * cd /vagrant; /usr/bin/php include/poller.php" >> friendicacron
109 sudo crontab friendicacron
110 sudo rm friendicacron
111
112 #Optional: checkout addon repositroy
113 #sudo git clone https://github.com/friendica/friendica-addons.git /vagrant/addon