module Astrovan module Util # Create one or more directories on the remote servers. Intermediate directories will be created # as required. def mkdir(*paths) options = paths.last.is_a?(Hash) ? paths.pop : {} # flatten, so that arrays of paths can be passed as arguments paths = paths.flatten.join(' ') # TODO: consider using sudo? exec "mkdir -p #{paths} && chmod g+w #{paths}", options end # Remove files or directories on the remote servers. # # Options: # * +recursive+ - set to true to attempt to recursively remove a directory def rm(*paths) options = paths.last.is_a?(Hash) ? paths.pop : {} # flatten, so that arrays of paths can be passed as arguments paths = paths.flatten.join(' ') # TODO: consider using sudo? rm = 'rm' rm << ' -r' if options.delete(:recursive) exec "#{rm} #{paths}", options end # Create a sylink on the remote servers. Any existing symlink will be removed first. # # Options: # * +to+ - the path to the new symlink def symlink(*paths) options = paths.last.is_a?(Hash) ? paths.pop : {} raise ArgumentError, "You must provide a target using the :to option" unless to = options.delete(:to) # flatten, so that arrays of paths can be passed as arguments paths = paths.flatten.join(' ') # TODO: consider using sudo? exec "ln -sf #{path} #{to}", options end end end