install.sh, now actually installing from the template
This commit is contained in:
parent
d2d303d06b
commit
b50ab8109e
1 changed files with 71 additions and 3 deletions
74
install.sh
74
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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue