From b8baa13b9d277943562cc6eb5f9676c8f1727477 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sat, 18 May 2024 13:12:27 -0500 Subject: [PATCH] pre push commit --- bucket-tool | 73 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/bucket-tool b/bucket-tool index 306c979..a016c10 100644 --- a/bucket-tool +++ b/bucket-tool @@ -1,47 +1,33 @@ #!/usr/bin/ruby -# BEGIN: Pre-Run Check - -if ENV["USER"] != 'root' - puts "This script should only be run by root (permissions issues). Please rerun it as root or prepend \"sudo\"" - exit -end - -# END: Pre-Run Check - - - -# BEGIN: Variables - -$DEBUG=false - -$CONFIG = Hash.new -$CONFIG[:bucket_dir]=` sudo puppet agent --configprint clientbucketdir `.strip() -$CONFIG[:action]="" -$CONFIG[:search_term]="" -$CONFIG[:log_file]="" -File.open('/etc/hostname') do |file| - $HOSTNAME=file.read().strip() -end -FLAG_REGEX=/\-+\S+/ -# END: Variables - - # BEGIN: Helper Functions def usage puts "#{__FILE__} [ACTION ] [] +Description: + This utlity is meant to be used to interact with & manage the filebucket on P4 nodes due to the + utility for that `puppet filebucket -l ` being nonfunctional. + + This implements the same functionality (minus the puppet tie-in) and will allow the user to + search the filebucket and restore from it. + Actions: search : Search for bucket entries matching a portion of the filepath list : List all Bucket entries list-files : List all files/paths that have been backed up to the bucket get : Get the content of a specific entry (by md5) - restore : Restore entry to Global Flags: -d | --debug : Set debug flag + -h | --help : This help message + +Author: + Name: Tristan Ancelet + Email: tristan.ancelet@acumera.com + Phone (Work) #: +1 (337) 965-1855 + " end @@ -79,8 +65,38 @@ end +# BEGIN: Variables + +if not (ARGV & ['-h', '--help']).empty? + usage + exit +end + +if ENV["USER"] != 'root' + puts "This script should only be run by root (permissions issues). Please rerun it as root or prepend \"sudo\"" + exit +end + + +$DEBUG=false + +$CONFIG = Hash.new +$CONFIG[:bucket_dir]=` sudo puppet agent --configprint clientbucketdir `.strip() +$CONFIG[:action]="" +$CONFIG[:search_term]="" +$CONFIG[:log_file]="" +File.open('/etc/hostname') do |file| + $HOSTNAME=file.read().strip() +end +FLAG_REGEX=/\-+\S+/ + +# END: Variables + + + # BEGIN: Handle CLI Args + if ARGV.count == 0 puts "No arguments were provided" usage @@ -90,7 +106,6 @@ end if not (ARGV & ['-d', '--debug']).empty? $DEBUG=true end - i=0 case ARGV[i] when 'search'