#!/usr/bin/env perl # Copyright (c) 2026, rodolico # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # helloWorld - Simple test script demonstrating cleanup script return format # # PURPOSE: # Demonstrates the proper format for cleanup scripts to return results and # error messages to sneakernet. This is a template/example script showing # how to structure output for integration with the sneakernet cleanup phase. # # USAGE: # Standalone: ./helloWorld # From sneakernet: Executed automatically during cleanup phase # From Perl script: my ($results, $errors) = eval { do './helloWorld' }; # # EXECUTION CONTEXT: # When executed by sneakernet: # - Script is read from transport drive, decrypted, and executed via eval() # - Progress messages sent to STDERR for real-time monitoring # - Results and errors returned via return statement for logging # - When run standalone, prints results and errors to STDOUT # # BEHAVIOR: # 1. Adds 'hello' to the results array # 2. Adds 'world' to the results array # 3. Adds a test error message to the error array # 4. Returns formatted results and errors # # OUTPUT FORMAT: # Returns: ($resultsString, $errorsString) # - Results: "hello\nworld\n" # - Errors: "This is a test error message" # # Author: rodolico # Version: 1.0 # Updated: 2026-01-22 use strict; use warnings; use 5.010; my @result; my @errorMessages = (); # if we are being called from sneakernet, get verbosity level, otherwise just set to 5 my $caller = caller(); # Check if called from another script and, if not, prints updates to STDOUT my $verbosityLevel = ($caller && defined $ZFS_Utils::verboseLoggingLevel) ? $ZFS_Utils::verboseLoggingLevel : 5; # Add messages to result array push @result, "hello"; push @result, "world" if $verbosityLevel >= 2; # Add test error message push @errorMessages, "This is a test error message"; # Optional: send progress to STDERR for real-time monitoring print STDERR "helloWorld: Generating test output...\n"; # When run standalone, print to STDOUT if ($caller) { # Called from another script (sneakernet) - return formatted results return ( join( "\n", @result ) . "\n", @errorMessages ? join("\n", @errorMessages) : "" ); } else { # Standalone execution - print results print "Results:\n"; print join( "\n", @result ) . "\n"; if (@errorMessages) { print "\n=== CLEANUP SCRIPT ERRORS ===\n"; print join("\n", @errorMessages) . "\n"; } } # End of script