-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.rb
111 lines (88 loc) · 2.73 KB
/
install.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env ruby
require 'yaml'
require 'tmpdir'
class DotFiles
GITHUB_URL = "git://github.com"
GIT_FILE_EXT = '.git'
EMACS_DIR = File.join(Dir.home, '.emacs.d')
LISP_DIR = File.join(EMACS_DIR, 'lisp')
LINUX_FONT_DIR = File.join(Dir.home, '.fonts')
OSX_FONT_DIR = File.join(Dir.home, "/Library/Fonts")
# TODO: Maybe only declare OS specific constants when running on that OS?
attr_accessor :directory
def self.install_in(directory, &block)
raise "Block is required!" unless block_given?
DotFiles.new(directory, &block)
end
def initialize(directory, &block)
@directory = directory
if Dir.exist?(@directory)
instance_eval(&block)
end
end
# WARNING: This is very unsafe since we are just trusting anything that comes
# from the user. Maybe switch this out for an actual ruby git client?
# By default, will clone git repositories into the directory passed
# into the `install_in` method.
def clone(repository, destination = nil)
destination ||= @directory
repository = File.join(GITHUB_URL, repository)
filename = File.basename(repository, GIT_FILE_EXT)
destination = File.join(destination, filename)
puts `git clone #{repository} #{destination}`
end
# Installs lisp libraries from Github that are not available in ELPA, MELPA Stable
def install_lisp(repositories)
unless Dir.exist?(LISP_DIR)
puts "Creating #{LISP_DIR}"
Dir.mkdir(LISP_DIR)
end
repositories.each do |repo|
clone(repo, LISP_DIR)
end
end
def install_font(fonts)
install_fonts_linux(fonts) if OS.linux?
install_fonts_mac(fonts) if OS.mac?
puts "Installing fonts on Windows not supported yet. Skipping." if OS.windows?
end
def install_fonts_linux(fonts)
puts "Linux font dir #{LINUX_FONT_DIR}"
unless Dir.exist?(LINUX_FONT_DIR)
puts "Creating #{LINUX_FONT_DIR}"
Dir.mkdir(LINUX_FONT_DIR)
end
tmpdir = Dir.mktmpdir
begin
fonts.each do |font|
clone(font, tmpdir)
end
glob = File.join(tmpdir, '**', '*.ttf')
puts Dir.glob(glob)
ensure
FileUtils.remove_entry(tmpdir)
end
end
module OS
class << self
def mac?
!!(/darwin/ =~ RUBY_PLATFORM)
end
def linux?
!!(/linux/ =~ RUBY_PLATFORM)
end
def windows?
!!(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM)
end
end
end
end
DotFiles.install_in "/home/zach/test" do
config = YAML.load_file("./repos.yml")
lisp_repositories = config["repositories"]["lisp"]
font_repositories = config["repositories"]["font"]
lisp_repositories.each do |repo|
clone repo
end
install_font font_repositories
end