Browse code

First strike: list repositories from a gitolite-admin repo

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2090 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on21/12/2011 16:51:49
Showing7 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+sshkey
2
+sshkey.pub
3
+gitolite-admin
0 4
new file mode 100755
... ...
@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+
3
+export GIT_SSH="$(dirname ${0})/ssh-wrapper.sh"
4
+cd "$(dirname ${0})/gitolite-admin"
5
+git "${@}"
0 6
new file mode 100755
... ...
@@ -0,0 +1,30 @@
1
+#!/bin/bash
2
+
3
+if [ -f "sshkey" ] ; then 
4
+  echo 'SSH-Key exists!'
5
+  exit 1
6
+fi
7
+
8
+WORKDIR="$(realpath "$(dirname ${0})")"
9
+
10
+ssh-keygen -t ecdsa -P '' -f "${WORKDIR}/sshkey"
11
+
12
+echo 'Paste the following public key in gitolite-config and allow it to access the gitolite-admin repository!'
13
+echo '----------------------'
14
+cat sshkey.pub
15
+echo '----------------------'
16
+echo -n 'Press ENTER when ready...'
17
+read
18
+
19
+export GIT_SSH="${WORKDIR}/ssh-wrapper.sh"
20
+git clone "git@git.$(hostname -d):gitolite-admin"
21
+
22
+cd "gitolite-admin"
23
+echo 'Probing pull...'
24
+git pull
25
+echo 'Probing push...'
26
+git push
27
+
28
+echo 'Everything set up!'
29
+
30
+
0 31
new file mode 100755
... ...
@@ -0,0 +1,2 @@
1
+#!/bin/bash
2
+/usr/bin/ssh -i "$(dirname ${0})/sshkey" "${@}"
0 3
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+<?php
2
+
3
+include('git.php');
4
+require_role(ROLE_SYSTEMUSER);
5
+
6
+list_repos();
7
+#refresh_gitosis();
8
+
0 9
new file mode 100644
... ...
@@ -0,0 +1,103 @@
1
+<?php
2
+require_role(ROLE_SYSTEMUSER);
3
+
4
+$data_dir = realpath( dirname(__FILE__).'/../data/' );
5
+$config_file = $data_dir.'/gitolite-admin/conf/webinterface.conf';
6
+$config_dir = $data_dir.'/gitolite-admin/conf/webinterface';
7
+$key_dir = $data_dir.'/gitolite-admin/keydir';
8
+DEBUG("gitolite-data_dir: ".$data_dir);
9
+$git_wrapper = $data_dir . '/git-wrapper.sh';
10
+
11
+
12
+function check_env() 
13
+{
14
+  global $git_wrapper, $data_dir, $config_file, $config_dir, $key_dir;
15
+  if (!is_executable($git_wrapper)) {
16
+    system_failure("git_wrapper.sh is not executable: {$git_wrapper}");
17
+  }
18
+  if (! (is_file($data_dir.'/sshkey') && is_file($data_dir.'/sshkey.pub'))) {
19
+    system_failure("SSH-key not found. Please setup the gitolite-module correctly. Run ./data/initialize.sh");
20
+  }
21
+  if (! is_dir($data_dir.'/gitolite-admin')) {
22
+    system_failure("Repository gitolite-admin ot found. Initial checkout must be made manually. Run ./data/initialize.sh");
23
+  }
24
+  if (! is_dir($config_dir)) {
25
+    system_failure("gitolite-admin repository is not prepared.");
26
+  }
27
+  if (! (is_dir($key_dir) && is_writeable($$config_file))) {
28
+    system_failure("Repository gitolite-admin is corrupted or webinterface.conf is not writeable.");
29
+  }
30
+}
31
+
32
+
33
+function git_wrapper($commandline)
34
+{
35
+  global $git_wrapper, $data_dir;
36
+
37
+  $command = $git_wrapper.' '.$commandline;
38
+  $output = array();
39
+  $retval = 0;
40
+  DEBUG($command);
41
+  exec($command, $output, $retval);
42
+  DEBUG($output);
43
+  DEBUG($retval);
44
+  if ($retval > 0) {
45
+    system_failure('Interner Fehler!');
46
+    // FIXME: Hier sollte auf jeden Fall ein Logging angeworfen werden!
47
+  }
48
+}
49
+
50
+function refresh_gitolite() 
51
+{
52
+  check_env();
53
+  git_wrapper('pull');
54
+}
55
+
56
+
57
+function read_config()
58
+{
59
+  global $gitolite_conf;
60
+  $customerno = (int) $_SESSION['customerinfo']['customerno'];
61
+  $groups = array();
62
+
63
+  $data = parse_ini_file($gitolite_conf, TRUE);
64
+  DEBUG($data);
65
+  
66
+}
67
+
68
+
69
+function list_repos() 
70
+{
71
+  global $config_file, $config_dir;
72
+  $username = $_SESSION['userinfo']['username'];
73
+  $userconfig = $config_dir . '/' . $username . '.conf';
74
+  DEBUG("using config file ".$userconfig);
75
+  if (! is_file($userconfig)) {
76
+    DEBUG("user-config does not exist");
77
+    return array();
78
+  }
79
+
80
+  $repos = array();
81
+  $lines = file($userconfig);
82
+  $current_repo = NULL;
83
+  foreach ($lines as $line) {
84
+    $m = array();
85
+    if (preg_match('_^[ \t]*repo ([^]]+)_', $line, $m) != 0) {
86
+      DEBUG("found repo ".$m[1]);
87
+      $repos[] = $m[1];
88
+    }
89
+  }
90
+  DEBUG($repos);
91
+  return $repos;
92
+}
93
+
94
+
95
+
96
+
97
+function add_key($pubkey, $handle)
98
+{
99
+  
100
+}
101
+
102
+
103
+
0 104
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+$role = $_SESSION['role'];
4
+
5
+if ($role & ROLE_SYSTEMUSER) {
6
+  $menu["git_git"] = array("label" => "Git-Zugänge", "file" => "git", "weight" => 1, "submenu" => "systemuser_account");
7
+}
8
+
9
+
10
+?>