Remove not dev related scripts (#4690)

pull/4694/head
Paulus Schoutsen 2016-12-03 09:59:20 -08:00 committed by GitHub
parent 898ba56d9f
commit f63a79ee8f
4 changed files with 0 additions and 341 deletions

View File

@ -1,98 +0,0 @@
#! /usr/bin/python
"""
Query the Home Assistant API for available entities.
Output is printed to stdout.
"""
import sys
import getpass
import argparse
try:
from urllib2 import urlopen
PYTHON = 2
except ImportError:
from urllib.request import urlopen
PYTHON = 3
import json
def main(password, askpass, attrs, address, port):
"""Fetch Home Assistant API JSON page and post process."""
# Ask for password
if askpass:
password = getpass.getpass('Home Assistant API Password: ')
# Fetch API result
url = mk_url(address, port, password)
response = urlopen(url).read()
if PYTHON == 3:
response = response.decode('utf-8')
data = json.loads(response)
# Parse data
output = {'entity_id': []}
output.update([(attr, []) for attr in attrs])
for item in data:
output['entity_id'].append(item['entity_id'])
for attr in attrs:
output[attr].append(item['attributes'].get(attr, ''))
# Output data
print_table(output, ['entity_id'] + attrs)
def print_table(data, columns):
"""Format and print a table of data from a dictionary."""
# Get column lengths
lengths = {}
for key, value in data.items():
lengths[key] = max([len(str(val)) for val in value] + [len(key)])
# Print header
for item in columns:
itemup = item.upper()
sys.stdout.write(itemup + ' ' * (lengths[item] - len(item) + 4))
sys.stdout.write('\n')
# print body
for ind in range(len(data[columns[0]])):
for item in columns:
val = str(data[item][ind])
sys.stdout.write(val + ' ' * (lengths[item] - len(val) + 4))
sys.stdout.write("\n")
def mk_url(address, port, password):
"""Construct the URL call for the API states page."""
url = ''
if address.startswith('http://'):
url += address
else:
url += 'http://' + address
url += ':' + port + '/api/states?'
if password is not None:
url += 'api_password=' + password
return url
if __name__ == "__main__":
all_options = {'password': None, 'askpass': False, 'attrs': [],
'address': 'localhost', 'port': '8123'}
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('attrs', metavar='ATTRIBUTE', type=str, nargs='*',
help='an attribute to read from the state')
parser.add_argument('--password', dest='password', default=None,
type=str, help='API password for the HA server')
parser.add_argument('--ask-password', dest='askpass', default=False,
action='store_const', const=True,
help='prompt for HA API password')
parser.add_argument('--addr', dest='address',
default='localhost', type=str,
help='address of the HA server')
parser.add_argument('--port', dest='port', default='8123',
type=str, help='port that HA is hosting on')
args = parser.parse_args()
main(args.password, args.askpass, args.attrs, args.address, args.port)

View File

@ -1,103 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: hass
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Home\ Assistant
### END INIT INFO
# /etc/init.d Service Script for Home Assistant
# Created with: https://gist.github.com/naholyr/4275302#file-new-service-sh
#
# Installation:
# 1) If any commands need to run before executing hass (like loading a
# virutal environment), put them in PRE_EXEC. This command must end with
# a semicolon.
# 2) Set RUN_AS to the username that should be used to execute hass.
# 3) Copy this script to /etc/init.d/
# sudo cp hass-daemon /etc/init.d/hass-daemon
# sudo chmod +x /etc/init.d/hass-daemon
# 4) Register the daemon with Linux
# sudo update-rc.d hass-daemon defaults
# 5) Install this service
# sudo service hass-daemon install
# 6) Restart Machine
#
# After installation, HA should start automatically. If HA does not start,
# check the log file output for errors.
# /var/opt/homeassistant/home-assistant.log
PRE_EXEC=""
RUN_AS="USER"
PID_FILE="/var/run/hass.pid"
CONFIG_DIR="/var/opt/homeassistant"
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --daemon"
REDIRECT="> $CONFIG_DIR/home-assistant.log 2>&1"
start() {
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
local CMD="$PRE_EXEC hass $FLAGS $REDIRECT;"
su -c "$CMD" $RUN_AS
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
kill $(cat "$PID_FILE")
while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;
echo 'Service stopped' >&2
}
install() {
echo "Installing Home Assistant Daemon (hass-daemon)"
echo "999999" > $PID_FILE
chown $RUN_AS $PID_FILE
mkdir -p $CONFIG_DIR
chown $RUN_AS $CONFIG_DIR
}
uninstall() {
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
rm -fv "$PID_FILE"
echo "Notice: The config directory has not been removed"
echo $CONFIG_DIR
update-rc.d -f hass-daemon remove
rm -fv "$0"
echo "Home Assistant Daemon has been removed. Home Assistant is still installed."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
install)
install
;;
uninstall)
uninstall
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|install|uninstall}"
esac

