#!/usr/bin/Temikus

Nloc - Network Location Management for Alfred

| Comments

I use OS X network location functionality a lot, but switching them from the preferences or in CLI can be a bit tedious, so I made an Alfred workflow to make it fast and efficient.

This workflow allows to quickly change between network locations.

Usage:

nloc network_location_name

Script supports autocompletion of known network locations:

Download:
Up-to-date workflow bundles can be downloaded here.

NOTE: Due to changes in security policy on OS X 10.8, system will ask you for your password after executing the workflow.
OS X 10.7 system shouldn’t ask for your password since it doesn’t require the networksetup command to be executed with super user privileges.

Alfred V2 Octopress Plugin Update

| Comments

Alfred has recently updated to version 2.0. Workflow functionality has been nicely updated so I made adjustments to my extension as well. In this version a blog generate option has been added to the workflow to launch static pages generation from Alfred and notify you on completion.

Usage:
Set the OCTOPATH variable in the scripts to your octopress installation directory and EDITORAPP to your favourite editor.

Commands:

blog Awesome post
#Create a new blog post, named "Awesome article"

blog generate
#Launch static page generation via Jekyll.

Download:
You can get the updated extension here.

UPDATE 2013-04-21
Fixed the issue where rake could fail on non-standard characters.

UPDATE 2013-05-01
Added native Alfred notification support. terminal-notifier gem no longer required. Extended debugging added. Minor fixes.

MacOS X Server Push Notification Issues

| Comments

Today, one of our MacOS X servers running Snow Leopard stopped sending push notifications. The problem was a bit unusual, so I decided to share my notes on the issue.

I noticed that devices stopped receiving push notifications from this particular server and /var/log/system.log was stating connection errors:

3/9/13 5:20:52 PM   push_notify[76] notification server connect failed, will retry in 300 seconds

First, we need to check the physical connection to APNS servers:

telnet gateway.sandbox.push.apple.com 2195
Trying 17.172.233.66...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

If that is correct, we need to see if the certificates used by the server are correct. Let’s look at what the server is using for push notifications:

$ sudo serveradmin settings notification:sslKeyFile
notification:sslKeyFile = "/etc/certificates/server.example.com.PMESMFPWKKB2K09I6I8BTKJERP5K152ADN239GDX8.concat.pem"
$ sudo serveradmin settings notification:sslCAFile
notification:sslCAFile = "/etc/certificates/server.example.com.PMESMFPWKKB2K09I6I8BTKJERP5K152ADN239GDX8.chain.pem"

Now, let’s look at the server’s certificates:

$ ls -l /etc/certificates/server.example.com.*
-rw-r--r--  1 root  wheel      1245 Mar  9 15:26 /etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.cert.pem
-rw-r--r--  1 root  wheel      1245 Mar  9 15:26 /etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.chain.pem
-rw-r-----  1 root  certusers  2988 Mar  9 15:26 /etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.concat.pem
-rw-r-----  1 root  certusers  1743 Mar  9 15:26 /etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.key.pem

As you can clearly see from the output – there is no such certificate in the storage. All we have to do now is change the certificate to the correct one:

$ sudo serveradmin settings notification:sslKeyFile = "/etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.concat.pem"
$ sudo serveradmin settings notification:sslCAFile = "/etc/certificates/server.example.com.N3ZKL8CPVO96759Y38K22D682J3PNB3HA4DL9800J.chain.pem"

Then reboot, et voila! Push notification service works again!

P.S. If you have multiple certificates and don’t know which to select for APN service, you can find out the info about them using openssl:

find /etc/certificates -type f -name '*.cert.pem' | while read certificate; do openssl x509 -in $certificate -noout -text; done

Octopress Publishing With Alfred

| Comments

Creating new posts in octopress can be somewhat tedious, so I decided to automate it via Alfred.

This Alfred extension automatically creates a post and opens the markdown file for it in your editor of choice (it uses Mou by default).

Just open Alfred, add a new shell script extension and paste the following script in, setting the octopath variable to your octopress installation directory and ‘editorapp’ to your favourite editor.

Note: Make sure you uncheck the box next to Spaces under the Advanced tab in Alfred. Otherwise, spaces will be escaped and filenames will contain -slash- blocks.

Post to octopress via Alfredlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
#Path for your octopress installation
octopath=/path/to/your/octopress
#Editor to open the post in. (Exact name of the .app bundle in your Applications folder)
editorapp=Mou

if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then

      source "$HOME/.rvm/scripts/rvm"
fi

cd $octopath
rvm use 1.9.3@octopress
octopost=$(rake new_post["{query}"]| grep -o 'source/_posts/.*')
open -a "$editorapp" $octopath/$octopost

You can download the extension bundle here.

New SAMBA Daemon in MacOS X Lion

| Comments

Not that long ago I ran into a strange issue with one old MacOS X application. The issue is – it couldn’t get the NETBIOS hostname of the machine right. I checked the settings – they were all correct. Then, I looked in /var/db/smb.conf and noticed, that the hostname there was outdated and didn’t respond to settings.

Looking into Apple’s documentation on MacOS X Lion I found a note:

“smbd version has been updated to 3.0.28a-apple”

When I looked into manpages I found that the config files have been changed as well:

FILES
    /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist
          The primary configuration for the SMB stack. This file is
          updated by various system services and should not be edited by
          hand.
    /System/Library/LaunchDaemons/com.apple.smbd.plist
          The smbd service's property list file for launchd(8).

The issue was that Apple rolled out a proprietary replacement for the old SAMBA daemon, which is now using PLIST configuration files. The issue is, that some old applications are still looking in /var/db/smb.conf to get the NETBIOS name of the machine.

Here’s a step-by-step workaround to solve the issue:

1) Enter terminal as a super-user:

sudo -s

2) Create a backup of the legacy smb.conf:

mv /var/db/smb.conf /var/db/smb.conf.bak

3) Add a stub smb.conf file to be parsed by the app, getting the NetBIOS name from PLIST file:

netbiosname=$(/usr/libexec/PlistBuddy -c "Print NetBIOSName" /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist) && printf "[global]\nnetbios name = $netbiosname" > smb.conf

4) Give it the necessary permissions:

chmod 644 /var/db/smb.conf

5) Reboot the machine.

NetBIOS name of the machine should be picked up by the application shortly after.

Welcome to Temikus’ Blog 2.0!

| Comments

Welcome, dear reader.

I decided to move from my existing hosted solution on Squarespace to a static blog, generated using Octopress. This will hopefully allow me to write more often, as it’s far easier to import my notes in this environment.

I hope you will find my notes interesting and/or helpful.

Kind regards, Artem Yakimenko