1 #!/usr/bin/env ruby |
1 #!/usr/bin/env ruby |
2 # vim: et sts=2 sw=2 fdm=marker |
2 # vim: et sts=2 sw=2 fdm=marker |
3 |
3 |
4 # we don't yet have rbenv so keep safe for ruby 1.9 |
4 # we don't yet have rbenv so keep safe for ruby 1.9 |
|
5 |
|
6 require 'getoptlong' |
5 |
7 |
6 if `which git` == '' |
8 if `which git` == '' |
7 puts "please install git" |
9 puts "please install git" |
8 exit 1 |
10 exit 1 |
9 end |
11 end |
10 |
12 |
|
13 def main |
|
14 opts = GetoptLong.new( |
|
15 [ '--help', '-h', GetoptLong::NO_ARGUMENT ], |
|
16 [ '--update', '-u', GetoptLong::NO_ARGUMENT ], |
|
17 [ '--setup', '-s', GetoptLong::NO_ARGUMENT ], |
|
18 ); |
|
19 |
|
20 case opts.get.shift |
|
21 when '--help' |
|
22 puts <<-ENDHELP.sub(/^\s+/,'') |
|
23 #{$0} usage: |
|
24 -h --help This help message |
|
25 -s --setup Perform home directory setup (git clone) |
|
26 -u --update Update git stuff (git pull) |
|
27 ENDHELP |
|
28 exit 1 |
|
29 when '--setup' |
|
30 setup |
|
31 when '--update' |
|
32 update |
|
33 end |
|
34 end |
11 |
35 |
12 # just checks and bails after each call, output already in STDERR |
36 # just checks and bails after each call, output already in STDERR |
13 def do_cmds (*cmds) |
37 def do_cmds (*cmds) |
14 cmds.each do |cmd| |
38 cmds.each do |cmd| |
15 puts "$ #{cmd}" |
39 puts "$ #{cmd}" |
16 system( cmd ) or exit $? |
40 system( cmd ) or exit $? |
17 end |
41 end |
18 end |
42 end |
19 |
43 |
20 |
44 |
|
45 def setup |
21 |
46 |
22 # oh-my-zsh {{{ |
47 # oh-my-zsh {{{ |
23 # some custom zsh files are already in .oh-my-zsh.cust |
48 # some custom zsh files are already in .oh-my-zsh.cust |
24 |
49 |
25 if Dir.exists?('.oh-my-zsh/.git') |
50 if Dir.exists?('.oh-my-zsh/.git') |
26 puts "oh-my-zsh already installed" |
51 puts "oh-my-zsh already installed" |
27 else |
52 else |
28 puts "Installing oh-my-zsh..." |
53 puts "Installing oh-my-zsh..." |
29 |
54 |
|
55 do_cmds \ |
|
56 'git clone git://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh' |
|
57 |
|
58 end |
|
59 |
|
60 # }}} |
|
61 |
|
62 |
|
63 # plenv {{{ |
|
64 |
|
65 if Dir.exists?('.plenv') |
|
66 puts "plenv already installed" |
|
67 else |
|
68 puts "Installing plenv..." |
|
69 |
|
70 do_cmds \ |
|
71 'git clone git://github.com/tokuhirom/plenv.git .plenv', |
|
72 'git clone git://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/' |
|
73 |
|
74 end |
|
75 |
|
76 # }}} |
|
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 |
|
89 end |
|
90 # }}} |
|
91 |
|
92 end |
|
93 |
|
94 def update |
|
95 |
|
96 [ |
|
97 '.oh-my-zsh', |
|
98 '.plenv', |
|
99 '.plenv/plugins/perl-build', |
|
100 '.rbenv', |
|
101 '.rbenv/plugins/ruby-build', |
|
102 ].each do |dir| |
30 do_cmds \ |
103 do_cmds \ |
31 'git clone git://github.com/robbyrussell/oh-my-zsh.git .oh-my-zsh' |
104 "chdir ~/#{dir} && git pull origin master" |
32 |
|
33 end |
105 end |
34 |
106 |
35 # }}} |
|
36 |
107 |
|
108 end |
37 |
109 |
38 # plenv {{{ |
110 main |
39 |
111 |
40 if Dir.exists?('.plenv') |
|
41 puts "plenv already installed" |
|
42 else |
|
43 puts "Installing plenv..." |
|
44 |
|
45 do_cmds \ |
|
46 'git clone git://github.com/tokuhirom/plenv.git .plenv', |
|
47 'git clone git://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/' |
|
48 |
|
49 end |
|
50 |
|
51 # }}} |
|
52 |
|
53 |
|
54 # rbenv {{{ |
|
55 if Dir.exists?('.rbenv') |
|
56 puts "rbenv already installed" |
|
57 else |
|
58 puts "Installing rbenv..." |
|
59 |
|
60 do_cmds \ |
|
61 'git clone https://github.com/sstephenson/rbenv.git .rbenv', |
|
62 'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/' |
|
63 |
|
64 end |
|
65 # }}} |
|
66 |
|
67 |
|
68 |
|