]> git.mxchange.org Git - friendica.git/blob - bin/dev/vagrant_provision.sh
Vagrant: Do not pull PHP requirements during VM setup
[friendica.git] / bin / dev / 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 #
7 # Run as root by vagrant
8 #
9 ##
10
11 ADMIN_NICK="admin"
12 ADMIN_PASSW="admin"
13
14 USER_NICK="user"
15 USER_PASSW="user"
16
17 ##
18
19 echo "Friendica configuration settings"
20 apt-get update
21
22 #Selfsigned cert
23 echo ">>> Installing *.xip.io self-signed SSL"
24 SSL_DIR="/etc/ssl/xip.io"
25 DOMAIN="*.xip.io"
26 EXTRADOMAIN="friendica.local"
27 PASSPHRASE="vaprobash"
28 SUBJ="
29 C=US/
30 ST=Connecticut/
31 O=Vaprobash/
32 localityName=New Haven/
33 commonName=$DOMAIN/
34 subjectAltName=DNS:$EXTRADOMAIN
35 "
36 mkdir -p "$SSL_DIR"
37 openssl genrsa -out "$SSL_DIR/xip.io.key" 4096
38 openssl req -new -subj "$(echo -n "$SUBJ" | tr "\n" "/")" -key "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.csr" -passin pass:$PASSPHRASE
39 openssl x509 -req -days 365 -in "$SSL_DIR/xip.io.csr" -signkey "$SSL_DIR/xip.io.key" -out "$SSL_DIR/xip.io.crt"
40
41
42 #Install apache2
43 echo ">>> Installing Apache2 webserver"
44 apt-get install -qq apache2
45 a2enmod rewrite actions ssl
46 cp /vagrant/bin/dev/vagrant_vhost.sh /usr/local/bin/vhost
47 chmod guo+x /usr/local/bin/vhost
48 vhost -s 192.168.22.10.xip.io -d /var/www -p /etc/ssl/xip.io -c xip.io -a friendica.local
49 a2dissite 000-default
50 service apache2 restart
51
52 #Install php
53 echo ">>> Installing PHP7"
54 apt-get install -qq php libapache2-mod-php php-cli php-mysql php-curl php-gd php-mbstring php-xml imagemagick php-imagick php-zip
55 systemctl restart apache2
56
57 #Install mysql
58 echo ">>> Installing Mysql"
59 debconf-set-selections <<< "mariadb-server mariadb-server/root_password password root"
60 debconf-set-selections <<< "mariadb-server mariadb-server/root_password_again password root"
61 apt-get install -qq mariadb-server
62 # enable remote access
63 # setting the mysql bind-address to allow connections from everywhere
64 sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
65 # adding grant privileges to mysql root user from everywhere
66 # thx to http://stackoverflow.com/questions/7528967/how-to-grant-mysql-privileges-in-a-bash-script for this
67 MYSQL=`which mysql`
68 Q1="GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;"
69 Q2="FLUSH PRIVILEGES;"
70 SQL="${Q1}${Q2}"
71 $MYSQL -uroot -proot -e "$SQL"
72 # add a separate database user for friendica
73 $MYSQL -uroot -proot -e "CREATE USER 'friendica'@'localhost' identified by 'friendica';"
74 $MYSQL -uroot -proot -e "GRANT ALL PRIVILEGES ON friendica.* TO 'friendica'@'localhost';"
75 $MYSQL -uroot -proot -e "FLUSH PRIVILEGES"
76 systemctl restart mysql
77
78
79 #configure rudimentary mail server (local delivery only)
80 #add Friendica accounts for local user accounts, use email address like vagrant@friendica.local, read the email with 'mail'.
81 echo ">>> Installing 'Local Only' postfix"
82 debconf-set-selections <<< "postfix postfix/mailname string friendica.local"
83 debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local Only'"
84 apt-get install -qq postfix mailutils libmailutils-dev
85 echo -e "friendica1:    vagrant\nfriendica2:    vagrant\nfriendica3:    vagrant\nfriendica4:    vagrant\nfriendica5:    vagrant" >> /etc/aliases && newaliases
86
87 # Friendica needs git for fetching some dependencies
88 echo ">>> Installing git"
89 apt-get install -qq git
90
91 #make the vagrant directory the docroot
92 echo ">>> Symlink /var/www to /vagrant"
93 rm -rf /var/www/
94 ln -fs /vagrant /var/www
95
96 # install deps with composer
97 cd /var/www
98
99 echo ">>> Setup Friendica"
100
101 # copy the .htaccess-dist file to .htaccess so that rewrite rules work
102 cp /vagrant/.htaccess-dist /vagrant/.htaccess
103
104 # create the friendica database
105 echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | $MYSQL -u root -proot
106
107 # install friendica
108 bin/console autoinstall -f /vagrant/mods/local.config.vagrant.php
109
110 # add users
111 # (disable a bunch of validation because this is a dev install, deh, it needs invalid emails and stupid passwords)
112 bin/console config system disable_email_validation 1
113 bin/console config system disable_password_exposed 1
114 bin/console user add "$ADMIN_NICK" "$ADMIN_NICK" "$ADMIN_NICK@friendica.local" en
115 bin/console user password "$ADMIN_NICK" "$ADMIN_PASSW"
116 bin/console user add "$USER_NICK" "$USER_NICK" "$USER_NICK@friendica.local" en
117 bin/console user password "$USER_NICK" "$USER_PASSW"
118
119 # set the admin
120 bin/console config config admin_email ""$ADMIN_NICK@friendica.local""
121
122
123 # create cronjob - activate if you have enough memory in you dev VM
124 # cronjob runs as www-data user
125 echo ">>> Installing cronjob"
126 echo "*/10 * * * *    www-data    cd /vagrant; /usr/bin/php bin/worker.php" >> /etc/cron.d/friendica
127
128 # friendica needs write access to /tmp
129 chmod 777 /tmp