Skip to content

Instantly share code, notes, and snippets.

@thewyzard44
Last active October 6, 2018 21:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thewyzard44/4c0ad89d0cbb68a50bdcc2c188dc83f1 to your computer and use it in GitHub Desktop.
Save thewyzard44/4c0ad89d0cbb68a50bdcc2c188dc83f1 to your computer and use it in GitHub Desktop.
chefdk + chruby in WSL/bash
umask 022
export PATH=~/bin:`echo $PATH | sed 's|:/bin:|&/opscode/chefdk/bin:/mnt/c/Users/Sean/AppData/Local/chefdk/gem/ruby/2.4.0/bin:/opscode/chefdk/embedded/bin:|'`
#!/bin/bash
ln -sfv /mnt/c/opscode /opscode
ln -sfv /opscode/chefdk/embedded /opt/rubies/chefdk
find /opscode/chefdk/ | egrep '/(chefdk|embedded)/bin/[^\./]+$' | xargs sed -i '/^#!C:/s|C:/|/|'
ln -sfv ruby.exe /opscode/chefdk/embedded/bin/ruby
sed -i -e '/$UID/,/fi/s/^[[:space:]]*\(if \|fi\)/#&/' -e 's/puts/print/' /usr/local/share/chruby/chruby.sh
#TODO: still need to idempotently script placing this next command right after the ruby shell-out in the chruby_use function
# not needed unless/until I reinstall chruby
#[[ "$var" =~ /chefdk$ ]] && PATH="${PATH//$RUBY_ROOT\/bin:/}" && eval "$(chef shell-init bash | grep -v '^export PATH=' | sed 's/\r//g')" && return
@thewyzard44
Copy link
Author

thewyzard44 commented Feb 17, 2018

  • works for current chruby (v0.3.9)
  • append the above .bashrc into your own.
  • put patch-chefdk.sh in your ~/bin
  • run patch-chefdk.sh once
  • run patch-chefdk.sh each time you update your windows chefdk (to whack the binstubs - line 6)
  • run patch-chefdk.sh each time you update your chruby to reapply the behavioural changes
    ** the last line needs manually placed in /usr/local/share/chruby/chruby.sh until I get a minute to sed/script it

Features:

  • functioning chefdk immediately upon starting bash
  • forces chruby to use /root/.gem for user gems even though you are 'root' (line 9) - for easy cleanup
  • can chruby into your own /opt/rubies (e.g. 2.4.3) and still have access to chefdk executables (e.g. kitchen - just not chef's ruby)
  • can chruby back into the chefdk with chruby chefdk (Line 14)

potential caveats:

  • GEM_HOME & GEM_PATH, etc... are not set upon initially entering bash, but ARE set upon chruby chefdk. it "shouldn't" be a big issue(?) due to...
  • user gems in chefdk mode still go into appdata/local/chefdk (or is that a feature?)

oh whoops - in the .bashrc you'll need to update that path with your own username

End Goal: one idempotent script that I can run everytime I update chruby or chefdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment