10 config
= configparser
.RawConfigParser()
11 config
.read(os
.path
.dirname(os
.path
.realpath(__file__
)) + "/../conf/config")
13 aur_db_host
= config
.get('database', 'host')
14 aur_db_name
= config
.get('database', 'name')
15 aur_db_user
= config
.get('database', 'user')
16 aur_db_pass
= config
.get('database', 'password')
17 aur_db_socket
= config
.get('database', 'socket')
19 repo_path
= config
.get('serve', 'repo-path')
20 repo_regex
= config
.get('serve', 'repo-regex')
21 git_shell_cmd
= config
.get('serve', 'git-shell-cmd')
22 git_update_cmd
= config
.get('serve', 'git-update-cmd')
23 ssh_cmdline
= config
.get('serve', 'ssh-cmdline')
25 enable_maintenance
= config
.getboolean('options', 'enable-maintenance')
26 maintenance_exc
= config
.get('options', 'maintenance-exceptions').split()
28 def pkgbase_exists(pkgbase
):
29 db
= mysql
.connector
.connect(host
=aur_db_host
, user
=aur_db_user
,
30 passwd
=aur_db_pass
, db
=aur_db_name
,
31 unix_socket
=aur_db_socket
)
34 cur
.execute("SELECT COUNT(*) FROM PackageBases WHERE Name = %s ",
38 return (cur
.fetchone()[0] > 0)
41 db
= mysql
.connector
.connect(host
=aur_db_host
, user
=aur_db_user
,
42 passwd
=aur_db_pass
, db
=aur_db_name
,
43 unix_socket
=aur_db_socket
)
46 cur
.execute("SELECT ID FROM Users WHERE Username = %s ", [user
])
47 userid
= cur
.fetchone()[0]
49 die('{:s}: unknown user: {:s}'.format(action
, user
))
51 cur
.execute("SELECT Name, PackagerUID FROM PackageBases " +
52 "WHERE MaintainerUID = %s ", [userid
])
54 print((' ' if row
[1] else '*') + row
[0])
57 def create_pkgbase(pkgbase
, user
):
58 if not re
.match(repo_regex
, pkgbase
):
59 die('{:s}: invalid repository name: {:s}'.format(action
, pkgbase
))
60 if pkgbase_exists(pkgbase
):
61 die('{:s}: package base already exists: {:s}'.format(action
, pkgbase
))
63 db
= mysql
.connector
.connect(host
=aur_db_host
, user
=aur_db_user
,
64 passwd
=aur_db_pass
, db
=aur_db_name
,
65 unix_socket
=aur_db_socket
)
68 cur
.execute("SELECT ID FROM Users WHERE Username = %s ", [user
])
69 userid
= cur
.fetchone()[0]
71 die('{:s}: unknown user: {:s}'.format(action
, user
))
73 cur
.execute("INSERT INTO PackageBases (Name, SubmittedTS, ModifiedTS, " +
74 "SubmitterUID, MaintainerUID) VALUES (%s, UNIX_TIMESTAMP(), " +
75 "UNIX_TIMESTAMP(), %s, %s)", [pkgbase
, userid
, userid
])
76 pkgbase_id
= cur
.lastrowid
78 cur
.execute("INSERT INTO CommentNotify (PackageBaseID, UserID) " +
79 "VALUES (%s, %s)", [pkgbase_id
, userid
])
84 def check_permissions(pkgbase
, user
):
85 db
= mysql
.connector
.connect(host
=aur_db_host
, user
=aur_db_user
,
86 passwd
=aur_db_pass
, db
=aur_db_name
,
87 unix_socket
=aur_db_socket
, buffered
=True)
90 if os
.environ
.get('AUR_PRIVILEGED', '0') == '1':
93 cur
.execute("SELECT COUNT(*) FROM PackageBases " +
94 "LEFT JOIN PackageComaintainers " +
95 "ON PackageComaintainers.PackageBaseID = PackageBases.ID " +
96 "INNER JOIN Users ON Users.ID = PackageBases.MaintainerUID " +
97 "OR PackageBases.MaintainerUID IS NULL " +
98 "OR Users.ID = PackageComaintainers.UsersID " +
99 "WHERE Name = %s AND Username = %s", [pkgbase
, user
])
100 return cur
.fetchone()[0] > 0
103 sys
.stderr
.write("{:s}\n".format(msg
))
106 def die_with_help(msg
):
107 die(msg
+ "\nTry `{:s} help` for a list of commands.".format(ssh_cmdline
))
109 user
= os
.environ
.get("AUR_USER")
110 cmd
= os
.environ
.get("SSH_ORIGINAL_COMMAND")
112 die_with_help("Interactive shell is disabled.")
113 cmdargv
= shlex
.split(cmd
)
116 if enable_maintenance
:
117 remote_addr
= os
.environ
["SSH_CLIENT"].split(" ")[0]
118 if not remote_addr
in maintenance_exc
:
119 die("The AUR is down due to maintenance. We will be back soon.")
121 if action
== 'git-upload-pack' or action
== 'git-receive-pack':
123 die_with_help("{:s}: missing path".format(action
))
125 path
= cmdargv
[1].rstrip('/')
126 if not path
.startswith('/'):
128 if not path
.endswith('.git'):
131 if not re
.match(repo_regex
, pkgbase
):
132 die('{:s}: invalid repository name: {:s}'.format(action
, pkgbase
))
134 if not pkgbase_exists(pkgbase
):
135 create_pkgbase(pkgbase
, user
)
137 if action
== 'git-receive-pack':
138 if not check_permissions(pkgbase
, user
):
139 die('{:s}: permission denied: {:s}'.format(action
, user
))
141 os
.environ
["AUR_USER"] = user
142 os
.environ
["AUR_PKGBASE"] = pkgbase
143 os
.environ
["GIT_NAMESPACE"] = pkgbase
144 cmd
= action
+ " '" + repo_path
+ "'"
145 os
.execl(git_shell_cmd
, git_shell_cmd
, '-c', cmd
)
146 elif action
== 'list-repos':
148 die_with_help("{:s}: too many arguments".format(action
))
150 elif action
== 'setup-repo':
152 die_with_help("{:s}: missing repository name".format(action
))
154 die_with_help("{:s}: too many arguments".format(action
))
155 create_pkgbase(cmdargv
[1], user
)
156 elif action
== 'restore':
158 die_with_help("{:s}: missing repository name".format(action
))
160 die_with_help("{:s}: too many arguments".format(action
))
163 if not re
.match(repo_regex
, pkgbase
):
164 die('{:s}: invalid repository name: {:s}'.format(action
, pkgbase
))
166 if pkgbase_exists(pkgbase
):
167 die('{:s}: package base exists: {:s}'.format(action
, pkgbase
))
168 create_pkgbase(pkgbase
, user
)
170 os
.environ
["AUR_USER"] = user
171 os
.environ
["AUR_PKGBASE"] = pkgbase
172 os
.execl(git_update_cmd
, git_update_cmd
, 'restore')
173 elif action
== 'help':
175 " help Show this help message and exit.\n" +
176 " list-repos List all your repositories.\n" +
177 " restore <name> Restore a deleted package base.\n" +
178 " setup-repo <name> Create an empty repository.\n" +
179 " git-receive-pack Internal command used with Git.\n" +
180 " git-upload-pack Internal command used with Git.")
182 die_with_help("invalid command: {:s}".format(action
))