huesler-informatik My 2 cents

Problems installing Ruby with RVM on OSX Yosemite 10.10.2

I tried to install Ruby 1.9.3 using RVM but it had problems auto detecting the correct compiler.

TLDR;

Error

$: rvm install 1.9.3
...
couldn't understand kern.osversion `14.1.0'
ld: dylib ./libruby.1.9.1.dylib missing LC_ID_DYLIB load command file './libruby.1.9.1.dylib' for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [.ext/x86_64-darwin14.1.0/enc/encdb.bundle] Error 1
make: *** [enc] Error 2
+__rvm_make:0> return 2
There has been an error while running make. Halting the installation.

Solution

$: brew install gcc48
$: CC=/usr/local/Cellar/gcc48/4.8.4/bin/gcc-4.8 rvm install 1.9.3

Background information

$: rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-1.9.3-p551.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/phuesler/.rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your cpu(s)...
ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 9813k  100 9813k    0     0  2669k      0  0:00:03  0:00:03 --:--:-- 2669k
ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /Users/phuesler/.rvm/src/ruby-1.9.3-p551 - please wait
ruby-1.9.3-p551 - #applying patch /Users/phuesler/.rvm/patches/ruby/GH-488.patch - please wait
ruby-1.9.3-p551 - #configuring - please wait
ruby-1.9.3-p551 - #post-configuration - please wait
ruby-1.9.3-p551 - #compiling - please wait
Error running '__rvm_make -j 1',
showing last 15 lines of /Users/phuesler/.rvm/log/1426179507_ruby-1.9.3-p551/make.log
linking static-library libruby.1.9.1-static.a
linking shared-library libruby.1.9.1.dylib
couldn't understand kern.osversion `14.1.0'
generating encdb.h
encdb.h unchanged
making enc
compiling ./enc/encdb.c
couldn't understand kern.osversion `14.1.0'
linking encoding encdb.bundle
couldn't understand kern.osversion `14.1.0'
ld: dylib ./libruby.1.9.1.dylib missing LC_ID_DYLIB load command file './libruby.1.9.1.dylib' for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [.ext/x86_64-darwin14.1.0/enc/encdb.bundle] Error 1
make: *** [enc] Error 2
+__rvm_make:0> return 2
There has been an error while running make. Halting the installation.

Looking at the error log showed that it might be using an incompatible version of gcc.

$: head /Users/phuesler/.rvm/log/1426179507_ruby-1.9.3-p551/make.log
+__rvm_make:0> make -j 1
    CC = /usr/local/opt/apple-gcc42/bin/gcc-4.2
    LD = ld
    LDSHARED = /usr/local/opt/apple-gcc42/bin/gcc-4.2 -dynamiclib
    CFLAGS = -O3 -g   -fno-common -pipe
    XCFLAGS = -include ruby/config.h -include ruby/missing.h -DRUBY_EXPORT
    CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I. -I.ext/include/x86_64-darwin14.1.0 -I./include -I.
    DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -install_name /Users/phuesler/.rvm/rubies/ruby-1.9.3-p551/lib/libruby.1.9.1.dylib -current_version 1.9.1 -compatibility_version 1.9.1  -Wl,-u,_objc_msgSend
    SOLIBS =
compiling main.c

So let's try to compile it using apples clang which ships with xcode:

$:  /usr/bin/gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
CC=/usr/bin/gcc rvm reinstall 1.9.3
ruby-1.9.3-p551 - #removing src/ruby-1.9.3-p551 - please wait
ruby-1.9.3-p551 - #removing rubies/ruby-1.9.3-p551 - please wait
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-1.9.3-p551.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Warning: found user selected compiler '/usr/bin/gcc', this will suppress RVM auto detection mechanisms.
Installing Ruby from source to: /Users/phuesler/.rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your cpu(s)...
ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, this may take a while depending on your connection...
ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /Users/phuesler/.rvm/src/ruby-1.9.3-p551 - please wait
ruby-1.9.3-p551 - #applying patch /Users/phuesler/.rvm/patches/ruby/GH-488.patch - please wait
ruby-1.9.3-p551 - #configuring - please wait
ruby-1.9.3-p551 - #post-configuration - please wait
ruby-1.9.3-p551 - #compiling - please wait
qruby-1.9.3-p551 - #installing - please wait
ruby-1.9.3-p551 - #making binaries executable - please wait
ruby-1.9.3-p551 - #downloading rubygems-2.4.6
ruby-1.9.3-p551 - #extracting rubygems-2.4.6 - please wait
ruby-1.9.3-p551 - #removing old rubygems - please wait
ruby-1.9.3-p551 - #installing rubygems-2.4.6 - please wait
ruby-1.9.3-p551 - #gemset created /Users/phuesler/.rvm/gems/ruby-1.9.3-p551@global
ruby-1.9.3-p551 - #importing gemset /Users/phuesler/.rvm/gemsets/global.gems - please wait
ruby-1.9.3-p551 - #generating global wrappers - please wait
ruby-1.9.3-p551 - #gemset created /Users/phuesler/.rvm/gems/ruby-1.9.3-p551
ruby-1.9.3-p551 - #importing gemsetfile /Users/phuesler/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p551 - #generating default wrappers - please wait
ruby-1.9.3-p551 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p551 - #complete
Ruby 'ruby-1.9.3-p551' was built using clang - but it's not (fully) supported, expect errors.
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

    http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering

