From d3b69ddf351a8739a5be180fc52e9063025526be Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 19:20:55 -0400 Subject: [PATCH 01/14] Added Dockerfiles for amd64 and armhf --- docker/Dockerfile.amd64 | 29 +++++++++++++++++++++++++++++ docker/Dockerfile.armhf | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 docker/Dockerfile.amd64 create mode 100644 docker/Dockerfile.armhf diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 new file mode 100644 index 0000000..a6fd59a --- /dev/null +++ b/docker/Dockerfile.amd64 @@ -0,0 +1,29 @@ +FROM amd64/ubuntu + +# Install and update packages +RUN apt-get update && apt-get install -y \ + bluez \ + git \ + wget \ + apt-transport-https + +# Install Mosquitto and friends +RUN apt-get update +RUN apt-get install -y \ + libwebsockets-dev \ + libmosquitto-dev \ + mosquitto \ + mosquitto-clients + +# Clone repo into working directory +RUN git clone https://github.com/andrewjfreyer/presence.git /presence + +# Change script permissions +WORKDIR /presence +RUN chmod +x presence.sh + +# Copy configuration files +COPY behavior_preferences mqtt_preferences owner_devices ./ + +ENTRYPOINT ["/bin/bash"] +CMD ["/presence/presence.sh"] diff --git a/docker/Dockerfile.armhf b/docker/Dockerfile.armhf new file mode 100644 index 0000000..6ae7531 --- /dev/null +++ b/docker/Dockerfile.armhf @@ -0,0 +1,29 @@ +FROM resin/raspberry-pi-debian + +# Install and update packages +RUN apt-get update && apt-get install -y \ + bluez \ + git \ + wget \ + apt-transport-https + +# Install Mosquitto and friends +RUN apt-get update +RUN apt-get install -y \ + libwebsockets-dev \ + libmosquitto-dev \ + mosquitto \ + mosquitto-clients + +# Clone repo into working directory +RUN git clone https://github.com/andrewjfreyer/presence.git /presence + +# Change script permissions +WORKDIR /presence +RUN chmod +x presence.sh + +# Copy configuration files +COPY behavior_preferences mqtt_preferences owner_devices ./ + +ENTRYPOINT ["/bin/bash"] +CMD ["/presence/presence.sh"] From acd3f6a8e2d270f9a04c6bcaffe50790e828fc2f Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 20:14:37 -0400 Subject: [PATCH 02/14] Updated Dockerfile.amd64 for deployment using Git context --- docker/Dockerfile.amd64 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index a6fd59a..04940d1 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -8,7 +8,6 @@ RUN apt-get update && apt-get install -y \ apt-transport-https # Install Mosquitto and friends -RUN apt-get update RUN apt-get install -y \ libwebsockets-dev \ libmosquitto-dev \ @@ -16,14 +15,14 @@ RUN apt-get install -y \ mosquitto-clients # Clone repo into working directory -RUN git clone https://github.com/andrewjfreyer/presence.git /presence +#RUN git clone https://github.com/andrewjfreyer/presence.git /presence # Change script permissions -WORKDIR /presence +#WORKDIR /presence RUN chmod +x presence.sh # Copy configuration files -COPY behavior_preferences mqtt_preferences owner_devices ./ +#COPY behavior_preferences mqtt_preferences owner_devices ./ ENTRYPOINT ["/bin/bash"] -CMD ["/presence/presence.sh"] +CMD ["presence.sh"] From 3bddeeba6029354f6771c1e211b78612ec27a55a Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 20:19:06 -0400 Subject: [PATCH 03/14] Added copy and working directory --- docker/Dockerfile.amd64 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 04940d1..cd3286c 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -18,7 +18,10 @@ RUN apt-get install -y \ #RUN git clone https://github.com/andrewjfreyer/presence.git /presence # Change script permissions -#WORKDIR /presence +RUN mkdir /presence +WORKDIR /presence +COPY . . + RUN chmod +x presence.sh # Copy configuration files From 73eb15242661430cef38de213f8b2c72aa95c317 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 20:40:35 -0400 Subject: [PATCH 04/14] Reversions --- docker/Dockerfile.amd64 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index cd3286c..37e8c8d 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -27,5 +27,4 @@ RUN chmod +x presence.sh # Copy configuration files #COPY behavior_preferences mqtt_preferences owner_devices ./ -ENTRYPOINT ["/bin/bash"] -CMD ["presence.sh"] +CMD ["presence/presence.sh"] From 0045269c19ba4d7ca59957feac8872a3785b9a4e Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:02:39 -0400 Subject: [PATCH 05/14] Moved PROCESS OPTIONS and HELP TEXT sections before LOAD PREFERENCES --- presence.sh | 190 ++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/presence.sh b/presence.sh index 82bf95d..efaa16a 100755 --- a/presence.sh +++ b/presence.sh @@ -18,7 +18,7 @@ #VERSION NUMBER VERSION=0.5.1 -#COLOR OUTPUT FOR RICH DEBUG +#COLOR OUTPUT FOR RICH DEBUG ORANGE='\033[0;33m' RED='\033[0;31m' NC='\033[0m' @@ -32,66 +32,10 @@ base_directory=$(dirname "$(readlink -f "$0")") mosquitto_pub_path=$(which mosquitto_pub) mosquitto_sub_path=$(which mosquitto_sub) -#ERROR CHECKING FOR MOSQUITTO PUBLICATION +#ERROR CHECKING FOR MOSQUITTO PUBLICATION [ -z "$mosquitto_pub_path" ] && echo "Required package 'mosquitto_pub' not found. Please install." && exit 1 [ -z "$mosquitto_sub_path" ] && echo "Required package 'mosquitto_sub' not found. Please install." && exit 1 -# ---------------------------------------------------------------------------------------- -# LOAD PREFERENCES -# ---------------------------------------------------------------------------------------- - -#OR LOAD FROM A SOURCE FILE -if [ ! -f "$base_directory/behavior_preferences" ]; then - echo -e "${GREEN}presence $VERSION ${RED}WARNING: ${NC}Behavior preferences are not defined:${NC}" - echo -e "/behavior_preferences. Creating file and setting default values.${NC}" - echo -e "" - - #DEFAULT VALUES - echo " -#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN AWAY FROM HOME -delay_between_owner_scans_away=6 - -#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN HOME -delay_between_owner_scans_present=30 - -#HOW MANY VERIFICATIONS ARE REQUIRED TO DETERMINE A DEVICE IS AWAY -verification_of_away_loop_size=6 - -#HOW LONG TO DELAY BETWEEN VERIFICATIONS THAT A DEVICE IS AWAY -verification_of_away_loop_delay=3 - -#PREFERRED HCI DEVICE -hci_device='hci0'" > "$base_directory/behavior_preferences" -fi - -# ---------------------------------------------------------------------------------------- -# VARIABLE DEFINITIONS -# ---------------------------------------------------------------------------------------- - -#SET PREFERENCES FROM FILE -DELAY_CONFIG="$base_directory/behavior_preferences" ; [ -f $DELAY_CONFIG ] && source $DELAY_CONFIG - -#LOAD DEFAULT VALUES IF NOT PRESENT -[ -z "$hci_device" ] && hci_device='hci0' -[ -z "$name_scan_timeout" ] && name_scan_timeout=5 -[ -z "$delay_between_owner_scans_away" ] && delay_between_owner_scans_away=6 -[ -z "$delay_between_owner_scans_present" ] && delay_between_owner_scans_present=30 -[ -z "$verification_of_away_loop_size" ] && verification_of_away_loop_size=6 -[ -z "$verification_of_away_loop_delay" ] && verification_of_away_loop_delay=3 - -#LOAD PREFERENCES IF PRESENT -MQTT_CONFIG=$base_directory/mqtt_preferences ; [ -f $MQTT_CONFIG ] && source $MQTT_CONFIG -[ ! -f "$MQTT_CONFIG" ] && echo "warning: please configure mqtt preferences file. exiting." && echo "" > "$MQTT_CONFIG" && exit 1 - -#FILL ADDRESS ARRAY WITH SUPPORT FOR COMMENTS -[ ! -f "$base_directory/owner_devices" ] && "" > "$base_directory/owner_devices" -macaddress_owners=($(cat "$base_directory/owner_devices" | grep -oiE "([0-9a-f]{2}:){5}[0-9a-f]{2}" )) -[ -z "$macaddress_owners" ] && echo "warning: no owner devices are specified. exiting." && exit 1 - - -#NUMBER OF CLIENTS THAT ARE MONITORED -number_of_owners=$((${#macaddress_owners[@]})) - # ---------------------------------------------------------------------------------------- # HELP TEXT # ---------------------------------------------------------------------------------------- @@ -122,7 +66,7 @@ while getopts "h?Vdbct:" opt; do show_help_text exit 0 ;; - V) + V) echo "$VERSION" exit 0 ;; @@ -142,25 +86,81 @@ shift $((OPTIND-1)) #SHIFT IF NECESSARY [ "$1" = "--" ] && shift +# ---------------------------------------------------------------------------------------- +# LOAD PREFERENCES +# ---------------------------------------------------------------------------------------- + +#OR LOAD FROM A SOURCE FILE +if [ ! -f "$base_directory/behavior_preferences" ]; then + echo -e "${GREEN}presence $VERSION ${RED}WARNING: ${NC}Behavior preferences are not defined:${NC}" + echo -e "/behavior_preferences. Creating file and setting default values.${NC}" + echo -e "" + + #DEFAULT VALUES + echo " +#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN AWAY FROM HOME +delay_between_owner_scans_away=6 + +#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN HOME +delay_between_owner_scans_present=30 + +#HOW MANY VERIFICATIONS ARE REQUIRED TO DETERMINE A DEVICE IS AWAY +verification_of_away_loop_size=6 + +#HOW LONG TO DELAY BETWEEN VERIFICATIONS THAT A DEVICE IS AWAY +verification_of_away_loop_delay=3 + +#PREFERRED HCI DEVICE +hci_device='hci0'" > "$base_directory/behavior_preferences" +fi + +# ---------------------------------------------------------------------------------------- +# VARIABLE DEFINITIONS +# ---------------------------------------------------------------------------------------- + +#SET PREFERENCES FROM FILE +DELAY_CONFIG="$base_directory/behavior_preferences" ; [ -f $DELAY_CONFIG ] && source $DELAY_CONFIG + +#LOAD DEFAULT VALUES IF NOT PRESENT +[ -z "$hci_device" ] && hci_device='hci0' +[ -z "$name_scan_timeout" ] && name_scan_timeout=5 +[ -z "$delay_between_owner_scans_away" ] && delay_between_owner_scans_away=6 +[ -z "$delay_between_owner_scans_present" ] && delay_between_owner_scans_present=30 +[ -z "$verification_of_away_loop_size" ] && verification_of_away_loop_size=6 +[ -z "$verification_of_away_loop_delay" ] && verification_of_away_loop_delay=3 + +#LOAD PREFERENCES IF PRESENT +MQTT_CONFIG=$base_directory/mqtt_preferences ; [ -f $MQTT_CONFIG ] && source $MQTT_CONFIG +[ ! -f "$MQTT_CONFIG" ] && echo "warning: please configure mqtt preferences file. exiting." && echo "" > "$MQTT_CONFIG" && exit 1 + +#FILL ADDRESS ARRAY WITH SUPPORT FOR COMMENTS +[ ! -f "$base_directory/owner_devices" ] && "" > "$base_directory/owner_devices" +macaddress_owners=($(cat "$base_directory/owner_devices" | grep -oiE "([0-9a-f]{2}:){5}[0-9a-f]{2}" )) +[ -z "$macaddress_owners" ] && echo "warning: no owner devices are specified. exiting." && exit 1 + + +#NUMBER OF CLIENTS THAT ARE MONITORED +number_of_owners=$((${#macaddress_owners[@]})) + # ---------------------------------------------------------------------------------------- # DEBUG FUNCTION # ---------------------------------------------------------------------------------------- debug_echo () { - if [ "$debug" == "1" ]; then + if [ "$debug" == "1" ]; then (>&2 echo -e "${ORANGE}DEBUG MSG: $1${NC}") - fi + fi } # ---------------------------------------------------------------------------------------- -# SCAN +# SCAN # ---------------------------------------------------------------------------------------- scan () { - if [ ! -z "$1" ]; then + if [ ! -z "$1" ]; then local result=$(hcitool -i $hci_device name "$1" 2>&1 | grep -v 'not available' | grep -vE "hcitool|timeout|invalid|error" ) debug_echo "Scan result: [$result]" - echo "$result" + echo "$result" fi } @@ -169,20 +169,20 @@ scan () { # ---------------------------------------------------------------------------------------- publish () { - if [ ! -z "$1" ]; then + if [ ! -z "$1" ]; then #SET NAME FOR 'UNKONWN' local name="$3" #IF NO NAME, RETURN "UNKNOWN" - if [ -z "$3" ]; then + if [ -z "$3" ]; then name="Unknown" - fi + fi #TIMESTAMP stamp=$(date "+%a %b %d %Y %H:%M:%S GMT%z (%Z)") - #DEBUGGING + #DEBUGGING [ "$debug" == "1" ] && (>&2 echo -e "${PURPLE}$mqtt_topicpath$1 { confidence : $2, name : $name, scan_duration_ms: $4, timestamp : $stamp} ${NC}") #POST TO MQTT @@ -203,7 +203,7 @@ one_owner_home=0 #FLAG FOR AT LEAST ONE OWNER BEING HOME # ---------------------------------------------------------------------------------------- #MAIN LOOP -while true; do +while true; do #RESET AT LEAST ONE DEVICE HOME one_owner_home=0 @@ -222,7 +222,7 @@ while true; do current_device_address="${macaddress_owners[$index]}" #CHECK FOR ADDITIONAL BLANK LINES IN ADDRESS FILE - if [ -z "$current_device_address" ]; then + if [ -z "$current_device_address" ]; then continue fi @@ -231,12 +231,12 @@ while true; do #OBTAIN RESULTS AND APPEND EACH TO THE SAME name_scan_result=$(scan $current_device_address) - + #MARK END OF SCAN OPERATION end_time=$(date +%s%N) - + #CALCULATE DIFFERENCE - duration_timer=$(( (end_time - start_timer) / 1000000 )) + duration_timer=$(( (end_time - start_timer) / 1000000 )) #THIS DEVICE NAME IS PRESENT if [ "$name_scan_result" != "" ]; then @@ -247,7 +247,7 @@ while true; do #NO DUPLICATE MESSAGES [ "$ok_to_publish" == "1" ] && publish "/$mqtt_room/$current_device_address" '100' "$name_scan_result" "$duration_timer" - #USER STATUS + #USER STATUS device_statuses[$index]="100" #SET AT LEAST ONE DEVICE HOME @@ -258,25 +258,25 @@ while true; do else - #USER STATUS + #USER STATUS status="${device_statuses[$index]}" - if [ -z "$status" ]; then + if [ -z "$status" ]; then status="0" - fi + fi #BY DEFAULT, SET REPETITION TO PREFERENCE repetitions="$verification_of_away_loop_size" - #IF WE ARE JUST STARTING OR, ALTERNATIVELY, WE HAVE RECORDED THE STATUS - #OF NOT HOME ALREADY, ONLY SCAN ONE MORE TIME. - if [ "$status" == 0 ];then + #IF WE ARE JUST STARTING OR, ALTERNATIVELY, WE HAVE RECORDED THE STATUS + #OF NOT HOME ALREADY, ONLY SCAN ONE MORE TIME. + if [ "$status" == 0 ];then repetitions=1 - fi + fi #SHOULD VERIFY ABSENSE - for repetition in $(seq 1 $repetitions); - do + for repetition in $(seq 1 $repetitions); + do #RESET OK TO PUBLISH ok_to_publish=1 @@ -287,7 +287,7 @@ while true; do percentage=$(($status * ( $repetitions - $repetition) / $repetitions)) #ONLY SCAN IF OUR STATUS IS NOT ALREADY 0 - if [ "$status" != 0 ];then + if [ "$status" != 0 ];then #MARK BEGINNING OF SCAN OPERATION start_timer=$(date +%s%N) @@ -297,12 +297,12 @@ while true; do #MARK END OF SCAN OPERATION end_time=$(date +%s%N) - + #CALCULATE DIFFERENCE - duration_timer=$(( (end_time - start_timer) / 1000000 )) + duration_timer=$(( (end_time - start_timer) / 1000000 )) - #CHECK SCAN - if [ "$name_scan_result_verify" != "" ]; then + #CHECK SCAN + if [ "$name_scan_result_verify" != "" ]; then #STATE IS SAME && ONLY REPORT CHANGES THEN DISABLE PUBLICATION [ "${device_statuses[$index]}" == '100' ] && [ "$changes_only" == 1 ] && ok_to_publish=0 @@ -322,18 +322,18 @@ while true; do #MUST BREAK CONFIDENCE SCANNING LOOP; 100' ISCOVERED break fi - fi + fi - #RETREIVE LAST-KNOWN NAME FOR PUBLICATION; SINCE WE OBVIOUSLY DIDN'T RECEIVE A NAME SCAN RESULT + #RETREIVE LAST-KNOWN NAME FOR PUBLICATION; SINCE WE OBVIOUSLY DIDN'T RECEIVE A NAME SCAN RESULT expectedName="${device_names[$index]}" - if [ "$percentage" == "0" ]; then + if [ "$percentage" == "0" ]; then #STATE IS SAME && ONLY REPORT CHANGES THEN DISABLE PUBLICATION [ "${device_statuses[$index]}" == '0' ] && [ "$changes_only" == 1 ] && ok_to_publish=0 #PRINT ZERO CONFIDENCE OF A DEVICE AT HOME [ "$ok_to_publish" == "1" ] && publish "/$mqtt_room/$current_device_address" "0" "$expectedName" "$duration_timer" - else + else #STATE IS SAME && ONLY REPORT CHANGES THEN DISABLE PUBLICATION [ "${device_statuses[$index]}" == '$percentage' ] && [ "$changes_only" == 1 ] && ok_to_publish=0 @@ -342,10 +342,10 @@ while true; do #REPORT CONFIDENCE DROP [ "$ok_to_publish" == "1" ] && publish "/$mqtt_room/$current_device_address" "$percentage" "$expectedName" "$duration_timer" - fi + fi #UPDATE STATUS ARRAY - device_statuses[$index]="$percentage" + device_statuses[$index]="$percentage" done fi done @@ -354,7 +354,7 @@ while true; do wait_duration=0 #DETERMINE APPROPRIATE DELAY - if [ "$one_owner_home" == 1 ]; then + if [ "$one_owner_home" == 1 ]; then wait_duration=$delay_between_owner_scans_present else wait_duration=$delay_between_owner_scans_away From 3acf01dfadd0b6ff2e39286b25b74696de64e3f6 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:18:04 -0400 Subject: [PATCH 06/14] Added -p option to getops to allow for change of base directory as arg --- presence.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/presence.sh b/presence.sh index efaa16a..37dd6b5 100755 --- a/presence.sh +++ b/presence.sh @@ -46,6 +46,7 @@ show_help_text() { echo " presence -d print debug messages and mqtt messages" echo " presence -b binary output only; either 100 or 0 confidence" echo " presence -c only post confidence status changes for owners/guests" + echo " presence -p path of configuration files" echo " presence -V print version" } @@ -60,7 +61,7 @@ debug=0 binary_only=0 changes_only=0 -while getopts "h?Vdbct:" opt; do +while getopts "h?Vdbcp:t:" opt; do case "$opt" in h|\?) show_help_text @@ -74,7 +75,9 @@ while getopts "h?Vdbct:" opt; do ;; b) binary_only=1 ;; - c) changes_only=1 + c) changes_only=1 + ;; + p) base_directory="$OPTARG" ;; *) echo "warning: unknown or depreciated option: $opt" esac From 30628d60c1f341d30235f89bb15a399b87ab8eb0 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:21:48 -0400 Subject: [PATCH 07/14] Updated Dockerfile to use config path option --- docker/Dockerfile.amd64 | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 37e8c8d..37ed4bd 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -1,11 +1,7 @@ FROM amd64/ubuntu # Install and update packages -RUN apt-get update && apt-get install -y \ - bluez \ - git \ - wget \ - apt-transport-https +RUN apt-get update && apt-get install -y bluez git # Install Mosquitto and friends RUN apt-get install -y \ @@ -14,17 +10,7 @@ RUN apt-get install -y \ mosquitto \ mosquitto-clients -# Clone repo into working directory -#RUN git clone https://github.com/andrewjfreyer/presence.git /presence - # Change script permissions -RUN mkdir /presence -WORKDIR /presence -COPY . . - RUN chmod +x presence.sh -# Copy configuration files -#COPY behavior_preferences mqtt_preferences owner_devices ./ - -CMD ["presence/presence.sh"] +CMD ["presence.sh", "-p", "/config"] From 43d39da2b5a1065ab2d8df59bc77819c188bec47 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:26:21 -0400 Subject: [PATCH 08/14] Added directory --- docker/Dockerfile.amd64 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 37ed4bd..14672f9 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -1,5 +1,9 @@ FROM amd64/ubuntu +# Create directory +RUN mkdir -p /presence +WORKDIR /presence + # Install and update packages RUN apt-get update && apt-get install -y bluez git From 500943d6557e5a0981d528fcd38294a04cbba747 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:29:32 -0400 Subject: [PATCH 09/14] Added copy command --- docker/Dockerfile.amd64 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 14672f9..56127d0 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -14,7 +14,8 @@ RUN apt-get install -y \ mosquitto \ mosquitto-clients -# Change script permissions +# Copy and change script permissions +COPY . . RUN chmod +x presence.sh CMD ["presence.sh", "-p", "/config"] From 1bb193391767baa499621dee9759046cae6fc44e Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:32:48 -0400 Subject: [PATCH 10/14] Added entrypoint --- docker/Dockerfile.amd64 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index 56127d0..af87a63 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -18,4 +18,5 @@ RUN apt-get install -y \ COPY . . RUN chmod +x presence.sh -CMD ["presence.sh", "-p", "/config"] +ENTRYPOINT ["/bin/bash"] +CMD ["/presence/presence.sh", "-p", "/config"] From 9e649ed30a9981b115aa3843eb1c27479e63ba8b Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 21:36:40 -0400 Subject: [PATCH 11/14] Dockerfile resdesign to work with Github context --- docker/Dockerfile.amd64 | 3 ++- docker/Dockerfile.armhf | 24 +++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docker/Dockerfile.amd64 b/docker/Dockerfile.amd64 index af87a63..e79d099 100644 --- a/docker/Dockerfile.amd64 +++ b/docker/Dockerfile.amd64 @@ -15,8 +15,9 @@ RUN apt-get install -y \ mosquitto-clients # Copy and change script permissions -COPY . . +COPY presence.sh . RUN chmod +x presence.sh +# Set entrypoint and run ENTRYPOINT ["/bin/bash"] CMD ["/presence/presence.sh", "-p", "/config"] diff --git a/docker/Dockerfile.armhf b/docker/Dockerfile.armhf index 6ae7531..4300145 100644 --- a/docker/Dockerfile.armhf +++ b/docker/Dockerfile.armhf @@ -1,29 +1,23 @@ FROM resin/raspberry-pi-debian +# Create directory +RUN mkdir -p /presence +WORKDIR /presence + # Install and update packages -RUN apt-get update && apt-get install -y \ - bluez \ - git \ - wget \ - apt-transport-https +RUN apt-get update && apt-get install -y bluez git # Install Mosquitto and friends -RUN apt-get update RUN apt-get install -y \ libwebsockets-dev \ libmosquitto-dev \ mosquitto \ mosquitto-clients -# Clone repo into working directory -RUN git clone https://github.com/andrewjfreyer/presence.git /presence - -# Change script permissions -WORKDIR /presence +# Copy and change script permissions +COPY presence.sh . RUN chmod +x presence.sh -# Copy configuration files -COPY behavior_preferences mqtt_preferences owner_devices ./ - +# Set entrypoint and run ENTRYPOINT ["/bin/bash"] -CMD ["/presence/presence.sh"] +CMD ["/presence/presence.sh", "-p", "/config"] From 2101ebbf6b9536a43a7d5a2f5c357a8fbdf6bd85 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 22:40:14 -0400 Subject: [PATCH 12/14] Created README.md for Docker directory --- docker/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..53f5f36 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,42 @@ +# Presence Docker Installation + +### Dockerfiles + +The `docker` folder contains Dockerfiles for deploying Presence on different architectures. Choose the file that matches your machine's architecture: + +**`Dockerfile.amd64`** +
+Your typical x64 machine - if you are deploying on a 64-bit laptop or desktop, this is the one you want. + +**`Dockerfile.armhf`** +
+The Raspberry Pi architecture - use this file if you are deploying on a Raspbery Pi. Confirmed working on: + - Raspberry Pi Zero W + - Raspberry Pi 3 + +### Example Docker Compose Installation + +1. Create a file called `docker-compose.yaml` and copy the example template below to the file. + +2. Create a local configuration directory on your host machine and create the files `behavior_preferences`, `mqtt_preferences`, and `owner_devices` per the main repository instructions. + +3. Change `` to the Dockerfile extension that matches your architecture. + +4. Change `` to the path of the local configuration directory you created in Step 2. + + +``` +version: "3" +services: + + # Presence -------------------------------------- + presence: + container_name: presence + network_mode: "host" + build: + context: https://github.com/iicky/presence.git + dockerfile: docker/Dockerfile. + volumes: + - :/config + restart: on-failure +``` From 04759d218a32fe245d3d32d5da50a317b89ad5b6 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 22:41:10 -0400 Subject: [PATCH 13/14] Updated README.md --- docker/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/README.md b/docker/README.md index 53f5f36..1f61a52 100644 --- a/docker/README.md +++ b/docker/README.md @@ -40,3 +40,10 @@ services: - :/config restart: on-failure ``` + +5. Build and deploy the Docker container by running the following commands: + +``` +docker-compose build presence +docker-compose up -d presence +``` From 7de8ff8e78c1ff91d51c8d34d22b3a0dbd569fc2 Mon Sep 17 00:00:00 2001 From: Mickey Scherrer Date: Fri, 21 Sep 2018 22:41:57 -0400 Subject: [PATCH 14/14] Update README.md --- docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index 1f61a52..fb31434 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,7 +2,7 @@ ### Dockerfiles -The `docker` folder contains Dockerfiles for deploying Presence on different architectures. Choose the file that matches your machine's architecture: +The `docker` folder contains Dockerfiles for deploying Presence in Docker containers on different architectures. Choose the file that matches your machine's architecture: **`Dockerfile.amd64`**