From 151976dd7a18a853d2bd787b438c71e63a0860bb Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Tue, 8 Dec 2015 20:48:00 -0600 Subject: [PATCH] Initial Commit --- WellDataEmpty.sql | 216 +++++++++++++++++++++++++++++++++++++++++ checkCurrentVersion.py | 63 ++++++++++++ config | 3 + default | 125 ++++++++++++++++++++++++ dhcpd.conf | 117 ++++++++++++++++++++++ henryPumpDev.pub | 1 + hostapd | 20 ++++ hostapd.conf | 13 +++ hostname | 1 + initialSetup.sh | 8 ++ interfaces | 20 ++++ isc-dhcp-server | 21 ++++ loggers | 43 ++++++++ my.cnf | 124 +++++++++++++++++++++++ setup.sh | 137 ++++++++++++++++++++++++++ setupUsers.sql | 7 ++ usbMount | 34 +++++++ website | 41 ++++++++ 18 files changed, 994 insertions(+) create mode 100644 WellDataEmpty.sql create mode 100644 checkCurrentVersion.py create mode 100644 config create mode 100644 default create mode 100644 dhcpd.conf create mode 100644 henryPumpDev.pub create mode 100644 hostapd create mode 100644 hostapd.conf create mode 100644 hostname create mode 100644 initialSetup.sh create mode 100644 interfaces create mode 100644 isc-dhcp-server create mode 100644 loggers create mode 100644 my.cnf create mode 100644 setup.sh create mode 100644 setupUsers.sql create mode 100644 usbMount create mode 100644 website diff --git a/WellDataEmpty.sql b/WellDataEmpty.sql new file mode 100644 index 0000000..0ea1727 --- /dev/null +++ b/WellDataEmpty.sql @@ -0,0 +1,216 @@ +-- MySQL dump 10.15 Distrib 10.0.12-MariaDB, for debian-linux-gnu (armv6l) +-- +-- Host: localhost Database: WellData +-- ------------------------------------------------------ +-- Server version 10.0.12-MariaDB-1~wheezy-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `Event_List` +-- +CREATE DATABASE IF NOT EXISTS WellData; +USE WellData; +DROP TABLE IF EXISTS `Event_List`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Event_List` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `device_name` varchar(45) DEFAULT NULL, + `type` varchar(45) DEFAULT NULL, + `cond` varchar(45) DEFAULT NULL, + `value` float DEFAULT NULL, + `datetime` datetime DEFAULT NULL, + `tag` varchar(45) DEFAULT NULL, + `stroke_number` int(16) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `Event_List` +-- + +LOCK TABLES `Event_List` WRITE; +/*!40000 ALTER TABLE `Event_List` DISABLE KEYS */; +/*!40000 ALTER TABLE `Event_List` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `Hist_Day` +-- + +DROP TABLE IF EXISTS `Hist_Day`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Hist_Day` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `gauge_date` datetime DEFAULT NULL, + `percent_run` float DEFAULT NULL, + `kWh` float DEFAULT NULL, + `electricity_cost` float DEFAULT NULL, + `peak_load` float DEFAULT NULL, + `min_load` float DEFAULT NULL, + `average_SPM` float DEFAULT NULL, + `production_calculated` float DEFAULT NULL, + `full_card_production` float DEFAULT NULL, + `polished_rod_HP` float DEFAULT NULL, + `lifting_cost` float DEFAULT NULL, + `fluid_above_pump` float DEFAULT NULL, + `pump_intake_pressure` float DEFAULT NULL, + `kWh_regen` float DEFAULT NULL, + `inflow_rate` float DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `Hist_Day` +-- + +LOCK TABLES `Hist_Day` WRITE; +/*!40000 ALTER TABLE `Hist_Day` DISABLE KEYS */; +/*!40000 ALTER TABLE `Hist_Day` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `Well_Test` +-- + +DROP TABLE IF EXISTS `Well_Test`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Well_Test` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `test_date` datetime DEFAULT NULL, + `test_volume_oil` float DEFAULT NULL, + `test_volume_water` float DEFAULT NULL, + `test_volume_gas` float DEFAULT NULL, + `k_factor` float DEFAULT NULL, + `projected_volume_oil` float DEFAULT NULL, + `projected_volume_water` float DEFAULT NULL, + `api_gravity_oil` float DEFAULT NULL, + `sg_oil` float DEFAULT NULL, + `sg_water` float DEFAULT NULL, + `test_hours` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `Well_Test` +-- + +LOCK TABLES `Well_Test` WRITE; +/*!40000 ALTER TABLE `Well_Test` DISABLE KEYS */; +/*!40000 ALTER TABLE `Well_Test` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `config` +-- + +DROP TABLE IF EXISTS `config`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `config` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `device_type` varchar(45) DEFAULT NULL, + `ip_address` varchar(45) DEFAULT NULL, + `dateChanged` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `config` +-- + + +DROP TABLE IF EXISTS `Notes`; + +CREATE TABLE `Notes` ( + `id` INT NOT NULL AUTO_INCREMENT , + `author` VARCHAR(64) NULL , + `note` VARCHAR(512) NULL , + `datetime` TIMESTAMP NULL DEFAULT NOW() , + `type` INT NULL , + `associated_stroke` INT NULL , + `deleted` INT NULL DEFAULT 0 , + PRIMARY KEY (`id`) ); + + +-- Dump completed on 2015-02-25 20:36:45 +DROP TABLE IF EXISTS `note_types`; + +CREATE TABLE `WellData`.`note_types` ( + `id` INT NOT NULL AUTO_INCREMENT , + `type` VARCHAR(64) NULL , + `deleted` INT NULL DEFAULT 0 , + PRIMARY KEY (`id`) ); + + +INSERT INTO `WellData`.`note_types` (`id`, `type`) VALUES ('1', 'Downtime Explanation'); +INSERT INTO `WellData`.`note_types` (`id`, `type`) VALUES ('2', 'Configuration Change'); +INSERT INTO `WellData`.`note_types` (`id`, `type`) VALUES ('3', 'Info'); +INSERT INTO `WellData`.`note_types` (`id`, `type`) VALUES ('4', 'Other'); + +DROP TABLE IF EXISTS `fluid_shot`; + +CREATE TABLE `WellData`.`fluid_shot` ( + `id` INT NOT NULL AUTO_INCREMENT, + `shot_datetime` DATETIME NULL, + `pump_intake_pressure` FLOAT NULL, + `fluid_gradient` FLOAT NULL, + `friction` FLOAT NULL, + PRIMARY KEY (`id`)); + + + CREATE TABLE `card_history` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Stroke_Time` datetime DEFAULT NULL, + `Card_ID` int(11) NOT NULL, + `Num_Tapers` int(11) DEFAULT NULL, + `Num_Points` int(11) DEFAULT NULL, + `Card_Type` varchar(45) DEFAULT NULL, + `Tubing_Head_Pressure` float DEFAULT NULL, + `Fluid_Gradient` float DEFAULT NULL, + `Stuffing_Box_Friction` float DEFAULT NULL, + `dt` float DEFAULT NULL, + `Downhole_Max_Load` float DEFAULT NULL, + `Downhole_Min_Load` float DEFAULT NULL, + `Downhole_Max_Position` float DEFAULT NULL, + `Downhole_Min_Position` float DEFAULT NULL, + `Downhole_Gross_Stroke` float DEFAULT NULL, + `Downhole_Adjusted_Gross_Stroke` float DEFAULT NULL, + `Downhole_Net_Stroke` float DEFAULT NULL, + `Downhole_Fluid_Load` float DEFAULT NULL, + `Surface_Max_Load` float DEFAULT NULL, + `Surface_Min_Load` float DEFAULT NULL, + `Surface_Max_Position` float DEFAULT NULL, + `Surface_Min_Position` float DEFAULT NULL, + `Tubing_Movement` float DEFAULT NULL, + `Surface_Stroke_Length` float DEFAULT NULL, + `Fillage_Percent` float DEFAULT NULL, + `Polished_Rod_HP` float DEFAULT NULL, + `Pump_HP` float DEFAULT NULL, + `SPM` float DEFAULT NULL, + `Fluid_Level` float DEFAULT NULL, + `Pump_Intake_Pressure` float DEFAULT NULL, + `Stroke_Production` float DEFAULT NULL, + `Drive_Torque_Mode` int(11) DEFAULT NULL, + `Drive_Reference` float DEFAULT NULL, + `Surface_Position` blob, + `Surface_Load` blob, + `Downhole_Position` blob, + `Downhole_Load` blob, + PRIMARY KEY (`id`,`Card_ID`) +); diff --git a/checkCurrentVersion.py b/checkCurrentVersion.py new file mode 100644 index 0000000..8c21de1 --- /dev/null +++ b/checkCurrentVersion.py @@ -0,0 +1,63 @@ +import boto3 +import re +import zipfile +import os +import sys + +#localFilename = "/Users/patrickjmcd/Dropbox (Henry Pump)/Patrick McDonagh/POConsole/POConsole/currentVersion.txt" +outputFolder = "/home/poconsole/src" +localFilename = "{0}/{1}".format(outputFolder, "currentVersion.txt") + +#s3 = boto3.resource('s3') +client = boto3.client('s3') + +def checkUpdateNeeded(force = False): + currentVersionObj = client.get_object(Bucket='henrypumpdata', Key='currentVersion.txt') + s3currentVersionStr = currentVersionObj['Body']._raw_stream.data + s3regex = re.search("(\d+)", s3currentVersionStr) + + s3cvInt = int(s3regex.groups()[0]) + + try: + localCurrentVersionStr = "" + with open(localFilename, 'r') as f: + localCurrentVersionStr = f.read() + localregex = re.search("(\d+)", localCurrentVersionStr) + localcvInt = int(localregex.groups()[0]) + except: + localcvInt = 0 + + + updateNeeded = not ( s3cvInt == localcvInt) + + if updateNeeded or force: + try: + targetFile = "{0}.zip".format(s3cvInt) + # if updateNeeded: + # print "Update needed to get {0}".format(targetFile) + # if force: + # print "Forcing update to get {0}".format(targetFile) + downloadCmd = client.download_file('henrypumpdata', targetFile, targetFile) + zfile = zipfile.ZipFile(targetFile) + zfile.extractall(outputFolder) + # for name in zfile.namelist(): + # (dirname,filename) = os.path.split(name) + # if not (dirname[:2] == "__"): + # print "Decompressing {0} on {1}.".format(filename,dirname) + # if not os.path.exists("{0}/{1}".format(outputFolder, dirname)): + # print "Creating {0}/{1}".format(outputFolder, dirname) + # os.makedirs("{0}/{1}".format(outputFolder, dirname)) + # zfile.extract(name, "{0}/{1}".format(outputFolder, dirname)) + with open(localFilename, 'w+') as f2: + f2.write(str(targetFile.replace(".zip",""))) + return {"status":"success", "message":"Files updated!"} + except: + return {"status":"error", "message":"error unzipping files"} + else: + return {"status":"success", "message":"All files are up to date!"} + +if __name__ == '__main__': + if len(sys.argv) > 1: + print checkUpdateNeeded(True) + else: + print checkUpdateNeeded() diff --git a/config b/config new file mode 100644 index 0000000..f1f04e2 --- /dev/null +++ b/config @@ -0,0 +1,3 @@ +[default] +aws_access_key_id = AKIAIJTEFVJEW2236CQQ +aws_secret_access_key = 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 diff --git a/default b/default new file mode 100644 index 0000000..ff08dd0 --- /dev/null +++ b/default @@ -0,0 +1,125 @@ +# You may add here your +# server { +# ... +# } +# statements for each of your virtual hosts to this file + +## +# You should look at the following URL's in order to grasp a solid understanding +# of Nginx configuration files in order to fully unleash the power of Nginx. +# http://wiki.nginx.org/Pitfalls +# http://wiki.nginx.org/QuickStart +# http://wiki.nginx.org/Configuration +# +# Generally, you will want to move this file somewhere, and start with a clean +# file but keep this around for reference. Or just disable in sites-enabled. +# +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. +## + +server { + listen 80 default_server; + #listen [::]:80 default_server ipv6only=on; + + root /usr/share/nginx/html; + index index.html index.htm; + + # Make site accessible from http://localhost/ + server_name localhost; + + location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico|navbar.html) { + root /home/poconsole/src/www/public; + access_log off; + expires max; + } + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + #try_files $uri $uri/ =404; + proxy_pass http://127.0.0.1:3000/; + # Uncomment to enable naxsi on this location + # include /etc/nginx/naxsi.rules + } + + location ~ \.(csv) { + root /mnt/usb/CSV; + autoindex on; + } + + + # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests + #location /RequestDenied { + # proxy_pass http://127.0.0.1:8080; + #} + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + #error_page 500 502 503 504 /50x.html; + #location = /50x.html { + # root /usr/share/nginx/html; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # fastcgi_split_path_info ^(.+\.php)(/.+)$; + # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini + # + # # With php5-cgi alone: + # fastcgi_pass 127.0.0.1:9000; + # # With php5-fpm: + # fastcgi_pass unix:/var/run/php5-fpm.sock; + # fastcgi_index index.php; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} + + +# another virtual host using mix of IP-, name-, and port-based configuration +# +#server { +# listen 8000; +# listen somename:8080; +# server_name somename alias another.alias; +# root html; +# index index.html index.htm; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} + + +# HTTPS server +# +#server { +# listen 443; +# server_name localhost; +# +# root html; +# index index.html index.htm; +# +# ssl on; +# ssl_certificate cert.pem; +# ssl_certificate_key cert.key; +# +# ssl_session_timeout 5m; +# +# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; +# ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES"; +# ssl_prefer_server_ciphers on; +# +# location / { +# try_files $uri $uri/ =404; +# } +#} diff --git a/dhcpd.conf b/dhcpd.conf new file mode 100644 index 0000000..8b5d5f4 --- /dev/null +++ b/dhcpd.conf @@ -0,0 +1,117 @@ +# +# Sample configuration file for ISC dhcpd for Debian +# +# + +# The ddns-updates-style parameter controls whether or not the server will +# attempt to do a DNS update when a lease is confirmed. We default to the +# behavior of the version 2 packages ('none', since DHCP v2 didn't +# have support for DDNS.) +ddns-update-style none; + +# option definitions common to all supported networks... +#option domain-name "example.org"; +#option domain-name-servers ns1.example.org, ns2.example.org; + +default-lease-time 600; +max-lease-time 7200; + +# If this DHCP server is the official DHCP server for the local +# network, the authoritative directive should be uncommented. +authoritative; + +# Use this to send dhcp log messages to a different log file (you also +# have to hack syslog.conf to complete the redirection). +log-facility local7; + +# No service will be given on this subnet, but declaring it helps the +# DHCP server to understand the network topology. + +#subnet 10.152.187.0 netmask 255.255.255.0 { +#} + +# This is a very basic subnet declaration. + +#subnet 10.254.239.0 netmask 255.255.255.224 { +# range 10.254.239.10 10.254.239.20; +# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; +#} + +# This declaration allows BOOTP clients to get dynamic addresses, +# which we don't really recommend. + +#subnet 10.254.239.32 netmask 255.255.255.224 { +# range dynamic-bootp 10.254.239.40 10.254.239.60; +# option broadcast-address 10.254.239.31; +# option routers rtr-239-32-1.example.org; +#} + +# A slightly different configuration for an internal subnet. +#subnet 10.5.5.0 netmask 255.255.255.224 { +# range 10.5.5.26 10.5.5.30; +# option domain-name-servers ns1.internal.example.org; +# option domain-name "internal.example.org"; +# option routers 10.5.5.1; +# option broadcast-address 10.5.5.31; +# default-lease-time 600; +# max-lease-time 7200; +#} + +# Hosts which require special configuration options can be listed in +# host statements. If no address is specified, the address will be +# allocated dynamically (if possible), but the host-specific information +# will still come from the host declaration. + +#host passacaglia { +# hardware ethernet 0:0:c0:5d:bd:95; +# filename "vmunix.passacaglia"; +# server-name "toccata.fugue.com"; +#} + +# Fixed IP addresses can also be specified for hosts. These addresses +# should not also be listed as being available for dynamic assignment. +# Hosts for which fixed IP addresses have been specified can boot using +# BOOTP or DHCP. Hosts for which no fixed address is specified can only +# be booted with DHCP, unless there is an address range on the subnet +# to which a BOOTP client is connected which has the dynamic-bootp flag +# set. +#host fantasia { +# hardware ethernet 08:00:07:26:c0:a5; +# fixed-address fantasia.fugue.com; +#} + +# You can declare a class of clients and then do address allocation +# based on that. The example below shows a case where all clients +# in a certain class get addresses on the 10.17.224/24 subnet, and all +# other clients get addresses on the 10.0.29/24 subnet. + +#class "foo" { +# match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; +#} + +#shared-network 224-29 { +# subnet 10.17.224.0 netmask 255.255.255.0 { +# option routers rtr-224.example.org; +# } +# subnet 10.0.29.0 netmask 255.255.255.0 { +# option routers rtr-29.example.org; +# } +# pool { +# allow members of "foo"; +# range 10.17.224.10 10.17.224.250; +# } +# pool { +# deny members of "foo"; +# range 10.0.29.10 10.0.29.230; +# } +#} + +subnet 192.168.4.0 netmask 255.255.255.0 { + range 192.168.4.10 192.168.4.50; + option broadcast-address 192.168.4.255; + option routers 192.168.4.1; + default-lease-time 600; + max-lease-time 7200; + option domain-name "local"; + option domain-name-servers 8.8.8.8, 8.8.4.4; +} diff --git a/henryPumpDev.pub b/henryPumpDev.pub new file mode 100644 index 0000000..a23fecb --- /dev/null +++ b/henryPumpDev.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyVaBSF9W5mZWnJp2ZjEdBoBH3NRvQwowuOoeWB/jEhCd/LWvmWkhZRB8jKzpc0vnNPOIGcVoMEYNir9QT4HbElCH3B5Wg9kqI4+MWfMgQorGjVGD3ukvsGqyj1LKrSLR91Nxy49yvwgMEJMFBT0NqnfsHKbfe88TZYb30/1+lE9MqTlUuF3KBTpv2Mr+Zbyd6nWnqDN9cq7MScaxQnlvZTaln38/eMIVeyTQ2BOjKYDPe0Y2lBzxnFQKxG+t6zwk/Fdli8U+AG791VephqPD34CuKbfnsX7kMHSJEhlAk7JkNz9BE9lyR4cp41qHF8gNqehdl4HWU0DZ6DKuxlGpL Henry Pump Developer Key diff --git a/hostapd b/hostapd new file mode 100644 index 0000000..5783c15 --- /dev/null +++ b/hostapd @@ -0,0 +1,20 @@ +# Defaults for hostapd initscript +# +# See /usr/share/doc/hostapd/README.Debian for information about alternative +# methods of managing hostapd. +# +# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration +# file and hostapd will be started during system boot. An example configuration +# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz +# +DAEMON_CONF="/etc/hostapd/hostapd.conf" + +# Additional daemon options to be appended to hostapd command:- +# -d show more debug messages (-dd for even more) +# -K include key data in debug messages +# -t include timestamps in some debug messages +# +# Note that -B (daemon mode) and -P (pidfile) options are automatically +# configured by the init.d script and must not be added to DAEMON_OPTS. +# +#DAEMON_OPTS="" diff --git a/hostapd.conf b/hostapd.conf new file mode 100644 index 0000000..17c43a9 --- /dev/null +++ b/hostapd.conf @@ -0,0 +1,13 @@ +interface=wlan0 +driver=nl80211 +ssid=HenryPOC +hw_mode=g +channel=6 +macaddr_acl=0 +auth_algs=1 +ignore_broadcast_ssid=0 +wpa=2 +wpa_passphrase=henrypump +wpa_key_mgmt=WPA-PSK +wpa_pairwise=TKIP +rsn_pairwise=CCMP diff --git a/hostname b/hostname new file mode 100644 index 0000000..091916f --- /dev/null +++ b/hostname @@ -0,0 +1 @@ +poconsole diff --git a/initialSetup.sh b/initialSetup.sh new file mode 100644 index 0000000..93410fc --- /dev/null +++ b/initialSetup.sh @@ -0,0 +1,8 @@ +echo "default password: raspberry" +ssh pi@raspberrypi "sudo adduser poconsole" +ssh pi@raspberrypi "sudo sed -i '$a poconsole ALL=(ALL) NOPASSWD: ALL' /etc/sudoers" + +OR + +sudo adduser poconsole +sudo sed -i '$a poconsole ALL=(ALL) NOPASSWD: ALL' /etc/sudoers \ No newline at end of file diff --git a/interfaces b/interfaces new file mode 100644 index 0000000..f6188fd --- /dev/null +++ b/interfaces @@ -0,0 +1,20 @@ +auto lo +iface lo inet loopback + +#iface eth0 inet dhcp +iface eth0 inet static +address 192.168.1.30 +netmask 255.255.255.0 +gateway 192.168.1.150 + +auto wlan0 +#Normal Wifi Mode +#allow-hotplug wlan0 +#iface wlan0 inet manual +#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf + +#ACCESS POINT MODE +iface wlan0 inet static +address 192.168.4.1 +netmask 255.255.255.0 +up iptables-restore < /etc/iptables.ipv4.nat diff --git a/isc-dhcp-server b/isc-dhcp-server new file mode 100644 index 0000000..ec7fb5a --- /dev/null +++ b/isc-dhcp-server @@ -0,0 +1,21 @@ +# Defaults for isc-dhcp-server initscript +# sourced by /etc/init.d/isc-dhcp-server +# installed at /etc/default/isc-dhcp-server by the maintainer scripts + +# +# This is a POSIX shell fragment +# + +# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf). +#DHCPD_CONF=/etc/dhcp/dhcpd.conf + +# Path to dhcpd's PID file (default: /var/run/dhcpd.pid). +#DHCPD_PID=/var/run/dhcpd.pid + +# Additional options to start dhcpd with. +# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead +#OPTIONS="" + +# On what interfaces should the DHCP server (dhcpd) serve DHCP requests? +# Separate multiple interfaces with spaces, e.g. "eth0 eth1". +INTERFACES="wlan0" diff --git a/loggers b/loggers new file mode 100644 index 0000000..2341e96 --- /dev/null +++ b/loggers @@ -0,0 +1,43 @@ +#! /bin/sh +# /etc/init.d/loggers + +### BEGIN INIT INFO +# Provides: loggers +# Required-Start: $remote_fs $syslog usbMount +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Simple script to start a program at boot +# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown. +### END INIT INFO + +# If you want a command to always run, put it here + +# Carry out specific functions when asked to by the system +case "$1" in + start) + echo "Starting loggers" + kill -9 $(cat /root/alarmLogger.pid) + kill -9 $(cat /root/dataLogger.pid) + # run application you want to start + #python /home/poconsole/src/dataLogger/alarmLogger.py & + #python /home/poconsole/src/dataLogger/dataLogger.py & + /usr/bin/python /home/poconsole/src/dataLogger/alarmLogger.py > /dev/null 2>&1 & echo $! > "/root/alarmLogger.pid" + /usr/bin/python /home/poconsole/src/dataLogger/dataLogger.py > /dev/null 2>&1 & echo $! > "/root/dataLogger.pid" + + ;; + stop) + echo "Stopping loggers" + # kill application you want to stop + #killall python + kill -9 $(cat /root/alarmLogger.pid) + kill -9 $(cat /root/dataLogger.pid) + +;; + *) + echo "Usage: /etc/init.d/loggers {start|stop}" + exit 1 + ;; +esac + +exit 0 diff --git a/my.cnf b/my.cnf new file mode 100644 index 0000000..9d7f336 --- /dev/null +++ b/my.cnf @@ -0,0 +1,124 @@ +# The MySQL database server configuration file. +# +# You can copy this to one of: +# - "/etc/mysql/my.cnf" to set global options, +# - "~/.my.cnf" to set user-specific options. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# This will be passed to all mysql clients +# It has been reported that passwords should be enclosed with ticks/quotes +# escpecially if they contain "#" chars... +# Remember to edit /etc/mysql/debian.cnf when changing the socket location. +[client] +port = 3306 +socket = /var/run/mysqld/mysqld.sock + +# Here is entries for some specific programs +# The following values assume you have at least 32M ram + +# This was formally known as [safe_mysqld]. Both versions are currently parsed. +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 + +[mysqld] +# +# * Basic Settings +# +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +lc-messages-dir = /usr/share/mysql +skip-external-locking +# +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +bind-address = 127.0.0.1 +# +# * Fine Tuning +# +key_buffer = 16M +max_allowed_packet = 16M +thread_stack = 192K +thread_cache_size = 8 +# This replaces the startup script and checks MyISAM tables if needed +# the first time they are touched +myisam-recover = BACKUP +#max_connections = 100 +#table_cache = 64 +#thread_concurrency = 10 +# +# * Query Cache Configuration +# +query_cache_limit = 1M +query_cache_size = 16M +# +# * Logging and Replication +# +# Both location gets rotated by the cronjob. +# Be aware that this log type is a performance killer. +# As of 5.1 you can enable the log at runtime! +#general_log_file = /var/log/mysql/mysql.log +#general_log = 1 +# +# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. +# +# Here you can see queries with especially long duration +#log_slow_queries = /var/log/mysql/mysql-slow.log +#long_query_time = 2 +#log-queries-not-using-indexes +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +#server-id = 1 +#log_bin = /var/log/mysql/mysql-bin.log +expire_logs_days = 10 +max_binlog_size = 100M +#binlog_do_db = include_database_name +#binlog_ignore_db = include_database_name +# +# * InnoDB +# +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! +# +# * Security Features +# +# Read the manual, too, if you want chroot! +# chroot = /var/lib/mysql/ +# +# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". +# +# ssl-ca=/etc/mysql/cacert.pem +# ssl-cert=/etc/mysql/server-cert.pem +# ssl-key=/etc/mysql/server-key.pem + + + +[mysqldump] +quick +quote-names +max_allowed_packet = 16M + +[mysql] +#no-auto-rehash # faster start of mysql but no tab completition + +[isamchk] +key_buffer = 16M + +# +# * IMPORTANT: Additional settings that can override those from this file! +# The files must end with '.cnf', otherwise they'll be ignored. +# +!includedir /etc/mysql/conf.d/ diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..4aecea7 --- /dev/null +++ b/setup.sh @@ -0,0 +1,137 @@ +#!/bin/bash +echo "POConsole Auto Configuration Script" +echo "-----------------------------------" +echo "Written by: Patrick McDonagh" +echo "Sit back and relax... I'll take over from here" + +echo "Setting up SSH Key" +mkdir ~/.ssh +cat henryPumpDev.pub >> ~/.ssh/authorized_keys + +echo "Changing hostname to poconsole" +sudo mv hostname /etc/hostname + +echo "Setting up networking" +sudo mv interfaces /etc/network/interfaces +sudo apt-get update +sudo apt-get -y upgrade +sudo apt-get -y install unzip cmake mysql-client python-dev htop nginx libmysqlclient-dev avahi-daemon screen mysql-server g++ gcc curl + +echo "Setting up USB Drive" +sudo mkdir /mnt/usb +sudo mkdir /mnt/usb/CSV +echo "Formatting to EXT4" +sudo mkfs.ext4 /dev/sda1 -L usbdrive +echo "Adding entry for USB in /etc/fstab" +sudo sh -c "echo '/dev/sda1 /mnt/usb ext4 defaults 0 0'>>/etc/fstab" +echo "Mounting all drives" +sudo mount -a +echo "Configuring MySQL to use the USB drive" +cd /mnt/usb +sudo mkdir mysql +sudo su +cp -Rv /var/lib/mysql/* /mnt/usb/mysql/ +chown -R mysql:mysql /mnt/usb/mysql +exit +cd ~/setup +sudo service mysql stop +sudo sed 's:/var/lib/mysql:/mnt/usb/mysql:g' /etc/mysql/my.cnf +sudo service mysql restart +sudo chmod 777 /mnt/usb +sudo chmod 777 /mnt/usb/* + + +echo "installing TuxEip" +wget https://github.com/leicht/TuxPLC/archive/master.zip +unzip master.zip +cd TuxPLC-master/tuxeip +cmake CMakeLists.txt +make + +cd lib +ar -x libtuxeip.a +gcc -shared *.o -o libtuxeip.so +sudo cp libtuxeip.so /usr/lib/ + +cd ~/setup +#sudo wget -O /etc/apt/sources.list.d/repository.pi3g.com.list http://repository.pi3g.com/sources.list +#wget -O - http://repository.pi3g.com/pubkey | sudo apt-key add - + +echo "Configuring MySQL" +# sudo mv my.cnf /etc/mysql/my.cnf +# sudo service mysql restart +mysql --user="root" --password="henrypump" --execute="source WellDataEmpty.sql" +mysql --user="root" --password="henrypump" --execute="source setupUsers.sql" + +echo "Configuring nginx" +sudo mv default /etc/nginx/sites-enabled/default + +echo "installing node" +wget http://node-arm.herokuapp.com/node_latest_armhf.deb +sudo dpkg -i node_latest_armhf.deb + + +# INSTALLING NODE ON UBUNTU +# curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - +# sudo apt-get install -y nodejs + +sudo npm install -g forever + +echo "Configuring Auto-start scripts" +sudo chmod 777 loggers +sudo chmod 777 website +# sudo chmod 777 usbMount +sudo mv loggers /etc/init.d/ +sudo mv website /etc/init.d/ +# sudo mv usbMount /etc/init.d/ +# sudo update-rc.d usbMount defaults +sudo update-rc.d loggers defaults +sudo update-rc.d website defaults + +echo "Installing pip - Python Package Manager" +wget https://bootstrap.pypa.io/get-pip.py +sudo python get-pip.py +sudo pip install mysql requests boto3 pycomm + +echo "Setting up POConsole software" +mkdir ~/src +mkdir ~/.aws +cp config ~/.aws/ +cp checkCurrentVersion.py ~/src/ +python ~/src/checkCurrentVersion.py True +cd ~/src/www +npm install +cd ~/setup + +echo "Setting up Wifi Access Point and DHCP Server" +sudo apt-get install -y hostapd isc-dhcp-server +sudo cp dhcpd.conf /etc/dhcp/ +sudo cp isc-dhcp-server /etc/default/ +sudo cp hostapd.conf /etc/hostapd/ +sudo cp hostapd /etc/default/ +sudo sed -i '$a net.ipv4.ip_forward=1' /etc/sysctl.conf +sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" +sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE +sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT +sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT +sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" +sudo ifdown wlan0 +sudo ifup wlan0 +sudo service hostapd start +sudo service isc-dhcp-server start + +echo "Setup Complete!" + +cd ~ +mv setup .setup +sudo userdel pi + +read -n1 -r -p "Press any key to reboot..." key + +if [ "$key" = ' ' ]; then + # Space pressed, do something + sudo reboot +else + # Anything else pressed, do whatever else. + sudo reboot +fi diff --git a/setupUsers.sql b/setupUsers.sql new file mode 100644 index 0000000..ad972bd --- /dev/null +++ b/setupUsers.sql @@ -0,0 +1,7 @@ +CREATE USER 'website'@'localhost' IDENTIFIED BY 'henrypump'; +GRANT ALL ON *.* TO 'website'@'localhost'; +CREATE USER 'admin'@'localhost' IDENTIFIED BY 'henrypump'; +GRANT ALL ON *.* to 'admin'@'localhost'; +CREATE USER 'admin'@'%' IDENTIFIED BY 'henrypump'; +GRANT ALL ON *.* to 'admin'@'%'; +FLUSH PRIVILEGES; diff --git a/usbMount b/usbMount new file mode 100644 index 0000000..b6e2691 --- /dev/null +++ b/usbMount @@ -0,0 +1,34 @@ +#! /bin/sh +# /etc/init.d/usbMount + +### BEGIN INIT INFO +# Provides: usbMount +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Simple script to start a program at boot +# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown. +### END INIT INFO + +# If you want a command to always run, put it here + +# Carry out specific functions when asked to by the system +case "$1" in + start) + echo "mounting USB /dev/sda1 to /usb/mnt" + # run application you want to start + sudo mount -o uid=poconsole,gid=poconsole /dev/sda1 /mnt/usb + ;; + stop) + echo "unmounting /usb/mnt" + # kill application you want to stop + sudo umount /mnt/usb + ;; + *) + echo "Usage: /etc/init.d/usbMount {start|stop}" + exit 1 + ;; +esac + +exit 0 diff --git a/website b/website new file mode 100644 index 0000000..fa29ec5 --- /dev/null +++ b/website @@ -0,0 +1,41 @@ +#! /bin/sh +# /etc/init.d/website + +### BEGIN INIT INFO +# Provides: website +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Simple script to start a program at boot +# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown. +### END INIT INFO + +# If you want a command to always run, put it here + +# Carry out specific functions when asked to by the system +case "$1" in + start) + echo "Starting website" + # run application you want to start + # /home/pi/runWebsite.sh + if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ] + then + export NODE_ENV=production + export PATH=/usr/local/bin:$PATH + forever start /home/poconsole/src/www/app.js > /dev/null + fi +;; + stop) + echo "Stopping website" + # kill application you want to stop + forever stopall + ;; + *) + echo "Usage: /etc/init.d/website {start|stop}" + exit 1 + ;; +esac + +exit 0 +