Please consider upgrading to ruby-2.2.0 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

Turns out building Ruby 1.9.3 with clang is not fully supported:

Ruby 'ruby-1.9.3-p551' was built using clang - but it's not (fully) supported, expect errors.

Let's try the latest gcc we can find on homebrew:

$: brew install gcc48
==> Installing gcc48 from homebrew/homebrew-versions
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/versions/gcc48-4.8.4.yosemite.
Already downloaded: /Library/Caches/Homebrew/gcc48-4.8.4.yosemite.bottle.tar.gz
==> Pouring gcc48-4.8.4.yosemite.bottle.tar.gz
[brew]  /usr/local/Cellar/gcc48/4.8.4: 1028 files, 142M
$: CC=/usr/local/Cellar/gcc48/4.8.4/bin/gcc-4.8 rvm install 1.9.3
ruby-1.9.3-p551 - #removing src/ruby-1.9.3-p551 - please wait
ruby-1.9.3-p551 - #removing rubies/ruby-1.9.3-p551 - please wait
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-1.9.3-p551.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Warning: found user selected compiler '/usr/local/Cellar/gcc48/4.8.4/bin/gcc-4.8', this will suppress RVM auto detection mechanisms.
Installing Ruby from source to: /Users/phuesler/.rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your cpu(s)...
ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, this may take a while depending on your connection...
ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /Users/phuesler/.rvm/src/ruby-1.9.3-p551 - please wait
ruby-1.9.3-p551 - #applying patch /Users/phuesler/.rvm/patches/ruby/GH-488.patch - please wait
ruby-1.9.3-p551 - #configuring - please wait
ruby-1.9.3-p551 - #post-configuration - please wait
ruby-1.9.3-p551 - #compiling - please wait
ruby-1.9.3-p551 - #installing - please wait
ruby-1.9.3-p551 - #making binaries executable - please wait
ruby-1.9.3-p551 - #downloading rubygems-2.4.6
ruby-1.9.3-p551 - #extracting rubygems-2.4.6 - please wait
ruby-1.9.3-p551 - #removing old rubygems - please wait
ruby-1.9.3-p551 - #installing rubygems-2.4.6 - please wait
ruby-1.9.3-p551 - #gemset created /Users/phuesler/.rvm/gems/ruby-1.9.3-p551@global
ruby-1.9.3-p551 - #importing gemset /Users/phuesler/.rvm/gemsets/global.gems - please wait
ruby-1.9.3-p551 - #generating global wrappers - please wait
ruby-1.9.3-p551 - #gemset created /Users/phuesler/.rvm/gems/ruby-1.9.3-p551
ruby-1.9.3-p551 - #importing gemsetfile /Users/phuesler/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p551 - #generating default wrappers - please wait
ruby-1.9.3-p551 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p551 - #complete
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

    http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering

Please consider upgrading to ruby-2.2.0 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

Stickies is beachballing - OSX Yosemite

Stickies kept beachballing on me upon startup and would eventually crash. Checking dmesg in the Terminal revealed that it had issues handling its own application state.

$: sudo dmesg
...
Sandbox: Stickies(22579) System Policy: deny file-write-unlink /Users/phuesler/Library/Saved Application State/com.apple.Stickies.savedState/restorecount.plist
...

I have fixed it by deleting restorecount.plist but making a backup of it first, just in case:

$: cp -p “~/Library/Saved Application State/com.apple.Stickies.savedState/restorecount.plist” /tmp/restorecount.plist
$: rm -rf “~/Library/Saved Application State/com.apple.Stickies.savedState/restorecount.plist”

Christmas game raffle winners

The winners have been notified.

Congratulations and Merry Christmas!

Christmas game raffle

 

I'm giving away the games and items I purchased from Yogscast Jingle Jam Humble Bundle.

  • Team Fortress 2 Thought That Counts Medal
  • Bridge Constructor
  • Magicka: Dungeons and Daemons DLC
  • Ace of Spades: Battle Builder
  • Thomas Was Alone
  • Mark of the Ninja
  • Montas (Early Access)
  • NiGHTS Into Dreams
  • Swords and Soldiers
  • Awesomenauts Honeydew Skolldir Skin
  • Awesomenauts Demon Skolldir Skins
  • Strike Suit Infinity
  • Call of Juarez
  • Miner Wars Arena

Please fill out the form below to participate and rest assured, I will not share your email address with anyone nor will I use it to send anything other than a winner's notice.

The winners will get the games/items in the form of redeemable Steam gift links.

Good luck and Merry Christmas!

Deleting old ZFS snapshots

** Update Jan 9th, 2015: Added support for GNU Date on Linux

