-fix- Linux and Grub wait forever after a hypervisor ACPI shutdown.

This is a designed-in feature of grub – useful if you’ve got a physical machine in front of you, as the linux box won’t automatically restart if someone kicks the power cable out or hits the off switch – and more importantly it won’t endlessly reboot if there’s a hardware problem, slowly shredding your file systems.

If you’re running Ubuntu as a headless virtual machine in the cloud, it’s not so useful. Disable it like this:

edit /etc/default/grub and add the line:

GRUB_RECORDFAIL_TIMEOUT=3

then sudo update-grub.

Next time you accidentally “sudo ip route flush table all” on your vm and acpi-restart it,  it’ll boot properly.

 

 

 

 

Workaround -fix- for missing “import” folder after attaching archives in Mac Mail 6.x

Archive folders detached and disappeared.
Re-imported them from ~/Library/Mail/V2/Mailboxes/…

and found a nice workaround for the missing “import” folder problem you hit if you try to import nested folder hierarchies in one go:

Try to import .mbox files first – if you click on through, the import will proceed, but you’ll never see any “import” folder created.  However when you next open the import dialogue and choose “Mac Mail” instead of .mbox, you’ll be able to see the contents of the nested folders, and drill down to the individual mboxes themselves.  Import them one at a time, then drag them into a coherent archive structure once you’re done.

-fix- Android File Transfer “Can’t access Device Storage”

Open the Developer Options on your Jellybean i9300 and disable “Verify Apps by USB”

“Verify apps over usb — Allows you to disable app checks for sideloading apps over USB, while still checking apps from other sources like the browser. This can speed up the development process while keeping the security feature enabled.”

System: 10.9.2 / Foxhound 1.0 , but it should work with most other Jellybean variants.

ssh multiple identities -fix- “Too many authentication failures for { username }”

So; you regularly use ssh to connect to a few different hosts – using different private keys for each user/server combination.

Your  ~/.ssh/ directory already has a few named private keys in it – you add a couple, bring the total to 5 or more…

ls ~/.ssh/
dave_mars.id_dsa
sue_deimos.id_dsa
steve_deimos.id_dsa
irene_phobos.id_dsa
lee_phobos.id_dsa
sue_mars.id_dsa
red_deimos.id_dsa

….and try connecting:

ssh -i .ssh/sue_mars.id_dsa -l sue mars

You’re denied, with an error like:

