]> BookStack Code Mirror - devops/blob - scripts/installation-ubuntu-16.04.sh
Update installation-ubuntu-16.04.sh
[devops] / scripts / installation-ubuntu-16.04.sh
1 #!/bin/sh
2 # This script will install a new BookStack instance on a fresh Ubuntu 16.04 server.
3 # This script is experimental and does not ensure any security.
4
5 echo ""
6 echo -n "Enter the domain you want to host BookStack and press [ENTER]: "
7 read DOMAIN
8
9 myip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1  -d'/')
10
11 export DEBIAN_FRONTEND=noninteractive
12 apt update
13 apt install -y git nginx curl php7.0-fpm php7.0-curl php7.0-mbstring php7.0-ldap php7.0-mcrypt \
14 php7.0-tidy php7.0-xml php7.0-zip php7.0-gd php7.0-mysql mysql-server-5.7 mcrypt
15
16 # Set up database
17 DB_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)"
18 mysql -u root --execute="CREATE DATABASE bookstack;"
19 mysql -u root --execute="CREATE USER 'bookstack'@'localhost' IDENTIFIED BY '$DB_PASS';"
20 mysql -u root --execute="GRANT ALL ON bookstack.* TO 'bookstack'@'localhost';FLUSH PRIVILEGES;"
21
22 # Download BookStack
23 cd /var/www
24 git clone https://github.com/ssddanbrown/BookStack.git --branch release --single-branch bookstack
25 BOOKSTACK_DIR="/var/www/bookstack"
26 cd $BOOKSTACK_DIR
27
28 # Install composer
29 EXPECTED_SIGNATURE=$(wget https://composer.github.io/installer.sig -O - -q)
30 curl -s https://getcomposer.org/installer > composer-setup.php
31 ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
32
33 if [ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ]
34 then
35     php composer-setup.php --quiet
36     RESULT=$?
37     rm composer-setup.php
38 else
39     >&2 echo 'ERROR: Invalid composer installer signature'
40     rm composer-setup.php
41     exit 1
42 fi
43
44 # Install BookStack composer dependancies
45 php composer.phar install
46
47 # Copy and update BookStack environment variables
48 cp .env.example .env
49 sed -i.bak 's/DB_DATABASE=.*$/DB_DATABASE=bookstack/' .env
50 sed -i.bak 's/DB_USERNAME=.*$/DB_USERNAME=bookstack/' .env
51 sed -i.bak "s/DB_PASSWORD=.*\$/DB_PASSWORD=$DB_PASS/" .env
52 # Generate the application key
53 php artisan key:generate --no-interaction --force
54 # Migrate the databases
55 php artisan migrate --no-interaction --force
56
57 # Set file and folder permissions
58 chown www-data:www-data -R bootstrap/cache public/uploads storage && chmod -R 755 bootstrap/cache public/uploads storage
59
60 # Add nginx configuration
61 curl -s https://raw.githubusercontent.com/BookStackApp/devops/master/config/nginx > /etc/nginx/sites-available/bookstack
62 sed -i.bak "s/bookstack.dev/$DOMAIN/" /etc/nginx/sites-available/bookstack
63 ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/bookstack
64
65 # Remove the default nginx configuration
66 rm /etc/nginx/sites-enabled/default
67
68 # Restart nginx to load new config
69 service nginx restart
70
71 echo ""
72 echo "Setup Finished, Your BookStack instance should now be installed."
73 echo "You can login with the email '[email protected]' and password of 'password'"
74 echo "MySQL was installed without a root password, It is recommended that you set a root MySQL password."
75 echo ""
76 echo "You can access your BookStack instance at: http://$myip/"