From b50ab8109e99fd3242c50018c622044060304ed3 Mon Sep 17 00:00:00 2001 From: Chris Oloff Date: Wed, 14 Jan 2026 18:47:35 +0200 Subject: [PATCH 1/2] install.sh, now actually installing from the template --- install.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index fe5a143..f249da5 100644 --- a/install.sh +++ b/install.sh @@ -1,4 +1,72 @@ -#!/bin/sh +#!/usr/local/env bash + +echo "installing Watt42 components for development..." + +# Define a function to read from the terminal +read_from_terminal() { + # Check if a tty is available + if [[ -t 0 ]]; then + # Use 'read -p' if standard input is an interactive terminal + read -p "$1" user_input + else + printf "\n" > /dev/tty + # If not interactive (e.g. piped), read from /dev/tty + # The '< /dev/tty' redirects input for 'read' to the terminal device + read -p "$1" user_input < /dev/tty + fi + echo "$user_input" +} + +required_commands=( git poetry ) +# ensure we have required commands available +for cmd in "${required_commands[@]}"; do + if ! command -v "$cmd" &> /dev/null; then + echo "Error: $cmd is not installed." >&2 + exit 1 + fi +done + +# ensure TARGET is either 'view' or 'client' +if [ -z "$TARGET" ] || { [ "$TARGET" != "view" ] && [ "$TARGET" != "client" ]; }; then + echo "Error: TARGET environment variable must be set to either 'view' or 'client'." >&2 + exit 1 +fi + +# determine exec directory +SCRIPT_DIR="$( pwd )" + +# create temp dir and cleanup on exit (TODO: we don't need a temp dir at the moment) +TEMP_DIR="$( mktemp -d )" +trap 'rm -rf "$TEMP_DIR"' EXIT + +cd ${TEMP_DIR} || exit 1 + +# prompt for directory name to clone template into +DIR_NAME=$(read_from_terminal "Enter your project name: ") + +read_from_terminal "Cloning template into ${SCRIPT_DIR}/${DIR_NAME}, press Enter to continue..." + +git clone https://source.c3.uber5.com/watt42-public/watt42-panelview-template.git "${SCRIPT_DIR}/${DIR_NAME}" + +# remove the origin from git +(cd "${SCRIPT_DIR}/${DIR_NAME}" || exit 1; git remote remove origin) + +echo "Your ${TARGET} project has been created in ${SCRIPT_DIR}/${DIR_NAME}" + +read_from_terminal "Installing dependencies with poetry, press Enter to continue..." +(cd "${SCRIPT_DIR}/${DIR_NAME}" || exit 1; poetry install) + +TOKEN=$(read_from_terminal "What is your API TOKEN? (request one at https://www.watt42.com/contact?request-token=1): ") + +# write token to .env file +echo "WATT42_API_TOKEN=${TOKEN}" > "${SCRIPT_DIR}/${DIR_NAME}/.env" + +SYSTEM_ID=$(read_from_terminal "What is your SYSTEM ID? (you can find it in your watt42.com dashboard): ") +# append system id to .env file +echo "WATT42_SYSTEM_ID=${SYSTEM_ID}" >> "${SCRIPT_DIR}/${DIR_NAME}/.env" + +echo "Setup complete! We will now start the ${TARGET} application. To run it later, navigate to ${SCRIPT_DIR}/${DIR_NAME} and run './run.sh'" + +# start the application +(cd "${SCRIPT_DIR}/${DIR_NAME}" || exit 1; ./run.sh) -echo "should install stuff..." -exit 0 \ No newline at end of file From 710f2611282c06b80f1263dfa3d7c53dbfebb164 Mon Sep 17 00:00:00 2001 From: Chris Oloff Date: Wed, 14 Jan 2026 18:48:10 +0200 Subject: [PATCH 2/2] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef6e5ca..9f57a75 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,5 @@ Install a frontend for a Watt42 system, experimental: ```sh -wget -q -O - https://source.c3.uber5.com/watt42-public/install/raw/branch/main/install.sh | bash +wget -q -O - https://source.c3.uber5.com/watt42-public/install/raw/branch/main/install.sh | TARGET=view bash ```