Skip to content

Commit

Permalink
Installation script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomek Rękawek committed Jan 8, 2019
1 parent dc9e87c commit cfa1179
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ The web server should redirect all the requests for unknown paths to the [htdocs
3. Upload the files from the [htdocs](htdocs) directory to the web server.
4. Make sure that the web server has permissions to create files in the [htdocs/data](htdocs/data) directory.
5. Configure the Wemos-based detector to send data to the *own API*. Use username and password the same as in the `config.php`. The path should reference the path: `/DEVICE_NAME/update`, where the `DEVICE_NAME` matches the one set in `config.php`.

## Deployment script

[install.sh](install.sh) is an interactive script can be used to setup nginx, PHP and Air Quality Dashboard on a Debian Stretch server. It can be run with a single command:

```
curl https://raw.githubusercontent.com/trekawek/air-quality-info/master/install.sh | bash -e
```

Remember to review the script before running the command below.
82 changes: 82 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

export DEBIAN_FRONTEND="noninteractive"

echo "Installing packages..."
apt-get update -qq
apt-get install -qq nginx php-fpm php-rrd curl zip net-tools

echo "Creating nginx config..."
cat <<EOF > /etc/nginx/sites-enabled/default
server {
listen 80;
server_name default_server;
root /var/www/air-quality-info;
index index.php;
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
# this probably should be updated
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi.conf;
}
}
EOF

echo "Downloading Air Quality Info..."
mkdir -p /var/www/air-quality-info
curl -L https://github.com/trekawek/air-quality-info/archive/master.zip > /tmp/air-quality-info.zip

echo "Unpacking the htdocs"
unzip -q /tmp/air-quality-info.zip -d /tmp
mv /tmp/air-quality-info-master/htdocs/* /var/www/air-quality-info

echo "Configuring Air Quality Info..."
read -e -p 'Enter username: ' username
read -e -s -p 'Enter password: ' password
echo
read -e -p 'Enter sensor id: ' sensor_id

cat <<EOF > /var/www/air-quality-info/config.php
<?php
define('CONFIG', array(
'devices' => array(
array(
'user' => '${username}',
'password' => '${password}',
'esp8266id' => '${sensor_id}',
'name' => 'main', # this will be used in URLs
'description' => 'Main location', # user-friendly location name, will be used in navbar
),
),
# Whether to store the last received JSON dump.
'store_json_payload' => true,
# Google Analytics ID
'ga_id' => ''
));
?>
EOF

chown -R www-data:www-data /var/www/air-quality-info

echo "Starting PHP and nginx..."
/etc/init.d/php7.0-fpm start
/etc/init.d/nginx start

server_ip="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')"

echo "Installation is ready"
echo ""
echo "Page is available at http://${server_ip}"
echo ""
echo "Configuration:"
echo "Server: ${server_ip}"
echo "Path: /main/update"
echo "Port: 80"
echo "User: ${username}"
echo "Password: [redacted]"

0 comments on commit cfa1179

Please sign in to comment.