Received disconnect from {mars' IP address} 2: Too many authentication failures for sue.

Which is confusing;  this may be the first time you’ve tried connecting to phobos with sue’s account.

Add the verbose switch to you ssh command:

ssh -v -i .ssh/sue_phobos.id_dsa -l sue phobos

You’ll see this at the end of the negotiation:

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/dave_mars.id_dsa
debug1: Authentications that can continue: publickey
 debug1: Offering RSA public key: .ssh/sue_deimos.id_dsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: .ssh/steve_deimos.id_dsa
debug1: Authentications that can continue: publickey
 debug1: Offering RSA public key: .ssh/irene_phobos.id_dsa
debug1: Authentications that can continue; publickey
 debug1: Offering RSA public key: .ssh/lee_phobos.id_dsa
Received disconnect from {phobos' IP address}: 2: Too many authentication failures for sue

Your local ssh agent is offering any key it can find, pre-loaded and cached from the .ssh directory (prove this caching by moving the other named keys somewhere else on your system – they’ll still be offered). The -i flag is a more of a guideline or hint to the agent.

To force the ssh client to offer only the key specified by -i, use the

-o IdentitiesOnly=yes

option:

ssh -o IdentitiesOnly=yes -i .ssh/sue_phobos.id_dsa -l sue phobos

or:

ssh -o "IdentitiesOnly yes" -i .ssh/sue_phobos.id_dsa -l sue phobos

…you’re connected.

 

Fix for Filemaker Pro 10 on OSX 10.8.5’s inability to “remote open” databases.

Clearing up some overdue updates (10.8.4>>5) on a couple of Mountain Lion machines, I came across this:

FIlemaker 10.03 opens with no apparent problem, creates and plays fine with local databases, but dumbly refuses to list any on a server in the same subnet.

Telnet to the server’s port 5003 worked and the server itself was visible in the “open remote” dialogue, but where the databases should’ve been – pure snowy-white #fff.

cat /var/log/system.log | grep filemaker

…gave a clue;

com.filemaker.messages[579]: 2014-01-15 15:56:20.302 +0000 [AttachThread_acd0fa28] ConstructORB() caught a CORBA INITIALIZE exception

exceptions relating to CORBA – indicating, as nothing else in the app had changed, that the client wasn’t talking to the server securely any more. “Certificates” I thought. To think is to -g-o-o-g-l-e- duckduckgo.

Sure enough, the internet provided and lead me on to a similar fix for Filemaker Pro 9.x on Mountain Lion – relating to an old, ppc-only OpenSSL library. The iMacs we were using *had* worked – but the certificates in use dated back to 2003. Replacing them with more recent certs and restarting Filemaker Pro gave an instant, solid connection to the databases on the server.

TL:DR;

Show Contents of the Filemaker Pro.app in /Applications, and replace the cert(s) with those from a more recent trial version (11 onwards):

/Applications/FileMaker Pro 10/FileMaker Pro.app/Contents/MacOS/root.pem

/Applications/FileMaker Pro 10/FileMaker Pro.app/Contents/MacOS/server.pem

Restart Filemaker.

 

Testing 2014

…let’s see if this looks as bad as the other posts…

No. It looks like the “featured” tag ID isn’t stored until there’s actually a tag with the name “featured” in the WP database.

Because clearly it’d be impossible to hard-code a check-on-fail-create routine into the theme-load… or is that bad practice? Probably. Perhaps they could ask or warn? Probably. But it’s free-as-in-beer, and I figured it out after a minute or two. Still…

Use USB installation media with a Virtualbox VM

So.
You want to create a Windows 7 virtual machine, on virtualbox, on your Mac.
Don’t ask why. The answer might include Visual Studio.
You have a sysprep’d Windows 7 USB drive full of installation extras, custom wim files… But the virtualbox GUI gives you no “boot from USB” option.

The workaround: Create a “stub” virtual disk file somewhere Virtualbox can read it that references the USB drive as a “raw” disk.

First, see what OSX thinks USB drive is called:
:~ username$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1000.1 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS osx 999.7 GB disk0s2
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: NO NAME *26.0 MB disk1
/dev/disk2
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *8.1 GB disk2

/dev/disk2

then create the vmdk:

VBoxManage internalcommands createrawvmdk -filename ~/test_usb_stub_disk2.vmdk -rawdisk /dev/disk2

Now attach the new stub disk to the same disk controller as the virtual machine’s main hard drive, using the next available SATA port (SATA Port 1 assuming the main drive is on SATA port 0 – if you don’t do this, removing your flash drive will make your VM unbootable and annoying to fix):

Screen shot 2013-07-10 at 18.37.49

…then start the virtual machine, clicking its pre-boot window immediately and using Function+F12 to open the boot menu which will give show you the virtual USB drive.

You should see the usual Windows installation prompts…

“Next >>”.

Switch between any installed php version in MAMP

By default, the MAMP’s free UI only lets you choose between php 5.3 and 5.4.
Developing and patching on hosting platforms that don’t or can’t install the latest version as soon as its available makes it useful to be able to choose *any* of the php versions MAMP makes available.

I could’ve just paid for MAMP Pro, but the pleasure of scripting it myself and revising sed and awk in the process couldn’t be missed.

First, awk the currently active php version from MAMP’s httpd.conf – splitting the matched line with a “/” delimiter:

awk -F '/'

then extracting the 6th “chunk”:

{ print $6 }

Then list the php version directories in the MAMP folder, using sed to erase the bits of the wide directory listing we don’t need, finally sorting the result in proper version order:

versionlist=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1n -k 2,2n -k 3,3n`

Full listing:

#!/bin/bash

# Get current php version
currentphp=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
 
# include the CocoaDialog app for Platypus' benefit.
CD="CocoaDialog.app/Contents/MacOS/CocoaDialog"
 
# Get the list of currently installed php versions in the MAMP hierarchy.
versionlist=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1n -k 2,2n -k 3,3n`
 
# Create the drop-down menu.
rv=`$CD dropdown --string-output  --text "The drop-down lists all php versions on this system. $currentphp is active. Which do you want to enable?" --items $versionlist --button1 "Ok"` 
 
# extract the version number from the drop-down result
chosen=`echo $rv | awk -F' ' '{ print $2 }'`
 
# Replace the decimal points with slashes
fixed=`echo $chosen | sed 's/\./\\\./g'` 
 
# Overwrite httpd.conf's existing php version with the new, chosen one.
sed -i 'BAK' -E "s/php5\.[0-9]{1,}\.[0-9]{1,}/$fixed/" /Applications/MAMP/conf/apache/httpd.conf
 
# Restart apache *gracefully*
/Applications/MAMP/bin/apache2/bin/apachectl graceful
 
# Re-check the current php version in httpd.conf *just in case*   
newphp=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
 
# ...and tell the user what the current version is. 
$CD ok-msgbox --no-cancel --text "$newphp is now enabled."

Bundling it into a simple [cmd][space] app with Platypus was as easy as including the CocoaDialog package and adding a few messages:

Screen shot 2013-06-11 at 17.25.16

Used in combination with my command line php version selector, I can test against any of 8 different php versions with minimum effort.

Execute scripts with different versions of php

There are several versions of php in my MAMP installation. I’ve built a script (appified with Platypus) that switches between them on the fly, but no elegant way to switch between them in a shell without *typing* redundantly.

So here’s a script to execute a standard .php file on the command line using any version of php on the system; actually any version just here:

/Applications/MAMP/bin/php/php5.*

Sample usage:

./phpVersionsExec -sv 3.2 -f factory_methods.php

The script accepts partial command line parameters, or runs interactively, or both if your command line is a little flaky. It tries to use sane defaults (reading the current php version from httpd.conf) and allows you to a useful combination of test file and php version… and at that point I stopped scripting before I’d reengineered Wheel v.1.0.

#!/bin/bash

# Functions are defined

usage(){
    echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    echo "* Usage:"
    echo "$0 [-f lf | filename.php] [-v {sv | hc | php{ n | n.n | n.n.n} }] | [-i] "
    echo "*"
    echo " -i                        - interactive mode."
    echo " -s                        - store php version and filename as defaults."
    echo " -f filename.php           - use filename.php"
    echo " -f lsd                    - use last-stored default filename."
    echo " -v lsd                    - use last-stored default php version."
    echo " -v chc                    - use current httpd.conf php version."
    echo " -v p -f index.php         - use highest version of php on the system."
    echo " -v 5 -f index.php      - use highest version of php 5."
    echo " -v 5.3 -f index.php    - use highest version of php 5.3 if available."
    echo " -v 5.3.20 -f index.php - use php 5.3.20 if available."
    echo "*"
    echo "* The script stores its 'default' php version (-v sd) and last file used (-f lf) in ~/.phpVersionExec.ini."
    echo "*"
    exit 1
}
 
initialiseDefaults() {
    # Set store-in-ini-file flag to false 
    storeDefaults=
 
    # Set goInteractive flag to false 
    goInteractive=
 
    # Set found-your-php-version flag to false 
    phpVersionExists=
 
    # Read all versions of php in MAMP folder hierarchy.
    installedPhpVersions=`ls -d /Applications/MAMP/bin/php/php5.* | sed 's/\/Applications\/MAMP\/bin\/php\///g' | sort -t. -k 1,1rn -k 2,2rn -k 3,3rn`
 
    # Read defaults from ini file if present.
    if [ -f ~/.phpVersionExec.ini ]; then
	a=0
	while read line
	do a=$(($a+1));
	    case "$a" in
		1) iniPhpVersion=$line;;
		2) iniPhpFile=$line;;
	    esac;
	done < ~/.phpVersionExec.ini
    fi
 
    # Read current MAMP default php version from httpd.conf  
    httpdConfPhpVersion=`awk -F '/' '/LoadModule php5_module/ { print $6 }' /Applications/MAMP/conf/apache/httpd.conf`
}
 
