My old shell scripts that have been retired from my dotfiles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.7 KiB

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Cwd;
  5. # Make symlinks from your git-project repo into the system. This is only
  6. # designed to work with Media Temple's git-project workflow.
  7. #
  8. # Usage: sudo link-stuff.pl /path/to/git/project
  9. #
  10. # The git-project root should have top-level folders such as `perl-libs`, with
  11. # a path convention like e.g. `perl-libs/$NAME/lib/**/*.pm` -- this script will
  12. # attempt to find system-installed counterparts and symlink them to the file
  13. # from your git repo.
  14. #
  15. # Currently supports the following types of things:
  16. # * perl-libs
  17. my $root = shift;
  18. if (!$root) {
  19. die "Usage: $0 /path/to/git/project\n";
  20. }
  21. if (!-d $root) {
  22. die "Error: $root is not a directory\n";
  23. }
  24. chdir($root);
  25. my $abspath = Cwd::abs_path(".");
  26. if (-d "./perl-libs") {
  27. perl_libs();
  28. }
  29. sub perl_libs {
  30. # Root directories to check.
  31. my @lib = (
  32. "/usr/share/perl5",
  33. "/usr/share/perl5/vendor_perl",
  34. );
  35. # Find all the perl-libs projects.
  36. opendir(my $dh, "./perl-libs");
  37. foreach my $project (readdir($dh)) {
  38. next unless -d "./perl-libs/$project/lib";
  39. print "Project: perl-libs/$project\n";
  40. # Get its modules.
  41. foreach my $module (scan("./perl-libs/$project/lib")) {
  42. $module =~ s{^\./perl-libs/$project/lib/}{}g;
  43. foreach my $lib (@lib) {
  44. if (-f "$lib/$module") {
  45. print " - Link: $lib/$module\n";
  46. unlink("$lib/$module");
  47. symlink("$abspath/perl-libs/$project/lib/$module", "$lib/$module");
  48. }
  49. }
  50. }
  51. }
  52. }
  53. # Recursively scan a directory.
  54. sub scan {
  55. my $dir = shift;
  56. my @found;
  57. opendir (my $dh, $dir);
  58. foreach my $file (readdir($dh)) {
  59. next if ($file eq '.' || $file eq '..');
  60. if (-d "$dir/$file") {
  61. push @found, scan("$dir/$file");
  62. } else {
  63. push @found, "$dir/$file";
  64. }
  65. }
  66. closedir($dh);
  67. return @found;
  68. }