-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capfile
78 lines (65 loc) · 2.59 KB
/
Capfile
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
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
# Capistrano script to populate a fresh shell with my personal configuration
# files and tools.
require 'rubygems'
require 'capistrano'
require 'find'
# Allocate PTYs on connecting
default_run_options[:pty] = true
set :repo_dir, File.dirname(__FILE__)
$: << '.' unless $:.include?('.')
libdir = File.join(fetch(:repo_dir), 'lib')
$: << libdir unless $:.include?(libdir)
# Load all capistrano configuration under config/deploy/
Dir["#{fetch(:repo_dir)}/config/*.rb"].each { |file| load(file) }
set :application, "jof's dotfiles"
set :user, ENV['USER']
set :deploy_to, '/home/jof'
desc "Deploy to the local host"
task :localhost do
role :server, "localhost"
end
task :find_deploy_to do
set :deploy_to, capture('echo ~jof')
end
# "Set ~/.ssh permissions."
task :set_ssh_permissions, :depends => :find_deploy_to do
dot_ssh = File.join(fetch(:deploy_to), '.ssh')
run("mkdir -p #{dot_ssh}")
run("find \"#{dot_ssh}\" -maxdepth 1 -type f -exec chmod 0600 {} \\;")
run("find \"#{dot_ssh}\" -maxdepth 1 -type d -exec chmod 0700 {} \\;")
run("chmod 0755 #{dot_ssh}")
authorized_keys = File.join(dot_ssh, "authorized_keys")
run("[ -f #{authorized_keys} ] && chmod 0644 #{authorized_keys}")
end
desc "Load up a home directory with personal options and tools."
task :deploy, :depends => :find_deploy_to do |config|
role(:server, hostname) if config[:hostname]
# Enumerate local files to place
# Place local files into remote deploy_to path
# Place SSH keys (work vs. personal? Submodule for work?)
local_file_root = File.join(fetch(:repo_dir), "homedir_root")
local_files = []
local_directories = []
Find.find(local_file_root) do |pathname|
next if pathname.match(/\/\.git(\/|$)/) # Skip any .git directories
local_directories << pathname if File.directory?(pathname)
local_files << pathname if File.file?(pathname)
end
local_files.sort!
local_directories.sort!
# Figure out the remote home directory and upload everything relative to there
# First, creating directories, and then filling them with files.
remote_home_directory = capture("echo ${HOME}").strip
local_directories.each do |directory_name|
relative_path = directory_name.sub(local_file_root, '')
remote_directory_path = File.expand_path(File.join(remote_home_directory, relative_path))
run "mkdir -p #{remote_directory_path}"
end
local_files.each do |filename|
relative_path = filename.sub(local_file_root, '')
remote_file_name = File.expand_path(File.join(remote_home_directory, relative_path))
upload(filename, remote_file_name, :via => :scp)
end
set_ssh_permissions
end