storeTheDefaults() {
    # Store last exec'd phpVersion and phpFile
    echo "Storing defaults:" 		    
    echo "$execPhpVersion" > ~/.phpVersionExec.ini
    echo "$phpFile" >> ~/.phpVersionExec.ini
    cat ~/.phpVersionExec.ini
}
 
execPhp () {
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* Chosen php version is $execPhpVersion"
		echo "*"
		echo "* Running command: /Applications/MAMP/bin/php/$execPhpVersion/bin/php -d display_errors=On -c /Applications/MAMP/bin/php/$execPhpVersion/conf/ -f $phpFile"
		echo "*"
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* PHP output begins:"
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		/Applications/MAMP/bin/php/$execPhpVersion/bin/php -d display_errors=On -c /Applications/MAMP/bin/php/$execPhpVersion/conf/ -f $phpFile
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		echo "* PHP output ends."
		echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
		if [[ $storeDefaults ]] ; then
		    storeTheDefaults
		fi
		exit 0
}
 
main() {
        # Use the last-stored-default php version or current Httpd.conf php version
	case $phpVersion in
	    lsd) phpVersion=$iniPhpVersion;;
	    chc) phpVersion=$httpdConfPhpVersion;;
	esac
 
        # Use the last-stored-default filename
	if [ $phpFile = "lsd" ]; then
	    phpFile=$iniPhpFile
	fi
 
        # Make sure the file exists - if not, go interactive.
	if [ ! -f $phpFile ]; then
	    	echo "The file selected - $phpFile - doesn't exist."
		interactive
	fi;
 
        # If the finally selected phpVersion is one of those currently in the MAMP stack... use it.
	for z in $installedPhpVersions; 
	do 
		if grep --quiet $phpVersion <<< $z; then
			execPhpVersion=$z
			phpVersionExists=true
			execPhp
		fi;
	done
 
        # If the finally selected phpVersion ISN'T one of those currently in the MAMP stack... get interactive.
	if [[ ! $phpVersionExists ]]; then
	    echo "Couldn't parse $phpVersion as an installed php version."   
	    interactive
	fi
}
 
interactive() {
	echo "Enter as accurate a php version as you need:"
        if [ ${#phpVersion} -gt 0 ]; then
	    echo " - ENTER for already-entered $phpVersion"
	    echo " - chc for httpd.conf php version: $httpdConfPhpVersion"
	else
	    echo " - ENTER for httpd.conf php version: $httpdConfPhpVersion"
	    phpVersion=$httpdConfPhpVersion
	fi
	echo " - lsd for Last Stored Default: $iniPhpVersion"
	echo " - N, N.N or N.N.N to select an installed php version:"
	echo "$installedPhpVersions"
	read interactivePhpVersion
	if [ ${#interactivePhpVersion} -gt 0 ]; then
	    phpVersion=$interactivePhpVersion
	else
	    echo "Defaulting to: $phpVersion"
	fi
 
	echo "Enter the php file you want to execute:"
	if [ ${#phpFile} -gt 0 ]; then
	    echo " - ENTER for already-entered $phpFile"
	    echo " - lsd for Last Stored Default: $iniPhpFile"
	else
	    echo " - ENTER for Last Stored Default: $iniPhpFile"
	    phpFile=$iniPhpFile
	fi
	read interactivePhpFile
	if [ ${#interactivePhpFile} -gt 0 ]; then
	    phpFile=$interactivePhpFile
	else
	    echo "Defaulting to $phpFile"
	fi
 
	main
}
 
# BEGIN 

initialiseDefaults
 
# Check and store any given options.
while getopts "sihv:f:" opt
do
        case "$opt" in
        v) phpVersion=$OPTARG;;
        f) phpFile=$OPTARG;;
        h) usage;;
        \?) usage;;
	s) storeDefaults=true;;
	i) goInteractive=true;;
        esac
done
 
 
# If goInteractive is true, go straight to interactive mode.
if [ $goInteractive ] ; then
        interactive
fi
 
# If exactly four arguments are given, go straight to main() initally bypassing the interactive mode.
if [ $# -eq 4 ] ; then
        main
fi
 
# If a strange number of arguments are given, display the help.
usage