View File

@ -1,20 +0,0 @@
# This is a simple service file for systems with systemd to tun HA as user.
#
# For details please check https://home-assistant.io/getting-started/autostart/
#
[Unit]
Description=Home Assistant for %i
After=network.target
[Service]
Type=simple
User=%i
# Enable the following line if you get network-related HA errors during boot
#ExecStartPre=/usr/bin/sleep 60
# Use `whereis hass` to determine the path of hass
ExecStart=/usr/bin/hass --runner
SendSIGKILL=no
RestartForceExitStatus=100
[Install]
WantedBy=multi-user.target

View File

@ -1,120 +0,0 @@
##
#
# Home Assistant - nginx Configuration File
#
# Using nginx as a proxy for Home Assistant allows you to serve Home Assisatnt
# securely over standard ports. This configuration file and instructions will
# walk you through setting up Home Assistant over a secure connection.
#
# 1) Get a domain name forwarded to your IP.
# Chances are, you have a dynamic IP Address (your ISP changes your address
# periodically). If this is true, you can use a Dynamic DNS service to obtain
# a domain and set it up to update with you IP. If you purchase your own
# domain name, you will be able to easily get a trusted SSL certificate
# later.
#
#
# 2) Install nginx on your server.
# This will vary depending on your OS. Check out Google for this. After
# installing, ensure that nginx is not running.
#
#
# 3) Obtain an SSL certificate.
#
# 3a) Using Let's Encrypt
# If you purchased your own domain, you can use https://letsencrypt.org/ to
# obtain a free, publicly trusted SSL certificate. This will allow you to
# work with services like IFTTT. Download and install per the instructions
# online and get a certificate using the following command.
#
# ./letsencrypt-auto certonly --standalone -d example.com -d www.example.com
#
# Instead of example.com, use your domain. You will need to renew this
# certificate every 90 days.
#
# 3b) Using openssl
# If you do not own your own domain, you may generate a self-signed
# certificate. This will not work with IFTTT, but it will encrypt all of your
# Home Assistant traffic.
#
# openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 9999
# sudo cp key.pem cert.pem /etc/nginx/ssl
# sudo chmod 600 /etc/nginx/ssl/key.pem /etc/nginx/ssl/cert.pem
# sudo chown root:root /etc/nginx/ssl/key.pem /etc/nginx/ssl/cert.pem
#
#
# 4) Create dhparams file
# As a fair warning, this file will take a while to generate.
#
# cd /etc/nginx/ssl
# sudo openssl dhparam -out dhparams.pem 2048
#
#
# 5) Install this configuration file in nginx.
#
# cp nginx-hass /etc/nginx/sites-available/hass
# cd /etc/nginx/sites-enabled
# sudo unlink default
# sudo ln ../sites-available/hass default
#
#
# 6) Double check this configuration to ensure all settings are correct and
# start nginx.
#
#
# 7) Forward ports 443 and 80 to your server on your router. Do not forward
# port 8123.
#
##
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
# Update this line to be your domain
server_name example.com;
# These shouldn't need to be changed
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}
server {
# Update this line to be your domain
server_name example.com;
# Ensure these lines point to your SSL certificate and key
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# Use these lines instead if you created a self-signed certificate
# ssl_certificate /etc/nginx/ssl/cert.pem;
# ssl_certificate_key /etc/nginx/ssl/key.pem;
# Ensure this line points to your dhparams file
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
# These shouldn't need to be changed
listen 443 default_server;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
proxy_buffering off;
location / {
proxy_pass http://localhost:8123;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}