diff --git a/scripts/backup.sh b/scripts/backup.sh index 0e3995c..a9fa118 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -21,14 +21,14 @@ fi mkdir -p "$backup_dir" print_info "Backing up to $backup_dir" -docker compose up -d mitmproxy-pretendo mongodb postgres minio redis +print_info "Starting necessary services..." +compose_no_progress up -d mitmproxy-pretendo mongodb postgres minio redis print_info "Backing up MongoDB..." run_verbose docker compose exec mongodb rm -rf /tmp/backup -# mongodump uses stderr for output -[[ -z "$show_verbose" ]] && mongodump_quiet=true -run_verbose docker compose exec mongodb mongodump -o /tmp/backup "${mongodump_quiet:+--quiet}" -run_verbose_no_errors docker compose cp mongodb:/tmp/backup "$backup_dir/mongodb" +# shellcheck disable=SC2046 +run_verbose docker compose exec mongodb mongodump -o /tmp/backup $(if_not_verbose --quiet) +run_verbose compose_no_progress cp mongodb:/tmp/backup "$backup_dir/mongodb" run_verbose docker compose exec mongodb rm -rf /tmp/backup print_info "Backing up Postgres..." @@ -39,14 +39,14 @@ run_verbose docker compose exec minio mc alias set minio http://minio.pretendo.c run_verbose docker compose exec minio rm -rf /tmp/backup run_verbose docker compose exec minio mkdir -p /tmp/backup run_verbose docker compose exec minio mc mirror minio/ /tmp/backup -run_verbose_no_errors docker compose cp minio:/tmp/backup "$backup_dir/minio" +run_verbose compose_no_progress cp minio:/tmp/backup "$backup_dir/minio" run_verbose docker compose exec minio rm -rf /tmp/backup print_info "Backing up Redis..." run_verbose docker compose exec redis redis-cli save -run_verbose_no_errors docker compose cp redis:/data/dump.rdb "$backup_dir/redis.rdb" +run_verbose compose_no_progress cp redis:/data/dump.rdb "$backup_dir/redis.rdb" print_info "Backing up Mitmproxy..." -run_verbose_no_errors docker compose cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy "$backup_dir/mitmproxy" +run_verbose compose_no_progress cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy "$backup_dir/mitmproxy" print_success "Backup completed successfully." diff --git a/scripts/compile-custom-inkay.sh b/scripts/compile-custom-inkay.sh index 692fcce..f6ec220 100755 --- a/scripts/compile-custom-inkay.sh +++ b/scripts/compile-custom-inkay.sh @@ -16,17 +16,19 @@ fi cd "$git_base_dir/repos/Inkay" if [[ -z "$should_reset" ]]; then - docker compose up -d mitmproxy-pretendo + print_info "Retrieving the mitmproxy CA certificate..." + compose_no_progress up -d mitmproxy-pretendo run_command_until_success "Waiting for mitmproxy to generate a certificate..." 5 \ docker compose exec mitmproxy-pretendo ls /home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem # Get the current certificate - run_verbose_no_errors docker compose cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem ./data/ca.pem + compose_no_progress cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem ./data/ca.pem else + print_info "Resetting the Inkay CA certificate..." git restore ./data/ca.pem - print_info "Reset Inkay CA certificate." fi +print_info "Compiling the Inkay patches..." rm -f ./*.elf ./*.wps # Set up the Inkay build environment and then build the patches @@ -34,10 +36,10 @@ docker build . -t inkay-build docker run -it --rm -v .:/app -w /app inkay-build print_success "Inkay patches built successfully at $(pwd)/Inkay-pretendo.wps" -# Upload the new Inkay patches to the Wii U if [[ -n "${WIIU_IP:-}" ]]; then + print_info "Uploading the new Inkay patches to your Wii U..." tnftp -u "ftp://user:pass@$WIIU_IP/fs/vol/external01/wiiu/environments/aroma/plugins/Inkay-pretendo.wps" ./Inkay-pretendo.wps - print_info "Reboot your Wii U now to apply the new patches." + print_success "Successfully uploaded the new Inkay patches. Reboot your Wii U now to apply them." else print_warning "The modified patches were not uploaded to your Wii U because you did not set an IP address." fi diff --git a/scripts/create-juxt-community.sh b/scripts/create-juxt-community.sh index 521fa87..7a94a55 100755 --- a/scripts/create-juxt-community.sh +++ b/scripts/create-juxt-community.sh @@ -11,18 +11,22 @@ add_option_with_value "-i --icon-path" "icon_path" "image-path" "Path to an icon add_option_with_value "-b --banner-path" "banner_path" "image-path" "Path to a banner image for the community" false parse_arguments "$@" +print_info "Creating new community $name..." + create_community_script=$(cat "$git_base_dir/scripts/run-in-container/create-juxt-community.js") # Clean up title IDs by removing non-alphanumeric characters, but keep commas title_ids=$(echo "$title_ids" | tr -dc "a-zA-Z0-9,") -docker compose up -d juxtaposition-ui +compose_no_progress up -d juxtaposition-ui if [[ -n "$icon_path" ]]; then - run_verbose_no_errors docker compose cp "$icon_path" juxtaposition-ui:/tmp/icon + compose_no_progress cp "$icon_path" juxtaposition-ui:/tmp/icon fi if [[ -n "$banner_path" ]]; then - run_verbose_no_errors docker compose cp "$banner_path" juxtaposition-ui:/tmp/banner + compose_no_progress cp "$banner_path" juxtaposition-ui:/tmp/banner fi -docker compose exec juxtaposition-ui node -e "$create_community_script" "$name" "$description" "$title_ids" "${icon_path:+/tmp/icon}" "${banner_path:+/tmp/banner}" +run_verbose docker compose exec juxtaposition-ui node -e "$create_community_script" "$name" "$description" "$title_ids" "${icon_path:+/tmp/icon}" "${banner_path:+/tmp/banner}" + +print_success "Successfully created community $name." diff --git a/scripts/internal/firstrun-minio-container.sh b/scripts/internal/firstrun-minio-container.sh index df714f2..e5ce887 100755 --- a/scripts/internal/firstrun-minio-container.sh +++ b/scripts/internal/firstrun-minio-container.sh @@ -4,13 +4,15 @@ source "$(dirname "$(realpath "$0")")/framework.sh" parse_arguments "$@" -load_dotenv minio.env minio.local.env +print_info "Setting up the MinIO container..." +load_dotenv minio.env minio.local.env minio_init_script=$(cat "$git_base_dir/scripts/run-in-container/minio-init.sh") -docker compose up -d minio - +compose_no_progress up -d minio run_command_until_success "Waiting for MinIO to be ready..." 5 \ docker compose exec minio mc alias set minio http://minio.pretendo.cc "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" -docker compose exec minio sh -c "$minio_init_script" +run_verbose docker compose exec minio sh -c "$minio_init_script" + +print_success "MinIO container is set up." diff --git a/scripts/internal/firstrun-mongodb-container.sh b/scripts/internal/firstrun-mongodb-container.sh index b63c40f..a5899c8 100755 --- a/scripts/internal/firstrun-mongodb-container.sh +++ b/scripts/internal/firstrun-mongodb-container.sh @@ -4,9 +4,11 @@ source "$(dirname "$(realpath "$0")")/framework.sh" parse_arguments "$@" +print_info "Setting up MongoDB container..." + mongodb_init_script=$(cat "$git_base_dir/scripts/run-in-container/mongodb-init.js") -docker compose up -d mongodb +compose_no_progress up -d mongodb # This won't work in /docker-entrypoint-initdb.d/ because MongoDB is in a special init state where it will refuse to # resolve anything but localhost. This needs to be run after it initializes. @@ -15,4 +17,6 @@ docker compose up -d mongodb run_command_until_success "Waiting for MongoDB to be ready..." 10 \ docker compose exec mongodb mongosh --eval "db.adminCommand('ping')" -docker compose exec mongodb mongosh --eval "$mongodb_init_script" +run_verbose docker compose exec mongodb mongosh --eval "$mongodb_init_script" + +print_success "MongoDB container is set up." diff --git a/scripts/internal/framework.sh b/scripts/internal/framework.sh index 7158137..e9e7984 100644 --- a/scripts/internal/framework.sh +++ b/scripts/internal/framework.sh @@ -101,6 +101,12 @@ run_verbose_no_errors() { fi } +# Run a Docker Compose command without showing progress unless the verbose option is set +compose_no_progress() { + # shellcheck disable=SC2046 + docker compose $(if_not_verbose --progress quiet) "$@" +} + # Run a command every 2 seconds silently until it succeeds, or show output if the max number of retries is reached. # # Usage: run_command_until_success wait_text max_attempts command... @@ -147,6 +153,26 @@ load_dotenv() { done } +# Output the provided text if the verbose option is set. +# +# Usage: if_verbose text... +# Example: command $(if_verbose --verbose) +if_verbose() { + if [[ -n "$show_verbose" ]]; then + echo "$*" + fi +} + +# Output the provided text unless the verbose option is set. +# +# Usage: if_not_verbose text... +# Example: command $(if_not_verbose --quiet) +if_not_verbose() { + if [[ -z "$show_verbose" ]]; then + echo "$*" + fi +} + # Argument parsing framework # Uses a lot of Bash parameter expansion tricks: https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion argument_variables=() diff --git a/scripts/internal/update-account-servers-database.sh b/scripts/internal/update-account-servers-database.sh index 4b2f36b..186c2e5 100755 --- a/scripts/internal/update-account-servers-database.sh +++ b/scripts/internal/update-account-servers-database.sh @@ -4,21 +4,23 @@ source "$(dirname "$(realpath "$0")")/framework.sh" parse_arguments "$@" -create_server_script=$(cat "$git_base_dir/scripts/run-in-container/update-account-servers-database.js") +print_info "Setting up Pretendo account servers database..." load_dotenv .env - dotenv_files=("friends" "miiverse-api" "wiiu-chat" "super-mario-maker") for file in "${dotenv_files[@]}"; do load_dotenv "$file.env" "$file.local.env" done +create_server_script=$(cat "$git_base_dir/scripts/run-in-container/update-account-servers-database.js") -docker compose up -d account +compose_no_progress up -d account -docker compose exec -e SERVER_IP="$SERVER_IP" \ +run_verbose docker compose exec -e SERVER_IP="$SERVER_IP" \ -e FRIENDS_PORT="$PN_FRIENDS_AUTHENTICATION_SERVER_PORT" \ -e FRIENDS_AES_KEY="$PN_FRIENDS_CONFIG_AES_KEY" \ -e MIIVERSE_AES_KEY="$PN_MIIVERSE_API_CONFIG_AES_KEY" \ -e WIIU_CHAT_PORT="$PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT" \ -e SMM_PORT="$PN_SMM_AUTHENTICATION_SERVER_PORT" \ account node -e "$create_server_script" + +print_success "Account servers database is set up." diff --git a/scripts/internal/update-miiverse-endpoints.sh b/scripts/internal/update-miiverse-endpoints.sh index af5e93c..32ac0fd 100755 --- a/scripts/internal/update-miiverse-endpoints.sh +++ b/scripts/internal/update-miiverse-endpoints.sh @@ -4,8 +4,12 @@ source "$(dirname "$(realpath "$0")")/framework.sh" parse_arguments "$@" +print_info "Setting up Pretendo Miiverse endpoints database..." + create_endpoint_script=$(cat "$git_base_dir/scripts/run-in-container/update-miiverse-endpoints.js") -docker compose up -d miiverse-api +compose_no_progress up -d miiverse-api + +run_verbose docker compose exec miiverse-api node -e "$create_endpoint_script" -docker compose exec miiverse-api node -e "$create_endpoint_script" +print_success "Miiverse endpoints database is set up." diff --git a/scripts/internal/update-postgres-password.sh b/scripts/internal/update-postgres-password.sh index 2edb143..911327f 100755 --- a/scripts/internal/update-postgres-password.sh +++ b/scripts/internal/update-postgres-password.sh @@ -4,9 +4,11 @@ source "$(dirname "$(realpath "$0")")/framework.sh" parse_arguments "$@" +print_info "Updating Postgres password..." + load_dotenv postgres.env postgres.local.env -docker compose up -d postgres +compose_no_progress up -d postgres run_command_until_success "Waiting for Postgres to be ready..." 5 \ docker compose exec postgres psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -l @@ -15,3 +17,5 @@ run_command_until_success "Waiting for Postgres to be ready..." 5 \ # scripts run_command_until_success "Failed to change Postgres password, retrying..." 5 \ docker compose exec postgres psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -c "ALTER USER $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD';" + +print_success "Postgres password updated." diff --git a/scripts/make-pnid-dev.sh b/scripts/make-pnid-dev.sh index 2c9b256..f20e378 100755 --- a/scripts/make-pnid-dev.sh +++ b/scripts/make-pnid-dev.sh @@ -8,6 +8,10 @@ should have administrative permissions." add_positional_argument "dev-pnid" "dev_pnid" "The PNID to give developer access" true parse_arguments "$@" +print_info "Giving $dev_pnid developer access..." + update_pnid_access_level_script=$(cat "$git_base_dir/scripts/run-in-container/make-pnid-dev.js") -docker compose exec account node -e "$update_pnid_access_level_script" "$dev_pnid" +run_verbose docker compose exec account node -e "$update_pnid_access_level_script" "$dev_pnid" + +print_success "Successfully set $dev_pnid's access level to developer." diff --git a/scripts/restore.sh b/scripts/restore.sh index dc87e0e..85ce08d 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -29,15 +29,15 @@ if [[ -z "$force" ]]; then fi print_info "Stopping unnecessary services..." -docker compose down -docker compose up -d mitmproxy-pretendo mongodb postgres minio redis +compose_no_progress down +print_info "Starting necessary services..." +compose_no_progress up -d mitmproxy-pretendo mongodb postgres minio redis print_info "Restoring MongoDB..." run_verbose docker compose exec mongodb rm -rf /tmp/backup -run_verbose_no_errors docker compose cp "$backup_dir/mongodb" mongodb:/tmp/backup -# mongodump uses stderr for output -[[ -z "$show_verbose" ]] && mongodump_quiet=true -run_verbose docker compose exec mongodb mongorestore /tmp/backup --drop "${mongodump_quiet:+--quiet}" +run_verbose compose_no_progress cp "$backup_dir/mongodb" mongodb:/tmp/backup +# shellcheck disable=SC2046 +run_verbose docker compose exec mongodb mongorestore /tmp/backup --drop $(if_not_verbose --quiet) run_verbose docker compose exec mongodb rm -rf /tmp/backup print_info "Restoring Postgres..." @@ -47,19 +47,19 @@ run_verbose_no_errors docker compose exec -T postgres psql -U "$POSTGRES_USER" - print_info "Restoring MinIO..." run_verbose docker compose exec minio mc alias set minio http://minio.pretendo.cc "$MINIO_ROOT_USER" "$MINIO_ROOT_PASSWORD" run_verbose docker compose exec minio rm -rf /tmp/backup -run_verbose_no_errors docker compose cp "$backup_dir/minio" minio:/tmp/backup +run_verbose compose_no_progress cp "$backup_dir/minio" minio:/tmp/backup run_verbose docker compose exec minio mc mirror /tmp/backup minio/ --overwrite --remove run_verbose docker compose exec minio rm -rf /tmp/backup print_info "Restoring Redis..." # Redis cannot be running when restoring a dump or it will overwrite the restored dump when it exits -run_verbose_no_errors docker compose stop redis -run_verbose_no_errors docker compose cp "$backup_dir/redis.rdb" redis:/data/dump.rdb +run_verbose compose_no_progress stop redis +run_verbose compose_no_progress cp "$backup_dir/redis.rdb" redis:/data/dump.rdb print_info "Restoring Mitmproxy..." # Mitmproxy cannot be running when restoring a backup or it will continue using its new certificate -run_verbose_no_errors docker compose stop mitmproxy-pretendo -run_verbose_no_errors docker compose cp "$backup_dir/mitmproxy" mitmproxy-pretendo:/home/mitmproxy/.mitmproxy +run_verbose compose_no_progress stop mitmproxy-pretendo +run_verbose compose_no_progress cp "$backup_dir/mitmproxy" mitmproxy-pretendo:/home/mitmproxy/.mitmproxy # The restored backup might be using different secrets than what are currently in the .env files "$git_base_dir/scripts/setup-environment.sh" --force diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index 2390daa..21aa3d7 100755 --- a/scripts/setup-environment.sh +++ b/scripts/setup-environment.sh @@ -24,8 +24,6 @@ generate_hex() { cd "$git_base_dir/environment" -print_info "Setting up local environment variables..." - if [[ -z "$no_environment" ]]; then if [[ -f "$git_base_dir/.env" ]]; then source $git_base_dir/.env @@ -52,11 +50,14 @@ if ls ./*.local.env >/dev/null 2>&1; then fi fi - docker compose down + print_info "Stopping containers and removing existing local environment files..." + compose_no_progress down rm ./*.local.env rm "$git_base_dir/.env" fi +print_info "Setting up local environment variables..." + # Generate an AES-256-CBC key for account server tokens account_aes_key=$(generate_hex 64) echo "PN_ACT_CONFIG_AES_KEY=$account_aes_key" >>./account.local.env @@ -123,7 +124,7 @@ boss_api_key=$(generate_password 32) echo "PN_BOSS_CONFIG_GRPC_BOSS_SERVER_API_KEY=$boss_api_key" >>./boss.local.env # Set up the server IP address -print_info "Using server IP address $server_ip." +if_verbose print_info "Using server IP address $server_ip." echo "SERVER_IP=$server_ip" >>"$git_base_dir/.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 @@ -131,7 +132,7 @@ echo "PN_SMM_SECURE_SERVER_HOST=$server_ip" >>./super-mario-maker.local.env # Get the Wii U IP address if [[ -n "$wiiu_ip" ]]; then - print_info "Using Wii U IP address $wiiu_ip." + if_verbose print_info "Using Wii U IP address $wiiu_ip." echo "WIIU_IP=$wiiu_ip" >>"$git_base_dir/.env" else print_info "Skipping Wii U IP address." @@ -139,7 +140,7 @@ fi # Get the 3DS IP address if [[ -n "$ds_ip" ]]; then - print_info "Using 3DS IP address $ds_ip." + if_verbose print_info "Using 3DS IP address $ds_ip." echo "DS_IP=$ds_ip" >>"$git_base_dir/.env" else print_info "Skipping 3DS IP address." @@ -162,7 +163,7 @@ Wii U IP address: ${wiiu_ip:-(not set)} 3DS IP address: ${ds_ip:-(not set)} EOF -print_success "Successfully set up environment." +print_success "Successfully set up the environment." # Some things need to be updated with the new environment variables and secrets, # but only if the setup script isn't in progress. The MongoDB container replica @@ -171,6 +172,5 @@ if [[ -z "${PRETENDO_SETUP_IN_PROGRESS:-}" ]]; then print_info "Running necessary container update scripts..." "$git_base_dir/scripts/internal/update-postgres-password.sh" "$git_base_dir/scripts/internal/update-account-servers-database.sh" - docker compose down print_success "Successfully updated the containers with new environment variables." fi diff --git a/scripts/setup-submodule-patches.sh b/scripts/setup-submodule-patches.sh index 1043b75..94c351f 100755 --- a/scripts/setup-submodule-patches.sh +++ b/scripts/setup-submodule-patches.sh @@ -41,7 +41,7 @@ for dir in "$git_base_dir/patches/"*; do error_count=$((error_count + 1)) fi else - run_verbose echo "Applying patch $patch" + if_verbose "Applying patch $patch" git apply "$patch" fi patch_count=$((patch_count + 1)) diff --git a/scripts/upload-3ds-files.sh b/scripts/upload-3ds-files.sh index 2c5d39c..9a9ede5 100755 --- a/scripts/upload-3ds-files.sh +++ b/scripts/upload-3ds-files.sh @@ -15,19 +15,20 @@ fi cd "$git_base_dir/console-files" if [[ -z "$should_reset" ]]; then - docker compose up -d mitmproxy-pretendo - - run_command_until_success "docker compose exec mitmproxy-pretendo ls /home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem" \ - "Waiting for mitmproxy to generate a certificate..." 4 + print_info "Retrieving the mitmproxy CA certificate..." + compose_no_progress up -d mitmproxy-pretendo + run_command_until_success "Waiting for mitmproxy to generate a certificate..." 5 \ + docker compose exec mitmproxy-pretendo ls /home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem # Get the current certificate - docker compose cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem ./mitmproxy-ca-cert.pem + compose_no_progress cp mitmproxy-pretendo:/home/mitmproxy/.mitmproxy/mitmproxy-ca-cert.pem ./mitmproxy-ca-cert.pem else - print_info "Reset the Juxt certificate." + print_info "Resetting the Juxt certificate..." fi # Upload the required files if [[ -n "${DS_IP:-}" ]]; then + print_info "Uploading the required files to your 3DS..." if [[ -z "$should_reset" ]]; then tnftp -u "ftp://user:pass@$DS_IP:5000/3ds/juxt-prod.pem" ./mitmproxy-ca-cert.pem tnftp -u "ftp://user:pass@$DS_IP:5000/gm9/scripts/FriendsAccountSwitcher.gm9" ./FriendsAccountSwitcher.gm9 @@ -35,7 +36,7 @@ if [[ -n "${DS_IP:-}" ]]; then else tnftp -u "ftp://user:pass@$DS_IP:5000/3ds/juxt-prod.pem" ./juxt-prod.pem fi - print_success "Successfully uploaded the required files to your 3DS." + print_success "Successfully uploaded the required files." else print_warning "The required files were not uploaded to your 3DS because you did not set an IP address." fi diff --git a/setup.sh b/setup.sh index b91c223..04a0eb1 100755 --- a/setup.sh +++ b/setup.sh @@ -56,18 +56,13 @@ setup_environment_variables() { } setup_containers() { - print_info "Setting up MongoDB container..." ./scripts/internal/firstrun-mongodb-container.sh - print_info "Setting up MinIO container..." ./scripts/internal/firstrun-minio-container.sh - print_info "Setting up Pretendo account servers database..." ./scripts/internal/update-account-servers-database.sh - print_info "Setting up Pretendo Miiverse endpoints database..." ./scripts/internal/update-miiverse-endpoints.sh - print_info "Updating Postgres password..." ./scripts/internal/update-postgres-password.sh print_info "Stopping containers after initial setup..." - docker compose down + compose_no_progress down } export PRETENDO_SETUP_IN_PROGRESS=true