add .homedir-setup.sh

Fri, 22 Jan 2016 22:08:34 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Fri, 22 Jan 2016 22:08:34 -0500
changeset 245
9fa186a70bbd
parent 244
721455edd12b
child 246
f37fa5e96d76

add .homedir-setup.sh

.homedir-setup.rb file | annotate | diff | comparison | revisions
.homedir-setup.sh file | annotate | diff | comparison | revisions
deleted file mode 100755
--- a/.homedir-setup.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env ruby
-# vim: et sts=2 sw=2 fdm=marker
-
-# we don't yet have rbenv so keep safe for ruby 1.9
-
-require 'getoptlong'
-
-if `which git` == ''
-  puts "please install git"
-  exit 1 
-end
-
-def main
-  if ARGV.length == 0
-    ARGV << '--help'
-  end
-
-  opts = GetoptLong.new(
-    [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
-    [ '--update', '-u', GetoptLong::NO_ARGUMENT ],
-    [ '--setup', '-s', GetoptLong::NO_ARGUMENT ],
-  );
-
-  Dir.chdir(
-    File.dirname File.expand_path $0
-  )
-
-  opts.each do |opt, arg|
-    case opt
-    when '--help'
-      puts <<-ENDHELP.sub(/^\s+/,'')
-        #{$0} usage:
-         -h --help    This help message
-         -s --setup   Perform home directory setup (git clone)
-         -u --update  Update git stuff (git pull)
-      ENDHELP
-      exit 1
-    when '--setup'
-      setup
-    when '--update'
-      update
-    end
-  end
-end
-
-# just checks and bails after each call, output already in STDERR
-def do_cmds (*cmds)
-  cmds.each do |cmd|
-    puts "$ #{cmd}"
-    system( cmd ) or exit $?
-  end
-end
-
-
-def setup
-  # zgen {{{
-    if Dir.exists?('.zgen')
-      puts "zgen already installed"
-    else
-      puts "Installing zgen..."
-
-      do_cmds \
-        'git clone https://github.com/tarjoilija/zgen.git .zgen'
-    end
-  # }}}
-
-  # plenv {{{
-    if Dir.exists?('.plenv')
-      puts "plenv already installed"
-    else
-      puts "Installing plenv..."
-
-      do_cmds \
-        'git clone https://github.com/tokuhirom/plenv.git .plenv',
-        'git clone https://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/'
-    end
-  # }}}
-
-  # rbenv {{{
-    if Dir.exists?('.rbenv')
-      puts "rbenv already installed"
-    else
-      puts "Installing rbenv..."
-
-      do_cmds \
-        'git clone https://github.com/sstephenson/rbenv.git .rbenv',
-        'git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/'
-    end
-  # }}}
-
-  # ndenv {{{
-    if Dir.exists?('.ndenv')
-      puts "ndenv already installed"
-    else
-      puts "Installing ndenv..."
-
-      do_cmds \
-        'git clone https://github.com/riywo/ndenv.git .ndenv',
-        'git clone https://github.com/riywo/node-build.git .ndenv/plugins/node-build'
-    end
-  # }}}
-end
-
-def update
-  [ '.zgen',
-    '.plenv',
-    '.plenv/plugins/perl-build',
-    '.rbenv',
-    '.rbenv/plugins/ruby-build',
-    '.ndenv',
-    '.ndenv/plugins/node-build',
-  ].each do |dir|
-    do_cmds \
-      "cd ~/#{dir} && git pull origin master"
-  end
-end
-
-main
-
new file mode 100755
--- /dev/null
+++ b/.homedir-setup.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+set -eu
+
+if ! git --version >/dev/null; then
+  echo "Please install git!"
+  exit 1
+fi
+
+pull () {
+  echo "$1:"
+  git -C $1 pull --no-tags
+}
+
+if ! [ -d .zgen ]; then
+  git clone https://github.com/tarjoilija/zgen.git .zgen
+else
+  pull .zgen
+fi
+
+if ! [ -d .plenv ]; then
+  git clone https://github.com/tokuhirom/plenv.git .plenv
+  git clone https://github.com/tokuhirom/Perl-Build.git .plenv/plugins/perl-build/
+else
+  pull .plenv
+  pull .plenv/plugins/perl-build
+fi
+
+if ! [ -d .rbenv ]; then
+  git clone https://github.com/sstephenson/rbenv.git .rbenv
+  git clone https://github.com/sstephenson/ruby-build.git .rbenv/plugins/ruby-build/
+else
+  pull .rbenv
+  pull .rbenv/plugins/ruby-build
+fi
+
+if ! [ -d .ndenv ]; then
+  git clone https://github.com/riywo/ndenv.git .ndenv
+  git clone https://github.com/riywo/node-build.git .ndenv/plugins/node-build
+else
+  pull .ndenv
+  pull .ndenv/plugins/node-build
+fi
+

mercurial