Add fancy terminal styling to the scripts

This commit is contained in:
Matthew Lopez
2023-12-26 11:53:26 -05:00
parent 0bac0bbc13
commit 8699f07763
11 changed files with 105 additions and 29 deletions

62
scripts/.function-lib.sh Normal file
View File

@@ -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}"
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 <PNID to give developer access>"
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"

View File

@@ -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

View File

@@ -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."

View File

@@ -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"

View File

@@ -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

View File

@@ -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"