Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

2014-10-28

Stop itamae-1.0.4 from using sudo

UPDATE 2014-11-07

My pull request has been merged.



I'm using itamae for provisioning some servers. However, I don't have sudo access. Here's how I stopped itamae from using sudo.

diff --git a/lib/itamae/backend.rb b/lib/itamae/backend.rb
index d4f6e35..25bab62 100644
--- a/lib/itamae/backend.rb
+++ b/lib/itamae/backend.rb
@@ -33,6 +33,7 @@ module Itamae
       when :ssh
         Specinfra.configuration.request_pty = true
         Specinfra.configuration.host = options.delete(:host)
+        Specinfra.configuration.disable_sudo = options.delete(:disable_sudo)
         Specinfra.configuration.ssh_options = options

         Specinfra.configuration.backend = :ssh
diff --git a/lib/itamae/cli.rb b/lib/itamae/cli.rb
index 8c40fe9..544a0e0 100644
--- a/lib/itamae/cli.rb
+++ b/lib/itamae/cli.rb
@@ -35,6 +35,7 @@ module Itamae
     option :ohai, type: :boolean, default: false
     option :vagrant, type: :boolean, default: false
     option :ask_password, type: :boolean, default: false
+    option :sudo, type: :boolean, default: true
     def ssh(*recipe_files)
       if recipe_files.empty?
         raise "Please specify recipe files."
diff --git a/lib/itamae/runner.rb b/lib/itamae/runner.rb
index 37908fc..3a5c96d 100644
--- a/lib/itamae/runner.rb
+++ b/lib/itamae/runner.rb
@@ -54,6 +54,7 @@ module Itamae
           opts[:user] = options[:user] || Etc.getlogin
           opts[:keys] = [options[:key]] if options[:key]
           opts[:port] = options[:port] if options[:port]
+          opts[:disable_sudo] = true unless options[:sudo]

           if options[:vagrant]
             config = Tempfile.new('', Dir.tmpdir)

This can be applied to a bundled itamae as follows.

#!/bin/bash

DIR=$(dirname "$0")

bundle install --path "$DIR/vendor/bundle"

# itamaeのno sudoパッチを当てる
pushd vendor/bundle/ruby/2.1.0/gems/itamae-1.0.4/lib/itamae &>/dev/null
patch <../../../../../../../../itamae-1.0.4-no-sudo.patch
popd &>/dev/null

Then, to use it...  (I couldn't get --no-sudo to work)

bundle exec itamae ssh -h server -u user --sudo=false recipes/recipe.rb

2010-01-20

Installing RMagick

The other day I had to install RMagick in order to get a RoR project running on a local box to do some maintenance and add new functionality.

Well, I thought everything would be all fine and dandy because I had installed ImageMagick to mess around with previously. But, for some reason, gem install rmagick was complaining it couldn't find Magick-Config or something.

I ended up trying a bunch of suggestions from other blogs (which I conveniently forgot to list...sorry for not giving credits) and somehow came up with this configure for ImageMagick:
./configure --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8

I've not had the time nor the patience to figure out which option is the key to this all; but, RMagick installed without problem.

2009-12-03

Making X binary files of Y bytes

I had to make some dummy files for testing uncompressed zip archives.

Here's what I did:
$ ruby -e 'File::open("hex.bin", "wb") {|f| 1.upto(5*1024) {|b| f.write("\xff")}}'
$ hexdump -Cv hex.bin | tail
00001370  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001380  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001390  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000013f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00001400
$ ruby -e '1.upto(10) {|i| s = sprintf("%04d",i); `ln -s ./hex.bin ./bin#{s}.bin`}'
$ find . -name "bin*.bin" -print | zip -r -0 -X source -@
$ du -abL
5120    ./bin0007.bin
5120    ./bin0004.bin
52202   ./source.zip
5120    ./bin0006.bin
5120    ./bin0002.bin
5120    ./bin0008.bin
5120    ./bin0005.bin
5120    ./bin0009.bin
5120    ./bin0001.bin
5120    ./hex.bin
5120    ./bin0003.bin
5120    ./bin0010.bin
112618  .
$

Awesome.