2014-10-28

Stop itamae-1.0.4 from using sudo

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

How to watch for correct input in bash

I've seen some pretty crazy ways to do this. Here's how I do it, which I think is the simplest way.
#!/bin/bash

while true; do
    read -p 'Prompt? (y/n) ' yn
    case "$yn" in
        y|Y)
            echo 'YES!'
            break;
            ;;
        n|N)
            echo 'NO!'
            break;
            ;;
    esac
done
This will loop until one of [yYnN] is entered.

2014-03-25

How to Change Atom's `navigator.language`

After tinkering a bit, I've finally figured out how to change the navigator.language! I ended up having to modify the libchromiumcontent.dylib bundled inside Atom.app...
$ cmp -bl {orig,ja-JP}/Atom.app/Contents/Frameworks/Atom\ Framework.framework/Versions/A/Libraries/libchromiumcontent.dylib
43700712 145 e 152 j
43700713 156 n 141 a
43700715 125 U 112 J
43700716 123 S 120 P
This is the value that is used for navigator.language. Once patched as above, navigator.language will return "ja-JP".

2014-03-21

Block Cursor for Atom

Atom's cursor doesn't change to cover the character behind it.  So, if you work with CJK files and want a block cursor (à la vim-mode), then you're left with a half-character-width cursor (the cursor width is set to one &nbsp; by default).

I made a patch for Atom v0.75.0 to fix this issue.

  • CJK Character
    • Before:
    • After:
  • Tab
    • Before:
    • After:

Atom File Types

There wasn't a straight-forward way to associate an arbitrary file type (file extension) with a grammar in Atom.  So, I made a package to do just that.

https://atom.io/packages/file-types

2012-10-04

The Node.js REPL and Backslashes in Strings

I thought there was something weird going on with the node.js REPL's handling of backslashes in Strings. I was thinking, "Why are there twice as many backslashes!?" Then, it hit me: the output is correct! It is escaping the value of the string, just as if a programmer were to have typed it. Duh. You can use the output as-is when copy-and-pasting. No need to manually add extra backspaces! That's pretty convenient, eh? This really had me confused me at first, though, because I am so used to the behavior of Chrome's console, which prints out the unescaped string values (even though it does put quotes around the value).

$ node
> "\ "
' '
> JSON.stringify("\ ")
'" "'
> "\\"
'\\'
> JSON.stringify("\\")
'"\\\\"'
> new Buffer("\\")
<Buffer 5c>
> new Buffer([0x5c]).toString()
'\\'
> new Buffer([0x5c, 0x5c]).toString()
'\\\\'

2012-02-29

U+2665 BLACK HEART SUIT

I was reading an article on StackOverflow when one of the ads caught my eye. It looked something like this:

1
2
3
4 <p>
5 &#x2665;
6 Your Job
7 </p>
8
9

"What character is that?" I wondered whilst automatically opening up the in-browser console.

> String.fromCharCode(0x2665)
""

Hey, it's the U+2665 BLACK HEART SUIT! So, that would make the message: ♥ Your Job.

Cool.