#!/bin/sh
#
# 2012 Evax Software <contact@evax.fr>
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#

if [ -f "$__object/parameter/default" ]; then
   default="$(cat "$__object/parameter/default")"
else
   default="no"
   echo "$default" > "$__object/parameter/default"
fi

ruby="$__object_id"
user="$(cat "$__object/parameter/user")"
state="$(cat "$__object/explorer/state")"

apt_ruby="build-essential openssl libreadline6 libreadline6-dev curl git-core
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3
libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
subversion"
apt_jruby="curl g++ openjdk-6-jre-headless"
apt_jruby_head="ant openjdk-6-jdk"
apt_ironruby="curl mono-2.0-devel"

emerge_ruby="libiconv readline zlib openssl curl git libyaml sqlite libxslt
libtool gcc autoconf automake bison m4"
emerge_jruby="dev-java/sun-jdk dev-java/sun-jre-bin"
emerge_ironruby="dev-lang/mono"

pacman_ruby="gcc patch curl zlib readline libxml2 libxslt git autoconf
diffutils make libtool bison subversion"
pacman_jruby="jdk jre curl"
pacman_ironruby="mono"

yum_ruby="gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel
libffi-devel openssl-devel make bzip2 autoconf automake libtool bison
iconv-devel"
yum_jruby="java"

os="$(cat "$__global/explorer/os")"
case "$os" in
 archlinux) type="pacman" ;;
 debian|ubuntu) type="apt" ;;
 gentoo) type="emerge" ;;
 fedora|redhat|centos) type="yum" ;;
 *);;
esac
case "$ruby" in
 ruby-head*)
    deps_list="${type}_ruby_head"
 ;;
 ruby*)
    deps_list="${type}_ruby"
 ;;
 jruby-head*)
    deps_list="${type}_jruby_head"
 ;;
 jruby*)
    deps_list="${type}_jruby"
 ;;
 ironruby*)
    deps_list="${type}_ironruby"
 ;;
esac
deps=$(eval echo \$$deps_list)
for p in $deps; do __package_${type} $p --state present; done

__rvm "$user" --state present