I needed to delete old zfs snapshots so I wrote a little bash script that does this for me. In addition to time parameters you can specify a match pattern as well as instructing the script to run a test run, which simulates the deletion of snapshots but does not actually delete them.

$: ./scripts/delete_snapshots.sh
No grep pattern supplied

delete_old_snapshots.sh -s SECONDS -m MINUTES -h HOURS -d DAYS -p GREP_PATTERN [-t]
 arguments:
 -s delete snapshots older than SECONDS
 -m delete snapshots older than MINUTES
 -h delete snapshots older than HOURS
 -d delete snapshots older than DAYS
 -p the grep pattern to use
 -t test run, do not destroy the snapshots just print them

Simulate the deletion of snapshots older than 1 day containing the word 'foo'

$: ./scripts/delete_snapshots.sh -d 1 -p foo -t

Delete snapshots older than 3 hours and 5 seconds:

$: ./scripts/delete_snapshots.sh -s 5 -p foo -h 1

Delete snapshots older than 1 second containing any characters (this is the nuclear option):

$: ./scripts/delete_snapshots.sh -s 1 -p '.'

Here is the script in its full glory. You can also find the latest version on my github repository.

#!/usr/bin/env bash

usage="$(basename "$0") -s SECONDS -m MINUTES -h HOURS -d DAYS -p GREP_PATTERN [-t]\n

arguments:\n
    -s delete snapshots older than SECONDS\n
    -m delete snapshots older than MINUTES\n
    -h delete snapshots older than HOURS\n
    -d delete snapshots older than DAYS\n
    -p the grep pattern to use\n
    -t test run, do not destroy the snapshots just print them
"

while getopts ":ts:m:h:d:p:" opt; do
  case $opt in
    s)
      seconds=$OPTARG
      ;;
    m)
      minutes=$OPTARG
      ;;
    h)
      hours=$OPTARG
      ;;
    d)
      days=$OPTARG
      ;;
    p)
      pattern=$OPTARG
      ;;
    t)
      test_run=true
      ;;
    \?)
      echo "Invalid option: -$OPTARG" 1>&2
      echo -e $usage 1>&2
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument." 1>&2
      echo -e $usage 1>&2
      exit 1
      ;;
  esac
done

if [[ -z $pattern ]]; then
  echo -e "No grep pattern supplied\n" 1>&2
  echo -e $usage 1>&2
  exit 1
fi

if [[ -z $days ]]; then
  days=0
fi

if [[ -z $hours ]]; then
  hours=0
fi

if [[ -z $minutes ]]; then
  minutes=0
fi

if [[ -z $seconds ]]; then
  seconds=0
fi

# Figure out which platform we are running on, more specifically, whic version of date
# we are using. GNU date behaves different thant date on OSX and FreeBSD
platform='unknown'
unamestr=$(uname)

if [[ "$unamestr" == 'Linux' ]]; then
  platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
  platform='bsd'
elif [[ "$unamestr" == 'OpenBSD' ]]; then
  platform='bsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
  platform='bsd'
else
  echo -e "unknown platform $unamestr 1>&2"
  exit 1
fi

compare_seconds=$(($days * 24 * 60 * 60 + $hours * 60 * 60 + $minutes * 60 + $seconds))
if [ $compare_seconds -lt 1 ]; then
  echo -e time has to be in the past 1>&2
  echo -e $usage 1>&2
  exit 1
fi

if [[ "$platform" == 'linux' ]]; then
compare_timestamp=`date --date="-$(echo $compare_seconds) seconds" +"%s"`
else
compare_timestamp=`date -j -v-$(echo $compare_seconds)S +"%s"`
fi

# get a list of snapshots sorted by creation date, so that we get the oldest first
# This will allow us to skip the loop early
snapshots=`zfs list -H -t snapshot -o name,creation -s creation | grep $pattern`

if [[ -z $snapshots ]]; then
  echo "no snapshots found for pattern $pattern"
  exit 0
fi


# for in uses \n as a delimiter
old_ifs=$IFS
IFS=$'\n'
for line in $snapshots; do
  snapshot=`echo $line | cut -f 1`
  creation_date=`echo $line | cut -f 2`

  if [[ "$platform" == 'linux' ]]; then
    creation_date_timestamp=`date --date="$creation_date" "+%s"`
  else
    creation_date_timestamp=`date -j -f "%a %b %d %H:%M %Y" "$creation_date" "+%s"`
  fi

  # Check if the creation date of a snapshot is less than our compare date
  # Meaning if it is older than our compare date
  # It is younger, we can stop processing since we the list is sorted by
  # compare date '-s creation'
  if [ $creation_date_timestamp -lt $compare_timestamp ]
  then
    if [[ -z $test_run ]]; then
      echo "DELETE: $snapshot from $creation_date"
      zfs destroy $snapshot
    else
      echo "WOULD DELETE: $snapshot from $creation_date"
    fi
  else
    echo "KEEP: $snapshot from $creation_date"
    echo "No more snapshots to be processed for $pattern. Skipping.."
    break
  fi
done
IFS=$old_ifs