pre push commit

This commit is contained in:
Tristan Ancelet 2024-05-18 13:12:27 -05:00
parent fd2e1a8352
commit b8baa13b9d

View File

@ -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 <arg>] [<flags>]
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 <action>` 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 <term> : 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 <entry-md5> : Get the content of a specific entry (by md5)
restore <entry-md5> : 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'