def symlink_dir(from, to) run "test -L #{to} || ( #{sudo} find #{to} -mindepth 1 -print | xargs -i mv {} #{from} && #{sudo} rm -rf #{to} && #{sudo} ln -s #{from} #{to} )" end def delete_files_from_dir1_which_exist_in_dir2(delete_from_dir, exist_in_dir) run "find #{exist_in_dir} -type f | xargs -n1 basename | xargs -I{} bash -c 'test -f #{delete_from_dir}/{} && rm -v #{delete_from_dir}/{} || echo no file #{delete_from_dir}/{} to delete'" end def symlink_files_in_dir(from_dir,to_dir) delete_files_from_dir1_which_exist_in_dir2(to_dir, from_dir) run "(#{sudo} test -d #{from_dir} && ( find #{from_dir}/ -mindepth 1 -print | xargs --verbose #{sudo} ln -s -f -t #{to_dir} ) ) || echo 'nothing to link'" end # # Symlinks the files in from_dir matching the regex into the to_dir # def symlink_files_in_dir_by_regex(from_dir,to_dir,regex) delete_files_from_dir1_which_exist_in_dir2(to_dir, from_dir) run "(#{sudo} test -d #{from_dir} && ( find #{from_dir}/ -mindepth 1 -regex '#{regex}' -print | xargs --verbose #{sudo} ln -s -f -t #{to_dir} ) ) || echo 'nothing to link'" end def mkdir_unless_exists( dir ) run "test -d #{dir} || #{sudo} mkdir -p #{dir}" end def symlink_dir(from, to) run "test -L #{to} || ( #{sudo} find #{to} -mindepth 1 -print | xargs -i mv {} #{from} && #{sudo} rm -rf #{to} && #{sudo} ln -s #{from} #{to} )" end def mkdir_unless_exists( dir ) run "test -d #{dir} || #{sudo} mkdir -p #{dir}" end def remove_file_if_exists( file ) run "(test -f #{file} && #{sudo} rm #{file}) || echo 'no existing #{file} file to remove'" end def remove_dir_if_exists( dir ) run "(test -d #{dir} && #{sudo} rm -rf #{dir}) || echo 'no existing #{dir} dir to remove'" end def set_permissions_on_dir( opts ) if opts[:ownership] run "(test -d #{opts[:dir]} && #{sudo} chown #{opts[:ownership]} ) || echo couldnt find #{opts[:dir]}" end if opts[:permissions] run "(test -d #{opts[:dir]} && #{sudo} chmod #{opts[:permissions]} ) || echo couldnt find #{opts[:dir]}" end end def set_permissions_on_files_in_dir( opts ) if opts[:ownership] run "(test -d #{opts[:dir]} && find #{opts[:dir]} -mindepth 1 | xargs #{sudo} chown #{opts[:ownership]} ) || echo couldnt find #{opts[:dir]}" end if opts[:permissions] run "(test -d #{opts[:dir]} && find #{opts[:dir]} -mindepth 1 | xargs #{sudo} chmod #{opts[:permissions]} ) || echo couldnt find #{opts[:dir]}" end end