From b354954a071f5cb0cbbbefa923de6c3b7aa81a38 Mon Sep 17 00:00:00 2001 From: "Derek J. Clark" Date: Sat, 26 Nov 2022 21:55:21 -0800 Subject: [PATCH] Use environment home instead of hard coding home_path --- Makefile | 93 ++++++++++++++++++++++++++++++++++++++++++ backend/Cargo.lock | 4 +- backend/Cargo.toml | 2 +- backend/src/main.rs | 9 +++- backend/src/utility.rs | 2 +- 5 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..691d433 --- /dev/null +++ b/Makefile @@ -0,0 +1,93 @@ +# Configuration settings +PLUGIN_NAME ?= $(shell basename $(PWD)) +PLUGIN_VERSION ?= 0.3.0 + +# Source files +TS_FILES := $(shell find src -name *.ts) +TSX_FILES := $(shell find src -name *.tsx) +SRC_FILES := $(TS_FILES) $(TSX_FILES) plugin.json + +TAR_FILES := bin dist main.py package.json plugin.json + +# plugin dir +DATA_PATH ?= homebrew + +# SSH Configuration +SSH_USER ?= gamer +SSH_HOST ?= 192.168.0.246 +SSH_MOUNT_PATH ?= /tmp/remote +SSH_DATA_PATH ?= /home/$(SSH_USER)/$(DATA_PATH) + +# Default target is to build and restart crankshaft +.PHONY: default +default: build restart + +.PHONY: build +build: build ## Builds the project + cd backend && ./build.sh && cd .. + +dist: $(SRC_FILES) node_modules + npm run build + +.PHONY: watch +watch: ## Build and watch for source code changes + npm run build-watch + +package-lock.json: package.json + npm i + +node_modules: node_modules/installed ## Install dependencies +node_modules/installed: package-lock.json + npm ci + touch $@ + +.PHONY: restart +restart: ## Restart crankshaft + ssh $(SSH_USER)@$(SSH_HOST) sudo systemctl restart plugin_loader -S + +.PHONY: debug +debug: ## Show Makefile variables + @echo "Source Files: $(SRC_FILES)" + +.PHONY: cef-debug +cef-debug: ## Open Chrome CEF debugging. Add a network target: localhost:8080 + chromium "chrome://inspect/#devices" + +.PHONY: tunnel +tunnel: ## Create an SSH tunnel to remote Steam Client (accessible on localhost:4040) + ssh $(SSH_USER)@$(SSH_HOST) -N -f -L 4040:localhost:8080 + +$(SSH_MOUNT_PATH)/.mounted: + mkdir -p $(SSH_MOUNT_PATH) + sshfs -o default_permissions $(SSH_USER)@$(SSH_HOST):$(SSH_DATA_PATH) $(SSH_MOUNT_PATH) + touch $(SSH_MOUNT_PATH)/.mounted + $(MAKE) tunnel + +# Cleans and transfers the project +$(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME): $(SRC_FILES) +# rm -rf $(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME) +# mkdir -p $(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME) +# cp -r $(TAR_FILES) $(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME) + +# Cleans and transfers the project +$(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME): $(SRC_FILES) + rsync -avh $(PWD)/ $(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME) --delete + +.PHONY: remote-restart +remote-restart: ## Restart remote crankshaft + ssh $(SSH_USER)@$(SSH_HOST) sudo systemctl restart plugin_loader + +.PHONY: mount +mount: $(SSH_MOUNT_PATH)/.mounted + +.PHONY: remote-update +remote-update: $(SSH_MOUNT_PATH)/plugins/$(PLUGIN_NAME) + +.PHONY: clean +clean: ## Clean all build artifacts + rm -rf build dist bin + +.PHONY: help +help: ## Show this help message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0dfa192..366d7f7 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1077,9 +1077,9 @@ dependencies = [ [[package]] name = "usdpl-back" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca96dac4ee471e9534940f99cb36f5212cbfaf4e7779eb3ba970d3c511d9583" +checksum = "88709aa9d6c5c65c0e8715dbb716b253ceebd0bd1097c4e5316660320ae604e1" dependencies = [ "async-recursion", "async-trait", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 9fbf9bd..a3a324a 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -usdpl-back = { version = "0.7.0", features = ["blocking"]} +usdpl-back = { version = "0.7.1", features = ["blocking"]} serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/backend/src/main.rs b/backend/src/main.rs index c3e07a8..ed8dcdb 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -18,14 +18,18 @@ use usdpl_back::core::serdes::Primitive; use usdpl_back::Instance; fn main() -> Result<(), ()> { + + let binding = usdpl_back::api::dirs::home().unwrap(); + let home_path = binding.to_str().unwrap(); + #[cfg(debug_assertions)] - let log_filepath = format!("/home/deck/{}.log", PACKAGE_NAME); + let log_filepath = format!("{}/{}.log", home_path, PACKAGE_NAME); #[cfg(not(debug_assertions))] let log_filepath = format!("/tmp/{}.log", PACKAGE_NAME); #[cfg(debug_assertions)] { if std::path::Path::new(&log_filepath).exists() { - std::fs::copy(&log_filepath, format!("/home/deck/{}.log.old", PACKAGE_NAME)).unwrap(); + std::fs::copy(&log_filepath, format!("{}/{}.log.old", home_path, PACKAGE_NAME)).unwrap(); } } WriteLogger::init( @@ -41,6 +45,7 @@ fn main() -> Result<(), ()> { std::fs::File::create(&log_filepath).unwrap(), ) .unwrap(); + log::debug!("Found home dir {:?}", home_path); log::info!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION); println!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION); diff --git a/backend/src/utility.rs b/backend/src/utility.rs index 1c1f90c..e3e8a71 100644 --- a/backend/src/utility.rs +++ b/backend/src/utility.rs @@ -26,6 +26,6 @@ pub fn unwrap_maybe_fatal(result: Result, message: & pub fn settings_dir() -> std::path::PathBuf { usdpl_back::api::dirs::home() - .unwrap_or_else(|| "/home/deck".into()) + .unwrap() .join(".config/powertools/") }