Permalink
Browse files

System functions are replaced with sunzi.mute() and sunzi.install(). …

…Removed SSH sample from template. v1.0.0
  • Loading branch information...
1 parent 26bb6d9 commit eb89d9b6a3572e5801ebe7c24f0873bc4263dbf3 @kenn committed Mar 22, 2013
View
@@ -83,7 +83,7 @@ sunzi/
sunzi.yml # add custom attributes and remote recipes here
recipes/ # put commonly used scripts here, referred from install.sh
- ssh_key.sh
+ sunzi.sh
roles/ # when role is specified, scripts here will be concatenated
app.sh # to install.sh in the compile phase
db.sh
View
@@ -47,7 +47,6 @@ def do_create(project)
template 'templates/create/sunzi.yml', "#{project}/sunzi.yml"
template 'templates/create/install.sh', "#{project}/install.sh"
template 'templates/create/recipes/sunzi.sh', "#{project}/recipes/sunzi.sh"
- template 'templates/create/recipes/ssh_key.sh', "#{project}/recipes/ssh_key.sh"
template 'templates/create/roles/app.sh', "#{project}/roles/app.sh"
template 'templates/create/roles/db.sh', "#{project}/roles/db.sh"
template 'templates/create/roles/web.sh', "#{project}/roles/web.sh"
@@ -1,6 +1,6 @@
#!/bin/bash
-# Load base utility functions like sunzi::silencer()
+# Load base utility functions like sunzi.mute() and sunzi.install()
source recipes/sunzi.sh
# This line is necessary for automated provisioning for Debian/Ubuntu.
@@ -10,15 +10,40 @@ export DEBIAN_FRONTEND=noninteractive
# Add Dotdeb repository. Recommended if you're using Debian. See http://www.dotdeb.org/about/
# source recipes/dotdeb.sh
-# SSH key
-source recipes/ssh_key.sh $(cat attributes/ssh_key)
+# Update installed packages
+sunzi.mute "aptitude update"
+sunzi.mute "aptitude -y safe-upgrade"
-# Update apt catalog. If you prefer less verbosity, use the sunzi::silencer version instead
-aptitude update
-aptitude -y safe-upgrade
-# sunzi::silencer "aptitude update"
-# sunzi::silencer "aptitude -y safe-upgrade"
+# Install packages
+sunzi.install "git-core ntp curl"
-# Install packages. If you prefer less verbosity, use the sunzi::silencer version instead
-aptitude -y install git-core ntp
-# sunzi::silencer "aptitude -y install git-core ntp"
+# Set RAILS_ENV
+environment=$(cat attributes/environment)
+
+if ! grep -Fq "RAILS_ENV" ~/.bash_profile; then
+ echo 'Setting up RAILS_ENV...'
+ echo "export RAILS_ENV=$environment" >> ~/.bash_profile
+ source ~/.bash_profile
+fi
+
+# Install Ruby using RVM
+source recipes/rvm.sh
+ruby_version=$(cat attributes/ruby_version)
+
+if [[ "$(which ruby)" != /usr/local/rvm/rubies/ruby-$ruby_version* ]]; then
+ echo "Installing ruby-$ruby_version"
+ sunzi.install build-essential libssl-dev libreadline6-dev
+ rvm install $ruby_version
+ rvm $ruby_version --default
+ echo 'gem: --no-ri --no-rdoc' > ~/.gemrc
+
+ # Install Bundler
+ gem update --system
+ gem install bundler
+fi
+
+# Install sysstat, then configure if this is a new install.
+if sunzi.install "sysstat"; then
+ sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
+ /etc/init.d/sysstat restart
+fi
@@ -1,18 +0,0 @@
-# SSH key
-# $1: SSH key filename
-
-if [ -f ~/.ssh/authorized_keys ]; then
- echo 'authorized_keys already created'
-else
- if [ -f "files/$1" ]; then
- echo 'Creating authorized_keys'
- mkdir -p ~/.ssh
- cat "files/$1" > ~/.ssh/authorized_keys
- rm "files/$1"
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/authorized_keys
- else
- echo "The public key file \"$1\" is not found! Look into files section in sunzi.yml."
- exit 1
- fi
-fi
@@ -1,6 +1,47 @@
-# This file is used to define functions under the sunzi:: namespace.
+# This file is used to define functions under the sunzi.* namespace.
-function sunzi::silencer() {
+# Set $sunzi_pkg to "aptitude" or "yum", or abort.
+#
+if which aptitude >/dev/null 2>&1; then
+ export sunzi_pkg=aptitude
+elif which yum >/dev/null 2>&1; then
+ export sunzi_pkg=yum
+fi
+
+if [ "$sunzi_pkg" = '' ]; then
+ echo 'sunzi only supports aptitude and yum!' >&2
+ exit 1
+fi
+
+# Mute STDOUT and STDERR
+#
+function sunzi.mute() {
echo "Running \"$@\""
- eval "$@ > /dev/null 2>&1"
+ `$@ >/dev/null 2>&1`
+ return $?
+}
+
+# Installer
+#
+function sunzi.installed() {
+ if [ "$sunzi_pkg" = 'aptitude' ]; then
+ dpkg -s $@ >/dev/null 2>&1
+ elif [ "$sunzi_pkg" = 'yum' ]; then
+ rpm -qa | grep $@ >/dev/null
+ fi
+ return $?
+}
+
+function sunzi.install() {
+ for name in $@
+ do
+ if sunzi.installed "$name"; then
+ echo "$name already installed"
+ return 1
+ else
+ echo "No packages found matching $name. Installing..."
+ sunzi.mute "$sunzi_pkg -y install $name"
+ return 0
+ fi
+ done
}
@@ -1,9 +1,8 @@
---
# Dynamic variables here will be compiled to individual files in compiled/attributes.
attributes:
- ssh_key: id_rsa.pub
- environment: development
- ruby_version: 1.9.3
+ environment: production
+ ruby_version: 2.0.0
# Remote recipes here will be downloaded to compiled/recipes.
recipes:
@@ -12,8 +11,8 @@ recipes:
# mongodb-10gen: https://raw.github.com/kenn/sunzi-recipes/master/debian/mongodb-10gen.sh
# Files specified here will be copied to compiled/files.
-files:
- - ~/.ssh/id_rsa.pub
+# files:
+# - ~/.ssh/id_rsa.pub
# Fine tune how Sunzi should work.
preferences:
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |spec|
spec.name = 'sunzi'
- spec.version = '0.9.1' # retrieve this value by: Gem.loaded_specs['sunzi'].version.to_s
+ spec.version = '1.0.0' # retrieve this value by: Gem.loaded_specs['sunzi'].version.to_s
spec.authors = ['Kenn Ejima']
spec.email = ['kenn.ejima@gmail.com']
spec.homepage = 'http://github.com/kenn/sunzi'

0 comments on commit eb89d9b

Please sign in to comment.