.homedir-setup.rb

changeset 245
9fa186a70bbd
parent 244
721455edd12b
child 246
f37fa5e96d76
equal deleted inserted replaced
244:721455edd12b 245:9fa186a70bbd
1 #!/usr/bin/env ruby
2 # vim: et sts=2 sw=2 fdm=marker
3
4 # we don't yet have rbenv so keep safe for ruby 1.9
5
6 require 'getoptlong'
7
8 if `which git` == ''
9 puts "please install git"
10 exit 1
11 end
12
13 def main
14 if ARGV.length == 0
15 ARGV << '--help'
16 end
17
18 opts = GetoptLong.new(
19 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
20 [ '--update', '-u', GetoptLong::NO_ARGUMENT ],
21 [ '--setup', '-s', GetoptLong::NO_ARGUMENT ],
22 );
23
24 Dir.chdir(
25 File.dirname File.expand_path $0
26 )
27
28 opts.each do |opt, arg|
29 case opt
30 when '--help'
31 puts <<-ENDHELP.sub(/^\s+/,'')
32 #{$0} usage:
33 -h --help This help message
34 -s --setup Perform home directory setup (git clone)
35 -u --update Update git stuff (git pull)
36 ENDHELP
37 exit 1
38 when '--setup'
39 setup
40 when '--update'
41 update
42 end
43 end
44 end
45
46 # just checks and bails after each call, output already in STDERR
47 def do_cmds (*cmds)
48 cmds.each do |cmd|
49 puts "$ #{cmd}"
50 system( cmd ) or exit $?
51 end
52 end
53
54
55 def setup
56 # zgen {{{
57 if Dir.exists?('.zgen')
58 puts "zgen already installed"
59 else
60 puts "Installing zgen..."
61
62 do_cmds \
63 'git clone https://github.com/tarjoilija/zgen.git .zgen'
64 end
65 # }}}
66
67 # plenv {{{
68 if Dir.exists?('.plenv')
69 puts "plenv already installed"
70 else
71 puts "Installing plenv..."
72
73 do_cmds \
74 'git clone https://github.com/tokuhirom/plenv.git .plenv',
75 'git clone https://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/'
76 end
77 # }}}
78
79 # rbenv {{{
80 if Dir.exists?('.rbenv')
81 puts "rbenv already installed"
82 else
83 puts "Installing rbenv..."
84
85 do_cmds \
86 'git clone https://github.com/sstephenson/rbenv.git .rbenv',
87 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/'
88 end
89 # }}}
90
91 # ndenv {{{
92 if Dir.exists?('.ndenv')
93 puts "ndenv already installed"
94 else
95 puts "Installing ndenv..."
96
97 do_cmds \
98 'git clone https://github.com/riywo/ndenv.git .ndenv',
99 'git clone https://github.com/riywo/node-build.git .ndenv/plugins/node-build'
100 end
101 # }}}
102 end
103
104 def update
105 [ '.zgen',
106 '.plenv',
107 '.plenv/plugins/perl-build',
108 '.rbenv',
109 '.rbenv/plugins/ruby-build',
110 '.ndenv',
111 '.ndenv/plugins/node-build',
112 ].each do |dir|
113 do_cmds \
114 "cd ~/#{dir} && git pull origin master"
115 end
116 end
117
118 main
119

mercurial