summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/addsshkey.pl31
-rwxr-xr-xsrc/adduser.pl55
-rwxr-xr-xsrc/chdesc.pl37
-rwxr-xr-xsrc/chowner.pl37
-rwxr-xr-xsrc/chstate.pl44
-rwxr-xr-xsrc/mvrepo.pl38
-rwxr-xr-xsrc/newrepo.pl76
-rwxr-xr-xsrc/rmrepo.pl36
-rwxr-xr-xsrc/rmuser.pl31
9 files changed, 385 insertions, 0 deletions
diff --git a/src/addsshkey.pl b/src/addsshkey.pl
new file mode 100755
index 0000000..431ce7d
--- /dev/null
+++ b/src/addsshkey.pl
@@ -0,0 +1,31 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 2) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 2 needed "
+ . colored("[user - ssh public key]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ";
+ $sshkey = $sshkey . $ARGV[1];
+ my $home_dir = HOME_DIR . $usr . '/';
+ open(my $fh, '>>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys');
+ print $fh "$sshkey\n";
+ close($fh);
+ print "Added new ssh key for user " . colored($usr, 'bold green') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/adduser.pl b/src/adduser.pl
new file mode 100755
index 0000000..4e0746d
--- /dev/null
+++ b/src/adduser.pl
@@ -0,0 +1,55 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 2) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 2 needed "
+ . colored("[user - ssh public key]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ";
+ $sshkey = $sshkey . $ARGV[1];
+ my $home_dir = HOME_DIR . $usr . '/';
+ system(
+ "adduser << EOF
+" . $usr . "
+
+
+
+
+
+git-shell
+" . HOME_DIR . $usr . "
+
+
+
+yes
+
+yes
+no
+EOF"
+ );
+ my (undef, undef, $uid, $gid) = getpwnam($usr);
+ mkdir $home_dir . '.ssh/', 0700;
+ chown $uid, $gid, $home_dir . '.ssh/';
+ open(my $fh, '>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys');
+ print $fh $sshkey . "\n";
+ close($fh);
+ chown $uid, $gid, $home_dir . '.ssh/authorized_keys';
+ chmod 0600, $home_dir . '.ssh/authorized_keys';
+ print "Created new git user " . colored($usr, 'bold green') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/chdesc.pl b/src/chdesc.pl
new file mode 100755
index 0000000..b0c25b7
--- /dev/null
+++ b/src/chdesc.pl
@@ -0,0 +1,37 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 3) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 3 needed "
+ . colored("[user - reponame - new description]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $desc = $ARGV[2];
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo = $repo . '.git';
+ }
+ $repo = $repo . '/';
+ open(my $desc_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'description');
+ print $desc_fh $desc;
+ close($desc_fh);
+ substr($repo, -1) = "";
+ print "Changed git repository " . colored($repo, 'bold green') . " description for user " . colored($usr, 'bold') . ".\n"
+ . "New description: ". colored($desc, 'bold green') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/chowner.pl b/src/chowner.pl
new file mode 100755
index 0000000..f3b1218
--- /dev/null
+++ b/src/chowner.pl
@@ -0,0 +1,37 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 3) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 3 needed "
+ . colored("[user - reponame - new owner]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $owner = $ARGV[2];
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo = $repo . '.git';
+ }
+ $repo = $repo . '/';
+ open(my $owner_fh, '>:encoding(utf-8)', $home_dir . $repo . 'owner');
+ print $owner_fh $owner;
+ close($owner_fh);
+ substr($repo, -1) = "";
+ print "Changed git repository " . colored($repo, 'bold green') . colored(" owner", 'bold') . " for user " . colored($usr, 'bold green') . ".\n"
+ . "New owner: ". colored($owner, 'bold green') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/chstate.pl b/src/chstate.pl
new file mode 100755
index 0000000..1411e99
--- /dev/null
+++ b/src/chstate.pl
@@ -0,0 +1,44 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 2) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 2 needed "
+ . colored("[user - reponame]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo = $repo . '.git';
+ }
+ my $state;
+ if (-e $home_dir . $repo . '/git-daemon-export-ok') {
+ unlink($home_dir . $repo . '/git-daemon-export-ok');
+ $state = 'private';
+ }
+ else {
+ open(my $fh, '>', $home_dir . $repo . '/git-daemon-export-ok');
+ close($fh);
+ $state = 'public';
+ my (undef, undef, $uid, $gid) = getpwnam($usr);
+ chown $uid, $gid, $home_dir . $repo . '/git-daemon-export-ok';
+ }
+ print "Changed git repository " . colored($repo, 'bold green')
+ . " for user " . colored($usr, 'bold green')
+ . colored(' visibility state', 'bold') . ' to '. colored($state, 'bold green') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/mvrepo.pl b/src/mvrepo.pl
new file mode 100755
index 0000000..968fdbc
--- /dev/null
+++ b/src/mvrepo.pl
@@ -0,0 +1,38 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use File::Copy;
+use Term::ANSIColor;
+
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 3) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 3 needed "
+ . colored("[user - reponame - new name]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $newname = $ARGV[2];
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo .= '.git';
+ }
+ if (substr($newname, -4) ne '.git') {
+ $newname .= '.git';
+ }
+ move($home_dir . $repo, $home_dir . $newname);
+ print "Changed git repository " . colored($repo, 'bold green')
+ . " name to " . colored($newname, 'bold green') . " for user " . colored($usr, 'bold') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/newrepo.pl b/src/newrepo.pl
new file mode 100755
index 0000000..dc8041b
--- /dev/null
+++ b/src/newrepo.pl
@@ -0,0 +1,76 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use File::Find;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 2) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, at least 2 needed "
+ . colored("[user - reponame - (description)]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $desc = "";
+ if ($argc >= 3) {
+ $desc = $ARGV[2];
+ }
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo = $repo . '.git';
+ }
+ $repo = $repo . '/';
+ mkdir $home_dir . $repo, 0755;
+ system(
+ '/usr/local/bin/git',
+ '-C',
+ $home_dir . $repo,
+ 'init',
+ '--bare'
+ );
+ my (undef, undef, $uid, $gid) = getpwnam($usr);
+ find(
+ sub {
+ chown $uid, $gid, $_;
+ },
+ $home_dir . $repo
+ );
+ system(
+ '/usr/bin/touch',
+ $home_dir . $repo . 'git-daemon-export-ok'
+ );
+ chown $uid, $gid, $home_dir . $repo . 'git-daemon-export-ok';
+ open(my $owner_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'owner');
+ print $owner_fh $usr;
+ close($owner_fh);
+ open(my $url_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'url');
+ substr($repo, -1) = "";
+ print $url_fh 'git://gitjoe.xyz/' . $usr . '/' . $repo;
+ close($url_fh);
+ $repo = $repo . '/';
+ open(my $desc_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'description');
+ if ($argc >= 3) {
+ print $desc_fh $desc;
+ }
+ else {
+ print $desc_fh 'No description yet';
+ }
+ close($desc_fh);
+ chown $uid, $gid, $home_dir . $repo . 'description';
+ substr($repo, -1) = "";
+ print "Created git repository " . colored($repo, 'bold green') . " for user " . colored($usr, 'bold') . ".\n";
+ print "Remote url: " . colored($usr . '@gitjoe.xyz:' . $repo, 'bold green') . "\n"
+ . "Public clone url: " . colored('git://gitjoe.xyz/' . $usr . '/' . $repo, 'bold green') . "\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/rmrepo.pl b/src/rmrepo.pl
new file mode 100755
index 0000000..b028bb4
--- /dev/null
+++ b/src/rmrepo.pl
@@ -0,0 +1,36 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+use constant HOME_DIR => '/usr/local/git/';
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 2) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 2 needed "
+ . colored("[user - reponame]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ my $repo = $ARGV[1];
+ my $home_dir = HOME_DIR . $usr . '/';
+ if (substr($repo, -4) ne '.git') {
+ $repo = $repo . '.git';
+ }
+ $repo = $repo . '/';
+ system(
+ '/bin/rm',
+ '-rfv',
+ $home_dir . $repo
+ );
+ print "Deleted git repository " . colored($repo, 'bold yellow') . " for user " . colored($usr, 'bold') . ".\n";
+ exit;
+}
+
+main();
+
+__END__
diff --git a/src/rmuser.pl b/src/rmuser.pl
new file mode 100755
index 0000000..9753950
--- /dev/null
+++ b/src/rmuser.pl
@@ -0,0 +1,31 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Term::ANSIColor;
+
+sub main
+{
+ my $argc = $#ARGV + 1;
+ if ($argc < 1) {
+ print colored("Failed!\n", 'bold red')
+ . "Missing argument, 1 needed "
+ . colored("[user]", 'bold')
+ . "\n";
+ exit 1;
+ }
+ my $usr = $ARGV[0];
+ system(
+ "rmuser << EOF
+" . $usr . "
+y
+y
+EOF"
+ );
+ print "Removed git user " . colored($usr, 'bold yellow') . ".\n";
+ exit;
+}
+
+main();
+
+__END__