From cb4b2d149f68fc72890c3e354ab50da92158649e Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Sun, 3 May 2020 20:10:54 -0700 Subject: [PATCH] WIP. --- advisorycircular.sh | 11 ++-- install.sh | 35 ++++++++----- package-lock.json | 59 ++++++++++++++-------- package.json | 2 +- src/main/lemondronor/advisorycircular.cljs | 12 ++++- 5 files changed, 78 insertions(+), 41 deletions(-) diff --git a/advisorycircular.sh b/advisorycircular.sh index 0c1ce13..22ee7d3 100644 --- a/advisorycircular.sh +++ b/advisorycircular.sh @@ -2,9 +2,12 @@ set -e dir=$(dirname "$0") -config_dir=/etc/advisorycircular instance="$1" +config_dir=/etc/advisorycircular +run_dir=/var/run/advisorycircular +sqb_path=/usr/local/share/run/advisorycircular/clean-basestation.sqb -config_path="$config_dir"/"$instance".conf -secrets_path="$config_dir"/"$instance".secret -"$dir"/intervalexec 10 node $dir/out/advisorycircular.js --config "$config_path" --secrets "$secrets_path" +config_path="$config_dir"/"$instance"-config.yaml +secrets_path="$config_dir"/"$instance"-secrets.yaml +history_path="$run_dir"/"$instance"-history.edn +(cd "$run_dir" && "$dir"/intervalexec 10 node $dir/out/advisorycircular.js --config "$config_path" --secrets "$secrets_path" --basestation-sqb "$sqb_path" --history "$history_path") diff --git a/install.sh b/install.sh index a66d271..5e1c8e0 100755 --- a/install.sh +++ b/install.sh @@ -2,16 +2,18 @@ set -e install_path=/usr/local/share/advisorycircular config_path=/etc/advisorycircular +run_path=/var/run/advisorycircular user=advisorycircular -# Create install and config directories if they doesn't exist. -mkdir -p "$install_path" -mkdir -p "$config_path" +# Create install, config, and run directories if they doesn't exist. +sudo mkdir -p "$install_path" +sudo mkdir -p "$config_path" +sudo mkdir -p "$run_path" # Create advisory-circular user if it doesn't exist. if ! id -u ${user} 2>/dev/null then - adduser --system --home ${install_path} --no-create-home --quiet ${user} + sudo adduser --system --home ${install_path} --no-create-home --quiet ${user} fi # Compile. @@ -19,14 +21,19 @@ npm install npx shadow-cljs compile script # Install -install intervalexec.py advisorycircular "$install_path"/intervalexec -install advisorycircular.sh "$install_path"/advisorycircular -cp -r node_modules "$install_path" -cp -r .shadow-cljs "$install_path" -mkdir -p "$install_path"/out -cp out/advisorycircular.js "$install_path"/out -chown -R "$user" "$install_path" +sudo install intervalexec.py "$install_path"/intervalexec +sudo install advisorycircular.sh "$install_path"/advisorycircular +sudo cp -r node_modules "$install_path" +sudo cp -r .shadow-cljs "$install_path" +sudo mkdir -p "$install_path"/out +sudo cp out/advisorycircular.js "$install_path"/out +sudo cp clean-basestation.sqb "$install_path" +sudo chown -R "$user" "$install_path" -cp config-skel.yaml "$config_path" -cp secrets-skel.yaml "$config_path" -chown -R "$user" "$config_path" +sudo cp config-skel.yaml "$config_path" +sudo cp secrets-skel.yaml "$config_path" +sudo chmod go-r "$config_path"/secrets-skel.yaml +sudo chown -R "$user" "$config_path" + +sudo chown -R "$user" "$run_path" +sudo chmod go-w "$run_path" diff --git a/package-lock.json b/package-lock.json index c826ccd..ee656a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "circlebot", + "name": "advisorycircular", "version": "0.0.1", "lockfileVersion": 1, "requires": true, @@ -589,9 +589,9 @@ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, "events": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.0.0.tgz", - "integrity": "sha512-Dc381HFWJzEOhQ+d8pkNon++bk9h6cdAoAj4iE6Q4y6xgTzySWXlKn05/TVNpjnfRqi/X0EpJEJohPjNI3zpVA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.1.0.tgz", + "integrity": "sha512-Rv+u8MLHNOdMjTAFeT3nCjHn2aGlx435FP/sDHNaRhDEMwyI/aB22Kj2qIN8R0cw3z28psEQLYwxVKLsKrMgWg==", "dev": true }, "evp_bytestokey": { @@ -757,13 +757,33 @@ "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" }, "hash-base": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", - "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", + "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", "dev": true, "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" + "inherits": "^2.0.4", + "readable-stream": "^3.6.0", + "safe-buffer": "^5.2.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==", + "dev": true + } } }, "hash.js": { @@ -1239,9 +1259,9 @@ } }, "pako": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.10.tgz", - "integrity": "sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==", + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", "dev": true }, "parse-asn1": { @@ -1531,15 +1551,14 @@ } }, "shadow-cljs": { - "version": "2.8.83", - "resolved": "https://registry.npmjs.org/shadow-cljs/-/shadow-cljs-2.8.83.tgz", - "integrity": "sha512-oqqSLARvYXopA9QLf5znrguvJOSRm65LYL9XHuRWaUbMGXlygqgCjSFgW1yREXmqUQ+i2TLoA1zulYO6nTTy6g==", + "version": "2.8.109", + "resolved": "https://registry.npmjs.org/shadow-cljs/-/shadow-cljs-2.8.109.tgz", + "integrity": "sha512-xUN5kBYgyk2OVv3Gz9/dxJdDNoImskYg6VNLpHkubCG46Q1Lv9tymd11Hyekka6WWk24QCNSVIyPta82txZGfQ==", "dev": true, "requires": { - "mkdirp": "^0.5.1", "node-libs-browser": "^2.0.0", "readline-sync": "^1.4.7", - "shadow-cljs-jar": "1.3.1", + "shadow-cljs-jar": "1.3.2", "source-map-support": "^0.4.15", "which": "^1.3.1", "ws": "^3.0.0" @@ -1559,9 +1578,9 @@ } }, "shadow-cljs-jar": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/shadow-cljs-jar/-/shadow-cljs-jar-1.3.1.tgz", - "integrity": "sha512-IJSm4Gfu/wWDsOQ0wNrSxuaGdjzsd78us+3bop3cpWsoO2Igdu6VIBItYrZHRRBKl5LIZKXfnSh/2eWG3C1EFw==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/shadow-cljs-jar/-/shadow-cljs-jar-1.3.2.tgz", + "integrity": "sha512-XmeffAZHv8z7451kzeq9oKh8fh278Ak+UIOGGrapyqrFBB773xN8vMQ3O7J7TYLnb9BUwcqadKkmgaq7q6fhZg==", "dev": true }, "signal-exit": { diff --git a/package.json b/package.json index 045fd46..711db4d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "private": true, "devDependencies": { - "shadow-cljs": "^2.8.83" + "shadow-cljs": "^2.8.109" }, "dependencies": { "commander": "^4.0.1", diff --git a/src/main/lemondronor/advisorycircular.cljs b/src/main/lemondronor/advisorycircular.cljs index 2137348..b39b965 100644 --- a/src/main/lemondronor/advisorycircular.cljs +++ b/src/main/lemondronor/advisorycircular.cljs @@ -541,7 +541,7 @@ ;; close to an airport, then it's probably just doing flight ;; training. :minimum-airport-distance-km 2.5 - :history-db-path "advisory-circular.db" + :history-db-path "advisorycircular.edn" :basestation-sqb "basestation.sqb" :twitter {:enabled? true}}) @@ -560,6 +560,8 @@ (assoc-in [:pelias :url] (.-peliasUrl commander)) (.-basestationSqb commander) (assoc :basestation-sqb (.-basestationSqb commander)) + (.-history commander) + (assoc :history-db-path (.-history commander)) (.-lat commander) (assoc :lat (.-lat commander)) (.-lon commander) @@ -607,6 +609,7 @@ (.option "--no-tweeting" "Do not tweet") (.option "--config " "Path to the configuration yaml file") (.option "--secrets " "Path to the secrets yaml file" "secrets.yaml") + (.option "--history " "Path to history/state file" "advisorycircular.edn") (.parse (.-argv js/process))) (let [start-time (current-time)] ;; If --config-path is specified, definitely try to read that @@ -621,7 +624,11 @@ secrets (util/read-config (.-secrets commander)) config (build-config base-config cli-config secrets) _ (validate-config config) - db (read-history-db (:history-db-path config)) + history-db-path (:history-db-path config) + _ (when (not (fs/existsSync history-db-path)) + (log-info "%s does not exist; creating empty one." history-db-path) + (write-history-db {} history-db-path)) + db (read-history-db history-db-path) data (get-adsbexchange-live-data {:url (get-in config [:adsbx :url]) :api-key (get-in config [:adsbx :api-key]) @@ -645,6 +652,7 @@ (count new-db) (count potential-circles))))) (p/catch :default e + (log-error "%s" e) (log-error "%s" (.-stack e)) (.exit js/process 1)))))