#!/bin/bash
#
# start mods server
#
# Neil Gershenfeld 
# (c) Massachusetts Institute of Technology 2016
#
# This work may be reproduced, modified, distributed, performed, and 
# displayed for any purpose, but must acknowledge the fab modules 
# project. Copyright is retained and must be preserved. The work is 
# provided as is; no warranty is provided, and users accept all 
# liability.
#
# find path, following symlinks
#    from http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/
#
#get_script_dir () {
#   SOURCE="${BASH_SOURCE[0]}"
#   while [ -h "$SOURCE" ]; do
#      DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#      SOURCE="$( readlink "$SOURCE" )"
#      [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
#   done
#   DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
#   echo "$DIR"
#   }
#path=$(get_script_dir)
#
# hard-code script path
#
path="/usr/local/bin/mods/scripts"
#
# cd to script
#
cd $path
cd ..
#
# uncomment to start local http server (ignores error if already running)
#
#http-server -p 8080 &
#
# uncomment to start node print server (ignores error if already running)
# for printer permission:
#    sudo adduser user_name lp
#    sudo adduser user_name lpadmin
#
cd js
node printserver.js 127.0.0.1 1234 &
zenity --info --text 'mods printserver started'
#
# uncomment to start node serial server (ignores error if already running)
# for serial permission:
#    sudo adduser user_name dialout
#
#cd js
#node serialserver.js 127.0.0.1 1234 &
#zenity --info --text 'mods serialserver started'