Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6. use File::Basename;
  7. my $numArgs = $#ARGV + 1;
  8.  
  9. if($numArgs < 2) {
  10. die "Usage: $0 [Bit Bucket Project e.g. FW, BDPE] [repo name] [-d dry run (optional)]";
  11. }
  12.  
  13. my $bitbucketProject = lc $ARGV[0];
  14. my $repoName = $ARGV[1];
  15. my $dryRun = $ARGV[2];
  16. my %moduleHash;
  17. my $bitBucketServer = "localhost";
  18. my $user = "admin";
  19. my $password = "bitbucket";
  20.  
  21.  
  22. print "Bit Bucket Project: $bitbucketProjectn";
  23. print "Repository name: $repoNamen";
  24.  
  25. sub importRepo {
  26.  
  27. my $command = sprintf("curl -u %s:%s -X POST -H "Content-Type: application/json" -d '{
  28. "name": "%s",
  29. "scmId": "git",
  30. "forkable": true
  31. }' http://%s:7990/rest/api/1.0/projects/%s/repos", $user, $password, $repoName, $bitBucketServer, $bitbucketProject);
  32.  
  33. if ($dryRun) {
  34. print "$commandn";
  35. } else {
  36. print "Doing importn";
  37. system $command;
  38. }
  39. my $bitbucketUrl = sprintf("ssh://git@%s:7999/%s/%s.git", $bitBucketServer, lc $bitbucketProject, $repoName);
  40. my $gitCommand = sprintf("cd %s; pwd; git repack -a -d -f; git push %s --mirror", $repoName, $bitbucketUrl);
  41. if ($dryRun) {
  42. print "$gitCommandn";
  43. } else {
  44. print "Running gitn";
  45. system $gitCommand;
  46. }
  47.  
  48. }
  49.  
  50. importRepo();
  51.  
  52. #!/bin/bash
  53.  
  54. BITBUCKETPROJECT=$1
  55.  
  56. if [ $# -ne 2 ]; then
  57. echo "Usage: $0 [Bit Bucket Project] [Path to repos]"
  58. exit 1;
  59. fi
  60.  
  61. echo "Bit bucket project: $BITBUCKETPROJECT"
  62.  
  63. for f in *; do
  64. if [[ -d $f ]]; then
  65. echo $f
  66. ./importRepository.pl $BITBUCKETPROJECT $f
  67. fi
  68. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement