Commit | Line | Data |
40056462 |
1 | package Oyster::Deploy::Git; |
73e49568 |
2 | use strict; |
3 | use warnings; |
40056462 |
4 | |
40056462 |
5 | use Git::Wrapper; |
40056462 |
6 | |
73e49568 |
7 | our $post_receive = q{ |
8 | #!/bin/sh |
9 | cd .. |
10 | env -i git reset --hard HEAD |
11 | dzil listdeps | xargs cpanm --local-lib=~/perl5 |
12 | }; |
13 | |
14 | our $post_update = q{ |
15 | #!/bin/sh |
16 | # This rather relies on being an account with permission to do this. |
17 | # Who does the script run as? Presumably the owner of the repo as git will |
18 | # use ssh-keys to get onto the server. |
19 | # |
20 | # Realistically that user needs to be put in /etc/sudoers |
21 | # |
22 | # user ALL=NOPASSWD: /etc/init.d/lighttpd |
23 | # |
24 | # Restart server |
25 | sudo /etc/init.d/lighttpd restart |
26 | }; |
40056462 |
27 | |
28 | sub create { |
29 | my $self = shift; |
30 | my $location = shift; |
c0ce95cc |
31 | |
40056462 |
32 | if( -f $location || -d $location ) { |
73e49568 |
33 | die("$location already exists"); |
40056462 |
34 | } |
c0ce95cc |
35 | |
40056462 |
36 | mkdir($location); |
37 | my $git = Git::Wrapper->new($location); |
6b832bd6 |
38 | $git->init(); |
c0ce95cc |
39 | |
73e49568 |
40 | open my $fh_post_receive, '>', $git->dir . '/.git/hooks/post-receive' |
41 | or die "Cannot write to " . $git->dir . '/.git/hooks/post-receive' . ": $!"; |
42 | print $fh_post_receive $post_receive; |
43 | close $fh_post_receive |
44 | or die "Cannot close " . $git->dir . '/.git/hooks/post-receive' . ": $!"; |
45 | |
46 | open my $fh_post_update, '>', $git->dir . '/.git/hooks/post-update' |
47 | or die "Cannot write to " . $git->dir . '/.git/hooks/post-update' . ": $!"; |
48 | print $fh_post_update $post_update; |
49 | close $fh_post_update |
50 | or die "Cannot close " . $git->dir . '/.git/hooks/post-update' . ": $!"; |
c0ce95cc |
51 | |
6b832bd6 |
52 | chmod(0x755, ($git->dir . '.git/hooks/post-receive', $git->dir . '.git/hooks/post-update')); |
c0ce95cc |
53 | |
40056462 |
54 | return 1; |
55 | } |
56 | |
57 | |
47863b26 |
58 | 1; |