Tag: windows

Ruby Gem install fails on Windows because of SSL

When installing the Openshift rhc client I need to install a Ruby gem on Windows. This resulted in an error message:

C:\Users\user>gem install rhc
ERROR:  Could not find a valid gem 'rhc' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect retur
          ned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (
    https://api.rubygems.org/latest_specs.4.8.gz)

This is because the Ruby network client is unable to verify the SSL Certificate Authority. Via Google a found a Gist
which explains how this can be fixed. I found the manual way the fastest way, since I
will not be using gem for other projects.

In short I did this:

Download http://curl.haxx.se/ca/cacert.pem to c:\temp

Executed in command prompt:
set SSL_CERT_FILE=c:\temp\cacert.pem

After this executing the command to install the client tools worked:

C:\temp>gem install rhc
Fetching: net-ssh-2.9.2.beta.gem (100%)
Successfully installed net-ssh-2.9.2.beta
Fetching: net-scp-1.2.1.gem (100%)
Successfully installed net-scp-1.2.1
Fetching: net-ssh-gateway-1.2.0.gem (100%)
Successfully installed net-ssh-gateway-1.2.0
Fetching: net-ssh-multi-1.2.0.gem (100%)
Successfully installed net-ssh-multi-1.2.0
Fetching: archive-tar-minitar-0.5.2.gem (100%)
Successfully installed archive-tar-minitar-0.5.2
Fetching: highline-1.6.21.gem (100%)
Successfully installed highline-1.6.21
Fetching: commander-4.2.1.gem (100%)
Successfully installed commander-4.2.1
Fetching: httpclient-2.5.3.3.gem (100%)
Successfully installed httpclient-2.5.3.3
Fetching: open4-1.3.4.gem (100%)
Successfully installed open4-1.3.4
Fetching: rhc-1.33.4.gem (100%)
===========================================================================

If this is your first time installing the RHC tools, please run 'rhc setup'

===========================================================================
Successfully installed rhc-1.33.4
Parsing documentation for archive-tar-minitar-0.5.2
Installing ri documentation for archive-tar-minitar-0.5.2
Parsing documentation for commander-4.2.1
Installing ri documentation for commander-4.2.1
Parsing documentation for highline-1.6.21
Installing ri documentation for highline-1.6.21
Parsing documentation for httpclient-2.5.3.3
Installing ri documentation for httpclient-2.5.3.3
Parsing documentation for net-scp-1.2.1
Installing ri documentation for net-scp-1.2.1
Parsing documentation for net-ssh-2.9.2.beta
Installing ri documentation for net-ssh-2.9.2.beta
Parsing documentation for net-ssh-gateway-1.2.0
Installing ri documentation for net-ssh-gateway-1.2.0
Parsing documentation for net-ssh-multi-1.2.0
Installing ri documentation for net-ssh-multi-1.2.0
Parsing documentation for open4-1.3.4
Installing ri documentation for open4-1.3.4
Parsing documentation for rhc-1.33.4
Installing ri documentation for rhc-1.33.4
Done installing documentation for archive-tar-minitar, commander, highline, http
client, net-scp, net-ssh, net-ssh-gateway, net-ssh-multi, open4, rhc after 27 se
conds
10 gems installed

Home

After fixing the SSL issue I encountered a second problem during the setup command, after the SSH key step
the client would attempt to write a file to the H:\ drive. It assumed that that was my homedrive, while it does not exist.

Generating an authorization token for this client ... C:/Ruby21-x64/lib/ruby/2.1
.0/fileutils.rb:250:in `mkdir': No such file or directory @ dir_s_mkdir - H: (Er
rno::ENOENT)
        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:250:in `fu_mkdir'
        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:224:in `block (2 levels)
in mkdir_p'
        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:222:in `reverse_each'
        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:222:in `block in mkdir_p'

        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:208:in `each'
        from C:/Ruby21-x64/lib/ruby/2.1.0/fileutils.rb:208:in `mkdir_p'
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rhc-1.33.4/lib/rhc/auth/toke
n_store.rb:34:in `[]='
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rhc-1.33.4/lib/rhc/auth/toke
n_store.rb:14:in `put'
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rhc-1.33.4/lib/rhc/auth/toke
n.rb:50:in `save'
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rhc-1.33.4/lib/rhc/wizard.rb
:243:in `block in login_stage'
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rhc-1.33.4/lib/rhc/highline_
extensions.rb:190:in `call'

It turns out that there are two environment variables that define the HOME folder on Windows: HOMEPATH and HOMEDRIVE. Set
the combination of these two to a writable folder. For example to your user dir on Windows. These environment variables can be
set in two ways: via the commandline (where they will be forgotten after closing the shell windows), or via the Advanced Properties
of the About dialog of My Computer.

The simplest way via the commandline is:

    SET HOMEPATH=\users\user
    SET HOMEDRIVE=C:

Leave a Comment

Running Second Crack on a Windows computer

This blog is hosted on a Linux server, but I generate the blog on my Windows laptop. Some small changes are required in order to get it to work on Windows. The readme.md on the Second Crack is very elaborate in the installation notes. This blogpost only describes the changes I had to make to get it to work on Windows.

Installation

I have installed Second Crack in a separate folder, in C:\apps\secondcrack. The source files are placed in _C:\blog_, in the following structure:

\cache
\drafts
\media
\pages
\posts
\templates
\www
    \css
    \js
    \img

The config.php in the Second Crack folder I have changed to reflect this structure.

Code change

The update.php script in the Second Crack engine folder which triggers the blog update must be changed. A locking mechanism has been implemented in this file, but it does not work under Windows because the used PHP extension (POSIX) is not available.
Thefore the lines in update.php related to locking must be commented out. This is the following snippet as an example:

update.php
<?php
/*define('LOCK_FILE', isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '/tmp/secondcrack-updater.pid');

// Ensure that no other instances are running
...
    fwrite(STDERR, "Cannot write lock file: " . LOCK_FILE . "\n");
    exit(1);
}*/

$fdir = dirname(__FILE__);

This will disable all functionality related to locking. Now updating the blog is a matter of executing (assuming the php.exe is installed in c:\php\php.exe:

c:\php\php.exe c:\apps\secondcrack\engine\update.php

Leave a Comment

Mount SMB network folder in local folder on Windows

The mklink command is available in Windows since Windows Vista. It allows you to map a location as a subfolder on a NTFS file system. This behavior is comparable to the Linux ln alternative. SMB/CIFS network folders can also be mapped using this technique.

The command to do this is:

mklink /d C:\Folder\ShareName \\Server\ShareName\Directory\

The command explained:

  • /d is a flag that tells mklink to create a directory symbolic link instead of the default, a file symbolic link
  • C:\Folder\ShareName is the destination locate to map the network share to
  • \\Server\ShareName\Directory is the SMB network folder location to use as source A requirement is that the \\Server\ShareName\Directory location has been visited before and the credentials to access the share have been stored. Once the command has been executed the network folder is directly available at \\Server\Sharename.

Leave a Comment

Concatenate files under Windows

Recently I found the need two concatenate two javascript files in a build script under Windows. Using Linux concatenating two different files is easy using the cat command. It turns out that using Windows it is also trivial.

copy /b script1.js+script2.js combined.js

That’s it, really easy. The /b operator is added to let copy handle the files as binary files, for safety reasons.

If the destination file already exists, copy will prompt to overwrite. This prompt can be set to Yes by default by adding the /y option.

copy /b /y script1.js+script2.js combined.js

When combining files from different folders, e.g. ..\script1.js+.\htdocs\script2.js make sure you are using backslashes and not forward slashes in the path.

Leave a Comment