From 8699f07763aed3d58eb2e3236e1edea0fe316b1f Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Tue, 26 Dec 2023 11:53:26 -0500 Subject: [PATCH] Add fancy terminal styling to the scripts --- scripts/.function-lib.sh | 62 ++++++++++++++++++++++ scripts/compile-custom-inkay.sh | 15 ++++-- scripts/create-juxt-community.sh | 1 + scripts/firstrun-minio-container.sh | 3 +- scripts/firstrun-mongodb-container.sh | 5 +- scripts/make-pnid-dev.sh | 3 +- scripts/setup-environment.sh | 25 +++++---- scripts/setup-submodule-patches.sh | 11 ++-- scripts/update-account-servers-database.sh | 5 +- scripts/update-miiverse-endpoints.sh | 1 + scripts/update-postgres-password.sh | 3 +- 11 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 scripts/.function-lib.sh diff --git a/scripts/.function-lib.sh b/scripts/.function-lib.sh new file mode 100644 index 0000000..28fb93f --- /dev/null +++ b/scripts/.function-lib.sh @@ -0,0 +1,62 @@ +#! /bin/sh + +# Terminal styling codes +reset=$(tput sgr0) +bold=$(tput bold) +underline=$(tput smul) +nounderline=$(tput rmul) +reverse=$(tput rev) +standout=$(tput smso) +nostandout=$(tput rmso) +dim=$(tput dim) + +red=$(tput setaf 1) +green=$(tput setaf 2) +yellow=$(tput setaf 3) +blue=$(tput setaf 4) +magenta=$(tput setaf 5) +cyan=$(tput setaf 6) +white=$(tput setaf 7) + +bgred=$(tput setab 1) +bggreen=$(tput setab 2) +bgyellow=$(tput setab 3) +bgblue=$(tput setab 4) +bgmagenta=$(tput setab 5) +bgcyan=$(tput setab 6) +bgwhite=$(tput setab 7) + +# Set up the stage counter +stage=1 + +# Useful functions +title() { + echo "${bold}${white}${bgmagenta}==================== ${*} ====================${reset}" + # Set the terminal emulator title + printf "\033]0;%s\a" "${*}" +} + +header() { + echo "${bold}${cyan}---------- ${*} ----------${reset}" +} + +stage() { + echo "${bold}${blue}=> ${underline}Stage ${stage}: ${*}${reset}" + stage=$((stage + 1)) +} + +error() { + echo "${bold}${red}Error: ${*}${reset}" >&2 +} + +warning() { + echo "${bold}${yellow}Warning: ${*}${reset}" >&2 +} + +info() { + echo "${cyan}${*}${reset}" +} + +success() { + echo "${bold}${green}${*}${reset}" +} diff --git a/scripts/compile-custom-inkay.sh b/scripts/compile-custom-inkay.sh index 6fabc26..1f57c52 100755 --- a/scripts/compile-custom-inkay.sh +++ b/scripts/compile-custom-inkay.sh @@ -3,20 +3,25 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" if [ ! -f "$git_base/environment/system.local.env" ]; then - echo "Missing environment file system.local.env. Did you run setup-environment.sh?" + error "Missing environment file system.local.env. Did you run setup-environment.sh?" exit 1 fi . "$git_base/environment/system.local.env" if [ -z "${WIIU_IP+x}" ]; then - echo "Missing environment variable WIIU_IP. Did you specify a Wii U IP address when you ran setup-environment.sh?" - echo "Continuing without automatic FTP upload." + warning "Missing environment variable WIIU_IP. Did you specify a Wii U IP address when you ran setup-environment.sh?" + info "Continuing without automatic FTP upload." fi cd "$git_base/repos/Inkay" docker compose up -d mitmproxy-pretendo +while ! docker compose exec mitmproxy-pretendo ls /home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem >/dev/null; do + info "Waiting for mitmproxy to generate a certificate..." + sleep 1 +done # Get the current certificate docker compose cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem ./data/ca.pem @@ -24,10 +29,10 @@ docker compose cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cer # Set up the Inkay build environment and then build the patches docker build . -t inkay-build docker run -it --rm -v .:/app -w /app inkay-build -echo "Inkay patches built successfully at $(pwd)/Inkay-pretendo.wps" +success "Inkay patches built successfully at $(pwd)/Inkay-pretendo.wps" # Upload the new Inkay patches to the Wii U if [ -n "${WIIU_IP+x}" ]; then ftp -u "ftp://user:pass@$WIIU_IP/fs/vol/external01/wiiu/environments/aroma/plugins/Inkay-pretendo.wps" ./Inkay-pretendo.wps - echo "Reboot your Wii U now to apply the new patches." + info "Reboot your Wii U now to apply the new patches." fi diff --git a/scripts/create-juxt-community.sh b/scripts/create-juxt-community.sh index 2f61446..36bc022 100755 --- a/scripts/create-juxt-community.sh +++ b/scripts/create-juxt-community.sh @@ -3,6 +3,7 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" create_community_script=$(cat "$git_base/scripts/run-in-container/create-juxt-community.js") if [ "$#" -lt 3 ]; then diff --git a/scripts/firstrun-minio-container.sh b/scripts/firstrun-minio-container.sh index a05c7da..29c662d 100755 --- a/scripts/firstrun-minio-container.sh +++ b/scripts/firstrun-minio-container.sh @@ -3,10 +3,9 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" minio_init_script=$(cat "$git_base/scripts/run-in-container/minio-init.sh") docker compose up -d minio docker compose exec minio sh -c "$minio_init_script" - -docker compose down diff --git a/scripts/firstrun-mongodb-container.sh b/scripts/firstrun-mongodb-container.sh index d4b3673..c27e055 100755 --- a/scripts/firstrun-mongodb-container.sh +++ b/scripts/firstrun-mongodb-container.sh @@ -3,6 +3,7 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" mongodb_init_script=$(cat "$git_base/scripts/run-in-container/mongodb-init.js") docker compose up -d mongodb @@ -13,10 +14,8 @@ docker compose up -d mongodb # https://github.com/docker-library/mongo/issues/339 while ! docker compose exec mongodb mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do - echo "Waiting for mongodb to be ready..." + info "Waiting for mongodb to be ready..." sleep 2 done docker compose exec mongodb mongosh --eval "$mongodb_init_script" - -docker compose down diff --git a/scripts/make-pnid-dev.sh b/scripts/make-pnid-dev.sh index 3f77a84..3b372b9 100755 --- a/scripts/make-pnid-dev.sh +++ b/scripts/make-pnid-dev.sh @@ -3,12 +3,13 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" update_pnid_access_level_script=$(cat "$git_base/scripts/run-in-container/make-pnid-dev.js") if [ "$#" -lt 1 ]; then echo "Usage: $0 " exit 1 fi -echo "Giving developer access to PNID $1..." +info "Giving developer access to PNID $1..." docker compose exec account node -e "$update_pnid_access_level_script" "$1" diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index f828af9..98dbea1 100755 --- a/scripts/setup-environment.sh +++ b/scripts/setup-environment.sh @@ -23,14 +23,15 @@ if [ "$#" -ge 2 ]; then wiiu_ip=$2 fi -echo "Setting up local environment variables..." - git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" cd "$git_base/environment" +info "Setting up local environment variables..." + firstrun=true if ls ./*.local.env 1>/dev/null 2>&1; then - echo "Local environment files already exist. They will be overwritten if you continue." + warning "Local environment files already exist. They will be overwritten if you continue." printf "Continue? [y/N] " read -r continue if [ "$continue" != "Y" ] && [ "$continue" != "y" ]; then @@ -95,25 +96,29 @@ echo "PN_MIIVERSE_API_CONFIG_AES_KEY=$miiverse_aes_key" >>./miiverse-api.local.e echo "JUXT_CONFIG_AES_KEY=$miiverse_aes_key" >>./juxtaposition-ui.local.env # Set up the server IP address -echo "Using server IP address $server_ip." +info "Using server IP address $server_ip." echo "SERVER_IP=$server_ip" >>./system.local.env echo "PN_FRIENDS_SECURE_SERVER_HOST=$server_ip" >>./friends.local.env echo "PN_WIIU_CHAT_SECURE_SERVER_LOCATION=$server_ip" >>./wiiu-chat.local.env # Get the Wii U IP address if [ -n "$wiiu_ip" ]; then - echo "Using Wii U IP address $wiiu_ip." + info "Using Wii U IP address $wiiu_ip." echo "WIIU_IP=$wiiu_ip" >>./system.local.env else - echo "Skipping Wii U IP address." + info "Skipping Wii U IP address." fi -echo "Successfully set up environment." +success "Successfully set up environment." -# Some things need to be updated with the new environment variables and secrets -if [ "$firstrun" = false ]; then - echo "Running necessary container update scripts..." +# Some things need to be updated with the new environment variables and secrets, +# but only if this isn't the first run and the setup script isn't in progress. +# The MongoDB container replica set won't be configured during initial setup, +# and the scripts will fail. +if [ "$firstrun" = false ] && [ -z "${PRETENDO_SETUP_IN_PROGRESS+x}" ]; then + info "Running necessary container update scripts..." "$git_base"/scripts/update-postgres-password.sh "$git_base"/scripts/update-account-servers-database.sh docker compose down + success "Successfully updated containers with new environment variables." fi diff --git a/scripts/setup-submodule-patches.sh b/scripts/setup-submodule-patches.sh index 1413ec0..f3716ef 100755 --- a/scripts/setup-submodule-patches.sh +++ b/scripts/setup-submodule-patches.sh @@ -2,14 +2,15 @@ set -eu -echo "Resetting all submodules..." +git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" + +info "Resetting all submodules..." git submodule sync --recursive git submodule foreach --recursive "git reset --hard" git submodule update --init --recursive --checkout --force -git_base=$(git rev-parse --show-toplevel) - -echo "Applying patches..." +info "Applying patches to submodules..." num_patches=0 for dir in "$git_base/patches/"*; do if [ -d "$dir" ]; then @@ -25,4 +26,4 @@ for dir in "$git_base/patches/"*; do done fi done -echo "Successfully applied $num_patches patches." +success "Successfully applied $num_patches patches." diff --git a/scripts/update-account-servers-database.sh b/scripts/update-account-servers-database.sh index f6a4b8d..782c18f 100755 --- a/scripts/update-account-servers-database.sh +++ b/scripts/update-account-servers-database.sh @@ -3,10 +3,11 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" create_server_script=$(cat "$git_base/scripts/run-in-container/update-account-servers-database.js") if [ ! -f "$git_base/environment/system.local.env" ]; then - echo "Missing environment file system.local.env. Did you run setup-environment.sh?" + error "Missing environment file system.local.env. Did you run setup-environment.sh?" exit 1 fi . "$git_base/environment/system.local.env" @@ -14,7 +15,7 @@ fi necessary_environment_files="friends miiverse-api wiiu-chat" for environment in $necessary_environment_files; do if [ ! -f "$git_base/environment/$environment.local.env" ]; then - echo "Missing environment file $environment.local.env. Did you run setup-environment.sh?" + error "Missing environment file $environment.local.env. Did you run setup-environment.sh?" exit 1 fi . "$git_base/environment/$environment.env" diff --git a/scripts/update-miiverse-endpoints.sh b/scripts/update-miiverse-endpoints.sh index a37d4ec..98f466d 100755 --- a/scripts/update-miiverse-endpoints.sh +++ b/scripts/update-miiverse-endpoints.sh @@ -3,6 +3,7 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" create_endpoint_script=$(cat "$git_base/scripts/run-in-container/update-miiverse-endpoints.js") docker compose up -d miiverse-api diff --git a/scripts/update-postgres-password.sh b/scripts/update-postgres-password.sh index 943e16f..879bfee 100755 --- a/scripts/update-postgres-password.sh +++ b/scripts/update-postgres-password.sh @@ -3,8 +3,9 @@ set -eu git_base=$(git rev-parse --show-toplevel) +. "$git_base/scripts/.function-lib.sh" if [ ! -f "$git_base/environment/postgres.local.env" ]; then - echo "Missing environment file postgres.local.env. Did you run setup-environment.sh?" + error "Missing environment file postgres.local.env. Did you run setup-environment.sh?" exit 1 fi . "$git_base/environment/postgres.env"