3 #=======================================================================
5 # File ID: b7ee76c4-10c2-11e0-8682-00023faf1383
10 # ©opyleft 2010– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
29 'rsyncnet-remote' => 0,
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = "0.2.0";
39 Getopt
::Long
::Configure
('bundling');
42 'create-remote|c' => \
$Opt{'create-remote'},
43 'debug' => \
$Opt{'debug'},
44 'directory|d=s' => \
$Opt{'directory'},
45 'exthd-remote|e' => \
$Opt{'exthd-remote'},
46 'gitlab-remote|g' => \
$Opt{'gitlab-remote'},
47 'help|h' => \
$Opt{'help'},
48 'quiet|q+' => \
$Opt{'quiet'},
49 'rsyncnet-remote|r' => \
$Opt{'rsyncnet-remote'},
50 'verbose|v+' => \
$Opt{'verbose'},
51 'version' => \
$Opt{'version'},
53 ) || die("$progname: Option error. Use -h for help.\n");
55 $Opt{'verbose'} -= $Opt{'quiet'};
56 $Opt{'help'} && usage
(0);
57 if ($Opt{'version'}) {
68 $Opt{'directory'} =~ /[^a-z0-9\-_\.\/]/ &&
69 die("$progname: $Opt{'directory'}: Invalid characters in --directory argument\n");
71 my $url = 'sunny@sunbase.org';
72 my $rsyncnet_url = $ENV{RN
};
73 my $dir = $Opt{'directory'} ?
"/home/sunny/repos/Git-$Opt{'directory'}" : "/home/sunny/repos/Git";
74 my $exthd_dir = '/media/exthd/alt/repos/Git';
76 defined($ARGV[0]) || die("$progname: No repo name specified, see --help\n");
78 $repo =~ s/(.*)\.git$/$1/i;
79 my $rg = "$dir/$repo.git";
80 $repo =~ /[^a-z0-9\-_\.\/]/ && die("$progname: $repo: Name contains invalid characters\n");
81 chomp(my $hname = `hostname`); # FIXME: Should probably use $HNAME
82 if ($Opt{'create-remote'}) {
83 mysystem
("ssh", $url, "mkdir $rg && git init --bare $rg");
84 mysystem
("git", "remote", "add", "sunbase", "$url:$rg");
86 msg
(1, "'$dir' exists, check for local repo...");
88 msg
(1, "'$rg' doesn't exist, create local repo");
89 mysystem
("git", "init", "--bare", $rg);
91 msg
(1, "$rg: Repo already exists, that's good");
93 mysystem
("git", "remote", "add", $hname, "sunny\@localhost:$rg");
94 chomp(my $origdir = `pwd`);
96 mysystem
("git", "remote", "add", "sunbase", "$url:$rg");
98 warn("$progname: $origdir: Cannot chdir to original directory: $!\n");
100 warn("$progname: $rg: chdir error: $!\n");
103 msg
(1, "'$dir' doesn't exist, skipping check for local repo");
106 if ($Opt{'gitlab-remote'}) {
107 mysystem
("git", "remote", "add", "gitlab", "git\@gitlab.com:sunny256/$repo.git");
109 if ($Opt{'exthd-remote'}) {
110 -d
"$exthd_dir/$repo.git/." || mysystem
("git", "init", "--bare", "$exthd_dir/$repo.git");
111 mysystem
("git", "remote", "add", "exthd", "sunny\@localhost:$exthd_dir/$repo.git");
113 if ($Opt{'rsyncnet-remote'}) {
114 my $repodir = sprintf("repos/Git%s/$repo.git",
115 length($Opt{'directory'}) ?
"-$Opt{'directory'}" : "",
117 mysystem
("git", "remote", "add", "rsync-net", "$rsyncnet_url:$repodir");
118 mysystem
("ssh", $rsyncnet_url, "git", "init", "--bare", "$repodir");
128 msg
(0, "Executing '" . join(" ", @cmd) . "'");
135 # Print program version {{{
136 print("$progname $VERSION\n");
142 # Send the help message to stdout {{{
145 if ($Opt{'verbose'}) {
151 Usage: $progname [options] repo_name
156 Set up the sunbase remote
158 Create a repo inside Git-X/ instead of Git/
160 Create and set up the exthd remote
162 Define the gitlab remote
166 Be more quiet. Can be repeated to increase silence.
167 -r, --rsyncnet-remote
168 Create the rsync-net remote and initialize it.
170 Increase level of verbosity. Can be repeated.
172 Print version information.
180 # Print a status message to stderr based on verbosity level {{{
181 my ($verbose_level, $Txt) = @_;
183 if ($Opt{'verbose'} >= $verbose_level) {
184 print(STDERR
"$progname: $Txt\n");
192 # This program is free software; you can redistribute it and/or modify
193 # it under the terms of the GNU General Public License as published by
194 # the Free Software Foundation; either version 2 of the License, or (at
195 # your option) any later version.
197 # This program is distributed in the hope that it will be useful, but
198 # WITHOUT ANY WARRANTY; without even the implied warranty of
199 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
200 # See the GNU General Public License for more details.
202 # You should have received a copy of the GNU General Public License
203 # along with this program.
204 # If not, see L<http://www.gnu.org/licenses/>.
206 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :