#!/usr/bin/env perl # updateConfig # # Script to convert snake_case keys to camelCase in sneakernet.conf.yaml files # Based on the key changes documented in configChanges # # Usage: updateConfig # # The script will: # 1. Create a backup of the original file (with .bak extension) # 2. Convert all snake_case keys to camelCase # 3. Report the changes made # # Author: R. W. Rodolico # Created: January 18, 2026 use strict; use warnings; use File::Copy; use File::Basename; our $VERSION = '1.0.0'; # Map of old snake_case keys to new camelCase keys my %keyMap = ( 'status_file' => 'statusFile', 'log_file' => 'logFile', 'display_logs_tty' => 'displayLogsOnTTY', 'dataset_dir' => 'datasetDir', 'serial_file' => 'serialFile', 'shutdown_after_replication' => 'shutdownAfterReplication', 'mount_point' => 'mountPoint', 'check_interval' => 'checkInterval', 'wait_timeout' => 'waitTimeout', ); # Parse command line arguments my $configFile = shift @ARGV; unless ($configFile) { print STDERR "Usage: $0 \n"; print STDERR " Converts snake_case keys to camelCase in YAML config file\n"; print STDERR " Creates a backup with .bak extension before making changes\n"; exit 1; } # Check if file exists unless (-f $configFile) { die "ERROR: File '$configFile' not found\n"; } # Check if file is readable unless (-r $configFile) { die "ERROR: File '$configFile' is not readable\n"; } # Check if file is writable unless (-w $configFile) { die "ERROR: File '$configFile' is not writable\n"; } print "Processing config file: $configFile\n"; # Create backup my $backupFile = "$configFile.bak"; if (-e $backupFile) { # If backup exists, create timestamped backup my @time = localtime(); my $timestamp = sprintf("%04d%02d%02d_%02d%02d%02d", $time[5] + 1900, $time[4] + 1, $time[3], $time[2], $time[1], $time[0]); $backupFile = "$configFile.bak.$timestamp"; } copy($configFile, $backupFile) or die "ERROR: Failed to create backup '$backupFile': $!\n"; print "Created backup: $backupFile\n"; # Read the file open(my $fh, '<', $configFile) or die "ERROR: Could not open '$configFile' for reading: $!\n"; my @lines = <$fh>; close($fh); # Track changes my %changeCount; my $totalChanges = 0; # Process each line for my $line (@lines) { # Skip comments and empty lines for counting purposes next if $line =~ /^\s*#/ || $line =~ /^\s*$/; # Replace keys - look for YAML key patterns (quoted or unquoted) for my $oldKey (keys %keyMap) { my $newKey = $keyMap{$oldKey}; # Match patterns like: # 'old_key' => # "old_key": # old_key: # 'old_key': if ($line =~ s/(['"]?)$oldKey\1(\s*[=:])/$1$newKey$1$2/g) { $changeCount{$oldKey}++; $totalChanges++; } } } # Write the modified content back open($fh, '>', $configFile) or die "ERROR: Could not open '$configFile' for writing: $!\n"; print $fh @lines; close($fh); # Report results print "\nConversion complete!\n"; print "Total changes made: $totalChanges\n"; if ($totalChanges > 0) { print "\nKeys converted:\n"; for my $oldKey (sort keys %changeCount) { printf(" %-30s -> %-30s (%d occurrence%s)\n", $oldKey, $keyMap{$oldKey}, $changeCount{$oldKey}, $changeCount{$oldKey} == 1 ? '' : 's'); } } else { print "No snake_case keys found - file may already be converted.\n"; } print "\nOriginal file backed up to: $backupFile\n"; exit 0;