-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.rb
70 lines (56 loc) · 1.59 KB
/
helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'fileutils'
helpers do
include Sinatra::Authorization
def create_site(site)
cat_key(site)
init_repo(site)
add_post_commit(site)
end
def init_repo(site)
FileUtils.mkdir_p File.join(site.directory, 'tmp')
`touch #{File.join(site.directory, 'tmp')}/never-deployed`
FileUtils.mkdir_p File.join(site.directory, 'public')
current_dir = Dir.getwd
Dir.chdir site.directory
`git init`
Dir.chdir current_dir
`ln -s #{site.directory} #{File.join(SITE_ROOT, site.name)}`
end
def add_post_commit(site)
post_commit = File.join(site.directory, '.git/hooks/post-receive')
File.open(post_commit, 'w') do |f|
f.write <<-HERE
#!/bin/sh
cd #{site.directory};
git reset --hard;
# run initial_deploy_hook here unless /tmp/deployed exists
# initial_deploy should be created in site.directory/deploy-hooks
if [ -x deploy-hooks/initial-deploy -a -f tmp/never-deployed ]
then
deploy-hooks/initial-deploy;
rm #{site.directory}/tmp/never-deployed;
fi
# config_gem file should be in site.directory/deploy-hooks
# post_deploy_hook should be created in site.directory/deploy
if [ -x deploy-hooks/post-receive ]
then
deploy-hooks/post-receive;
fi
cd #{site.directory} && git --git-dir=`pwd`/.git reset --hard;
touch #{site.directory}/tmp/restart.txt;
HERE
f.chmod(0775)
end
end
def cat_key(site)
File.open("#{ENV['HOME']}/.ssh/authorized_keys", 'a') do |f|
f << site.ssh_public_key
end
end
def authorization_realm
'bivou.ac'
end
def authorize(login, password)
login == "bivvy" && password == "whackers"
end
end