class RBT::ReplaceSymlinks
Constants
- ARRAY_ALLOWED_DIRS
#¶ ↑
ARRAY_ALLOWED_DIRS
¶ ↑ARRAY_ALLOWED_DIRS
specifies from which directories to run this script.We only allow it from specific directories such as /usr/bin and others.
#¶ ↑
- REMOVE_INSTEAD_OF_SYMLINKING
#¶ ↑
REMOVE_INSTEAD_OF_SYMLINKING
¶ ↑Set this to true if you want to remove rather than symlink.
It may be better to just symlink, rather than remove anyway, hence why this constant is usually kept at false.
#¶ ↑
Public Class Methods
new( this_dir = return_pwd, remove_instead_of_symlinking = REMOVE_INSTEAD_OF_SYMLINKING, run_already = true )
click to toggle source
#¶ ↑
initialize¶ ↑
“this_dir” is the allowed dir, our target.
#¶ ↑
# File lib/rbt/utility_scripts/replace_symlinks.rb, line 48 def initialize( this_dir = return_pwd, remove_instead_of_symlinking = REMOVE_INSTEAD_OF_SYMLINKING, run_already = true ) reset set_this_dir(this_dir) set_remove_symlink( remove_instead_of_symlinking ) run if run_already end
Public Instance Methods
allowed_dirs?()
click to toggle source
append_this_directory_to_the_allowed_directories(i)
click to toggle source
collect_files()
click to toggle source
feedback_allowed_directories()
click to toggle source
is_allowed_dir?(d)
click to toggle source
replace_files()
click to toggle source
#¶ ↑
replace_files
¶ ↑
Normally this is used to symlink, but we can also remove.
#¶ ↑
# File lib/rbt/utility_scripts/replace_symlinks.rb, line 176 def replace_files @array_files.each { |file| target_file = sysbin_directory?+File.basename(file) if File.exist? target_file if @remove_symlink opne "#{rev}Removing #{sfile(file)}#{rev}." else opne "#{rev}Replacing '{sfile(file)}"\ "#{rev} with #{sfile(target_file)}#{rev}." # Wanna remove /bin/unlink. end if @simulate_only else remove(file) # Need to remove the old file. symlink(file, target_file) if @remove_symlink == false end end } end
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/replace_symlinks.rb, line 64 def reset super() infer_the_namespace # ======================================================================= # # === :debug # ======================================================================= # disable_debug # ======================================================================= # # === @simulate_only # ======================================================================= # @simulate_only = true # ======================================================================= # # === @array_allowed_dirs # ======================================================================= # @array_allowed_dirs = ARRAY_ALLOWED_DIRS end
run()
click to toggle source
set_remove_symlink(i)
click to toggle source
set_this_dir(i)
click to toggle source
#¶ ↑
set_this_dir
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/replace_symlinks.rb, line 84 def set_this_dir(i) i = i.first if i.is_a? Array i = return_pwd if i.nil? case i # case tag # ======================================================================= # # === replace_symlinks --help # ======================================================================= # when /-?-?help$/i show_help exit # ======================================================================= # # === replace_symlinks --directory=/opt # ======================================================================= # when /--directory=(.+)/ # This is allowed to bypass the allowed directory. i = $1.to_s.dup append_this_directory_to_the_allowed_directories(i) end unless is_allowed_dir? i # Verify that the directory is proper. Report otherwise. e 'Not allowed directory: '+sdir(i) feedback_allowed_directories e 'Consider changing or using one of the directories listed above.' e 'Hint: You can do so via --directory=' raise NotAllowedDirectory, 'not allowed directory' end i << '/' unless i.end_with? '/' @this_dir = i end
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/replace_symlinks.rb, line 147 def show_help opn(:no_colon) e e e 'This class can either replace or remove symlinks.' e 'In order to use this, navigate to the target directory '\ 'in question' e 'so that it becomes the current working directory (cwd / pwd).' e e 'Alternatively, you can use the option --directory= to assign' e 'to a specific directory.' e end