#!/usr/bin/env bash set -e # if any command fails, stop immediately { # this ensures the entire script is downloaded # CVMT_PKGDIR="/opt/cvmt" CVMT_CDNURL="https://svsupport.blob.core.windows.net/files/VisionSense_Trainer/Packages" CVMT_APTPKG="ca-certificates curl gpg" CVMT_DOTENV="" CVMT_BASEON="" CVMT_DBTYPE="" CVMT_DBNAME="cvmt" CVMT_DBUSER="cvmt" CVMT_DBPASS= CVMT_DBHOST="pg" CVMT_DBPORT="5432" CVMT_GWTYPE="" cvmt_console_color() { local color_code="$1" local text="$2" echo -e "\033[${color_code}m${text}\033[0m" } cvmt_console_error() { local text="$1" cvmt_console_color "31" "$text" } cvmt_console_title() { local text="$1" cvmt_console_color "36" "$text" } cvmt_console_light() { local text="$1" cvmt_console_color "96" "$text" } cvmt_console_event() { local text="$1" cvmt_console_color "32" "$text" } cvmt_network_ipaddress() { local interface="$1" ip addr show "$interface" | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1 } cvmt_welcome() { local accept_eula="n" cvmt_console_title "Welcome to CVMT Installer" echo "This script will help you install CVMT on your system." echo "Please follow the prompts to complete the installation." echo cvmt_console_title "End User License Agreement (EULA)" echo "Please read the EULA carefully before proceeding." echo "" echo "https://svsupport.blob.core.windows.net/files/VisionSense_Trainer/Packages/EULA.txt" echo "" echo "By continuing, you agree to the terms and conditions of the EULA." echo read -r -p "Do you accept the EULA? (y/N): " accept_eula /dev/null sudo chown $(whoami):$(whoami) $Out sudo chmod 600 $Out fi } cvmt_install_config_fetch() { local Url="$CVMT_CDNURL/$1" local Out="$CVMT_PKGDIR/$1" sudo curl -L $Url -o $Out sudo chown $(whoami):$(whoami) $Out sudo chmod 600 $Out if [ ! -f $Out ]; then local delay=30 cvmt_console_error "Failed to download $1 from $Url, Retrying in $delay seconds..." sleep $delay cvmt_install_config_fetch "$1" fi } cvmt_install_config_advenv() { cvmt_install_config_fetch "compose-cv.yml" cvmt_install_config_fetch "compose-hw.yml" } cvmt_install_config_wslenv() { cvmt_install_config_fetch "compose-cv.yml" cvmt_install_config_fetch "compose-db.yml" cvmt_install_config_fetch "compose-ep.yml" } cvmt_install_config() { cvmt_console_title "Downloading Compose Stack Configuration" echo "This will download the Docker Compose stack configuration files for CVMT." echo if [ "$CVMT_BASEON" = "ADVENV" ]; then cvmt_install_config_advenv elif [ "$CVMT_BASEON" = "WSLENV" ]; then cvmt_install_config_wslenv else cvmt_console_error "Compose stack installation for this environment is not implemented yet." exit 1 fi if [ ! -f $CVMT_PKGDIR/.env ]; then cvmt_console_error ".env file not found in $CVMT_PKGDIR. Installation aborted." exit 1 fi while ! sudo docker compose --env-file $CVMT_PKGDIR/.env pull; do local delay=30 cvmt_console_error "Fail to pull docker images. Retrying in $delay seconds..." sleep $delay done } cvmt_install() { cvmt_install_docker cvmt_install_nvidia cvmt_install_option cvmt_install_config } cvmt_cleanup_advenv() { echo "Continue to setup other packages for Advantech Environment..." } cvmt_cleanup_wslenv() { cd $CVMT_PKGDIR sudo docker compose --env-file $CVMT_PKGDIR/.env up -d echo cvmt_console_title "Thank you for trying VisionSense Trainer!" local ipaddr=$(cvmt_network_ipaddress "eth0") echo echo "To access Trainer in Windows Host, please run the following command in PowerShell as Administrator:" echo cvmt_console_light "Add-Content -Path \"C:/Windows/System32/drivers/etc/hosts\" -Value \"$ipaddr trainer.local\"" echo echo "You can verify the entry has been added by running:" echo cvmt_console_light "Resolve-DnsName trainer.local" echo echo "Then open your web browser in Windows Host and go to:" echo cvmt_console_light "http://trainer.local" echo } cvmt_cleanup() { cvmt_console_title "Installation Completed" echo "CVMT has been successfully installed on your system." echo if [ "$CVMT_BASEON" = "ADVENV" ]; then cvmt_cleanup_advenv elif [ "$CVMT_BASEON" = "WSLENV" ]; then cvmt_cleanup_wslenv else cvmt_console_error "Cleanup for this environment is not implemented yet." exit 1 fi } cvmt_welcome cvmt_require cvmt_setting cvmt_install cvmt_cleanup } # this ensures the entire script is downloaded #