NTFS BitLocker Access on macOS 10.13 High Sierra

Mac OS X No Comments

I had a flash drive with important info that I needed to access. Unfortunately, I only had a Mac computer and the flash drive was protected by Windows BitLocker encryption.

A quick google pointed me at “M3 Bitlocker Loader for Mac”, which looked to be free. Unfortunately, it was not. The utility mounted the flash drive, prompted me for a password, and unencrypted the drive successfully. I was able to see the files but when I attempted to read or copy, the utility said that I needed to buy it for $40. Kinda expensive but if someone is desperate….

Thankfully there is a free solution called “Dislocker fuse”. Installation is easy using the HomeBrew package manager. Below are the steps I took to mount the flash drive.

Install “Dislocker fuse”

  1. Install Xcode from the Mac App Store.
  2. Install the “Xcode Command Line Tools” by running this command in the “Terminal.app”:
    xcode-select --install

    Note: If you skip this step, the Homebrew installation will install multiple versions of the “Xcode Command Line Tools” (for different OS and Xcode versions) and then hang.

  3. Install Homebrew:
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  4. Install Fuse for macOS (which Dislocker requires):
    brew cask install osxfuse
  5. Reboot the Mac to ensure that “Fuse for macOS” is fully installed.
  6. Install Dislocker:
    brew install dislocker

Mount and Decrypt the Flash Drive

  1. Plug your USB flash drive into the Mac. Click the Ignore button on the “The disk you inserted was not readable by this computer” dialog box.
  2. Get the identifier for the BitLocker partition on the flash drive:
    diskutil list

    /dev/disk2 (external, physical):
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:     FDisk_partition_scheme                        *61.9 GB    disk2
       1:               Windows_NTFS                         61.9 GB    disk2s1

    Note: The identifier for my flash drive partition (shown on far right above) is “disk2s1”. If you don’t use the correct identifier, you will get a “The signature of the volume (м) doesn’t match the BitLocker’s ones (-FVE-FS- or MSWIN4.1)” error when attempting to unlock the BitLocker partition below.

  3. Unlock and mount the partition:
    # Unlock the BitLocker partition to a Dislocker virtual partition file
    sudo dislocker -v -V /dev/disk2s1 -r -uPASSWORD /tmp/mydrive

    # Mount the unlocked virtual partition
    sudo hdiutil attach /tmp/mydrive/dislocker-file -imagekey diskimage-class=CRawDiskImage -mountpoint /Volumes/mydrive

    Notes:
    – Replace PASSWORD with your password. Make sure to escape any special characters like exclamation mark with a backslash (ex: “secret\!”).
    – The “-r” flag passed to Dislocker allows only read-only access. When I omitted the flag to get read-write access, the dislocker command failed.

  4. Later, unmount the drive by doing the following:
    # Unmount the unlocked virtual partition
    sudo hdiutil detach /Volumes/mydrive

    # Release the virtual partition
    sudo hdiutil detach /tmp/mydrive

Info above gotten from Open Bitlocker USB stick on OS X.

No Comments

Re-install MacPorts After MacOS Upgrade

Mac OS X No Comments

I upgraded from Mac OS X 10.10 Yosemite to macOS 10.12 Sierra. After that, any MacPorts command I ran returned the following error:

Error: Current platform "darwin 16" does not match expected platform "darwin 14"
Error: If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration
OS platform mismatch
    while executing
"mportinit ui_options global_options global_variations"
Error: /opt/local/bin/port: Failed to initialize MacPorts, OS platform mismatch

The problem is that MacPorts is specific to a Mac OS X platform. The best way to fix this problem is to follow the Migrating a MacPorts installation guide.

Totally Clean Slate

MacPorts migration provides a “restore_ports.tcl” script to restore all the ports (a.k.a. packages) once you have upgraded MacPorts. However, I decided to start from a clean slate and only install ports as I needed them.

# Save list of installed ports (FYI for myself)
port -qv installed > ~/ports_installed.txt

# Save list of ports you manually installed (exclude dependency ports)
port installed requested > ~/ports_requested.txt

# Uninstall all installed ports
sudo port -f uninstall installed

# Clean any partially-completed builds
# Remove leftover build files (this should be done automatically already)
sudo rm -rf /opt/local/var/macports/build/*

# Remove download files
sudo rm -rf /opt/local/var/macports/distfiles/*

Note: I noticed that executables like svn (from subversion port) were left behind in /usr/bin and could still be used.

Partially Clean Slate

If you decide to keep your existing ports and to use the “restore_ports.tcl” script, you might consider cleaning out inactive packages:

# Get list of inactive ports you likely no longer need
# Alternative command: port echo inactive
port installed inactive

# Remove all of the inactive ports
sudo port uninstall inactive

Install macOS-specific MacPorts

Install the latest MacPorts for your macOS version:

  1. Install or upgrade to the latest version of Xcode Developer Tools (free from the Mac’s App Store) and run it once.
  2. Install the latest Command Line Developer Tools by running this command in the Terminal app:
    xcode-select --install
  3. Download and install the MacPorts package matching your Mac OS X version. It will overwrite the existing MacPorts installation.

Update MacPorts Configuration

The new MacPorts installer won’t modify the existing configuration file so you will need to update it manually. The updated configuration file “macports.conf.default” is located in the “/opt/local/etc/macports” directory. The old configuration file “macports.conf” is also in the same location.

Before overwriting the old file with the new, I recommend doing a file comparison:

cd /opt/local/etc/macports/
diff macports.conf macports.conf.default

Note: If you prefer a nice graphical user interface, you can use the FileMerge application which comes with Xcode. Just run FileMerge and input the paths to the two files to compare them.

There wasn’t any significant difference between the two files (beyond comments), but I went ahead and overwrote the old one with the new.

cd /opt/local/etc/macports/
sudo cp macports.conf.default macports.conf

Note: There are two other MacPorts configuration files, “variants.conf” and “sources.conf”, which the migration guide doesn’t mention. I compared them anyways and the only significant difference I found was in the “sources.conf” where the “rsync” value was different. I overwrote the “sources.conf” with the latest to ensure that everything is updated.

If you didn’t do a totally clean slate, you will want to follow the migration instructions on how to run the “restore_ports.tcl” script.

Some info above derived from:

No Comments

Install macOS Sierra Using Bootable USB Flash Drive

Mac OS X No Comments

To perform a clean installation of macOS Sierra (basically, Mac OS X 10.12), I recommend using a bootable USB flash drive containing the macOS Sierra installer. Below are the steps I took to create the bootable USB flash drive and how I used it to install macOS Sierra.

Note: The macOS Sierra Disk Utility and installer appears to be more buggy and much slower than previous versions. The best advice for installing macOS Sierra is to try again and be very patient (if you expect an operation to complete in 5 minutes, then give it at least 50 minutes).

Download macOS Sierra Installer

The macOS Sierra installer is available from the Mac App Store. Run the “App Store” application, search for “macOS Sierra”, and download it. It will save the installer as an “/Applications/Install macOS Sierra.app” file (about 4.97GB in size).

Note: If you run the macOS Sierra installer to upgrade your Mac, the downloaded file will be deleted automatically after the upgrade is completed. To keep that file, you will want to move it out of the Applications folder so it won’t be deleted after an upgrade. Launch the “Terminal” application and run this command to move the downloaded installer to your user’s “Downloads” folder:

sudo mv /Applications/Install\ macOS\ Sierra.app/ ~/Downloads/

If you are paranoid (doesn’t hurt), you can verify that the installer file was downloaded correctly by verify its checksum. Run the “Terminal” application and this command:

hdiutil verify /Applications/Install\ macOS\ Sierra.app/Contents/SharedSupport/InstallESD.dmg

# If successful, the last output line should read:
# hdiutil: verify: checksum of "/Applications/Install macOS Sierra.app/Contents/SharedSupport/InstallESD.dmg" is VALID

Format USB Flash Drive

The macOS Sierra installer takes up 5.1GB of space on the USB flash drive, so you will need a flash drive with a capacity of 8GB or greater.

Note: If the flash drive is mounted under “/Volumes” successfully when you plug it in, you can skip the following steps to reformat the flash drive. This is because the script we run to create the bootable drive will reformat the flash drive as an initial step. Because I am paranoid, I recommend reformatting the USB flash drive manually anyhow.

Format the USB flash drive using these steps:

  1. Plug in the USB flash drive to your Mac.
  2. Launch the “Disk Utility” application.
  3. On the left-hand pane, select the USB drive (not the partition under it, if any).
  4. Click on the “Erase” tab (or button at the top).
    1. Input a name like “Sierra” (this name will be overwritten later).
    2. Select “Mac OS Extended (Journaled)” for “Format”.
    3. Select “Master Boot Record” for “Scheme”.
    4. Click the “Erase…” button at the bottom. Click the “Erase” button in the warning popup dialog if you get one.
      • The format operation may take several minutes to complete. (USB 2.0 and large capacity drives will take longer.) After the format completes, the partition will be mounted under “/Volumes/Sierra” (or whatever name you selected above).
      • Note: Under macOS Sierra, the Erase function will fail if the USB drive’s partition is mounted. You can manually unmount the partition before running Erase. Or you can run Erase twice; the first time will unmount the partition and fail, and the second time will actually do the format (which will succeed).
  5. Close the “Disk Utility” application.

Create Bootable USB Flash Drive Installer

To create the bootable USB macOS Sierra installer, run the “Terminal” application and this command:

# The --volume value is the mounted USB flash drive partition; in this case, named /Volumes/Sierra

sudo /Applications/Install\ macOS\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/Sierra --applicationpath /Applications/Install\ macOS\ Sierra.app --nointeraction

# You will be prompted for your user's administrative password.

The “createinstallmedia” program will erase the USB flash drive, create a new partition named “Install macOS Sierra”, and copy the installation files to that partition. The output will look like:

Erasing Disk: 0%... 10%... 20%... 30%...100%...
Copying installer files to disk...
Copy complete.
Making disk bootable...
Copying boot files...
Copy complete.
Done.

The program will pause at the “Copying installer files to disk…” output line above. This step took 20-30 minutes with my Kingston 16GB USB 2.0 flash drive. Yours may take a shorter or longer time. I recommend giving it at least an hour, maybe two, before giving up.

Note: Mac hardware is very finicky about USB flash drives. Initially, I used a Corsair 32GB USB 3.0 drive; however, when I held down the Option key to try to boot with it, the Mac would freeze with a black startup screen. The Kingston 16GB USB 2.0 drive did not have this problem. So if you enounter issues (when erasing and copying) or weirdness (when booting), consider changing to another brand of USB flash drive. If you don’t have another drive, consider at least testing the flash drive to make sure it is not bad or corrupted (“First Aid” in “Disk Utility” is the minimum; google for more powerful tools).

Boot With USB Flash Drive

Note: I recommending connecting the Mac to its AC power adapter before beginning the macOS Sierra installation. The installation may take a long time (an hour or more) and you don’t want the battery to die in the middle.

To boot a Mac with the USB flash drive:

  1. Shutdown the Mac.
  2. Insert the USB flash drive.
  3. While holding the “option/alt” key down, turn on the Mac to display the boot Startup Manager.
  4. You should see one or more icons, one of which should be called “Install macOS Sierra” for the USB flash drive. (The internal hard drive may not be visible if it does not have a valid, bootable partition installed.)
    • Note: If you don’t see the USB flash drive’s “Install macOS Sierra”, try removing and re-inserting the USB flash drive while viewing the Startup Manager screen. The USB flash drive should then appear after a few seconds.
  5. Select the “Install macOS Sierra” (with left/right arrow keys) and hit the “return/enter” key to boot from the USB flash drive.

It may take 5-10 minutes or longer to load the installer from the USB flash drive. Sometimes the progress bar may appear to be frozen… just be patient. I would give it at least 30-60 minutes to load before giving up.

Format the Hard Drive

When the installer finishes loading, you will see a “macOS Utilities” window appear. Do the following to format the internal hard drive:

  1. Click on the “Disk Utility” option and click the “Continue” button on the bottom to launch the “Disk Utility” application.
  2. On the left-hand pane, select the hard drive (not the partition under it, if any).
  3. Click on the “Erase” button at the top.
    1. Input a name like “macOS”.
    2. Select “Mac OS Extended (Journaled)” for “Format”.
    3. Select “GUID Partition Map” for “Scheme”.
    4. Click the “Erase…” button at the bottom.
      • For SSD (Solid State Drive), the format operation may take less than a minute to complete. For mechanical hard drive, it may several minutes to hours, depending upon the size, speed, and condition of your hard drive.
      • Note: Again, the Erase function will fail if the hard drive’s partition is mounted. You can manually unmount the partition before running Erase. Or you can run Erase twice; the first time will unmount the partition and fail, and the second time will actually do the format (which will succeed).
  4. Close the “Disk Utility” application.

Note: Now and then, I noticed the output of the Erase seems to erroneously double the size of the hard drive. For a 128GB hard drive, the graph shows 120.88GB macOS (in blue) and 120.37 GB Unformatted (in red). I think it is just a user interface bug because when I close Disk Utility and re-open it, the graph then only shows the 120.88GB macOS (in blue).

Install macOS Sierra

Back at the “macOS Utilities” window, do the following to begin the macOS Sierra installation process:

  1. Click on the “Install macOS” option and click the “Continue” button.
  2. The “macOS Sierra” installer’s splash screen will appear. Click the “Continue” button.
  3. Click on the “Agree” button to agree to the license. A popup confirmation window will appear; click on the popup’s “Agree” button.
  4. Select the hard drive and click the “Install” button.

Note: You may encounter strange hardware behavior. On my 13 inch Macbook Pro Retina, the macOS Sierra installer turned the fan on to maximum for the whole duration of the installation. Thankfully, once it finished and rebooted, the fan turned off and stayed off.

The macOS Sierra installer tries to be helpful by telling you how long it will take. Unfortunately, it lies. You should take whatever remaining time it tells you and multiple by 10 (for minutes) or 100 (for seconds). If it says “6 minutes remaining”, that could mean 60 minutes or one hour remaining. Worse, if it says “6 seconds remaining”, you may be staring at that message for 600 seconds or one hour.

The best solution is to be patient. Go grab a bite to eat and watch a movie. Take a long nap or better yet, sleep your 8 hours. I would wait at least 4 hours before giving up.

Note: You can display the installer’s log window (using the menu or pressing Cmd+L). I didn’t find this helpful at all. Even for a successful install, numerous errors are logged; I don’t know what is a critical or non-critical error. And often, you won’t see a progress/status log output for a long time, easily 20-30 minutes. Not seeing any new log statements does not mean that the installer froze. So the logs didn’t do anything for me.

What Does Giving Up Mean?

Giving up means you have accepted defeat. The next step is to retreat and try again. Some suggestions on how to proceed:

  • Reset your Mac by doing the following:
    1. Reset the SMC (see step 3 under the “Reset the SMC on Mac notebook computers” section).
    2. Reset the NVRAM (aka PRAM).
    3. Run the Apple Hardware Diagnostic or Test to make sure you don’t have a hardware failure.
    4. Finally, retry the macOS Sierra install.
  • Use a different USB port on the Mac.
  • Use another brand of USB flash drive.
  • Delete and re-download the macOS Sierra installer (especially if you downloaded it a long while ago). Even if the checksum is okay, you may want to re-download in case there is a newer version of the installer with a bug fix for your very problem.
  • Download an older Mac OS X version, say Mac OS X 10.11 El Capitan, install that, and then upgrade to macOS Sierra. If you know the Mac OS X version which came with your Mac originally, consider downloading (if you still have access) and installing that version first.
  • Use the Mac Recovery System to download and install the original OS version that came with your Mac. Then upgrade from that to macOS Sierra.
  • Buy a more recent model Mac (at most a couple of years old). It may be that your current Mac is too old or slow to support macOS Sierra. It’s okay to keep running an old Mac OS version. (For example, if I had a Core 2 Duo Mac, I would not run anything later than Mac OS X 10.9 Mavericks on it.)

Hopefully, this post will help you to do a fresh installation of macOS Sierra.

Some info above taken from:

No Comments

Node.js Express with Nginx Reverse Proxy and Cache

Mac OS X No Comments

As a web developer, have you ever asked yourself whether to use a period or a plus sign to concatenate two strings? The former is used by PHP and the latter by Javascript. If you switch between the frontend Javascript and the backend PHP languages often, you’ll find yourself asking this and other syntax questions.

nodejs-logoNode.js eliminates that problem by supporting the use of Javascript in the backend. It is a Javascript runtime that replaces the PHP backend. However, using Javascript for both frontend and backend is not the best reason to migrate to Node.js. You will want to use Node.js because of the Node Package Manager (NPM). NPM makes finding, sharing, and reusing Javascript code packages a breeze. When implementing a backend function, the first step to take is to search for an NPM package that provides that function already.

Node.js Express is a simple but powerful Node.js web application framework. We’ll use it as the backend to serve web pages. While Express can serve static files, Nginx is much faster at that task and provides many other benefits.

Using Nginx as a reverse proxy (browsers query Nginx which then calls Express) and cache for Express provides the following benefits:

  • Nginx is built as a high performance server with many optimizations. It can handle many concurrent connections and can perform load balancing. Nginx can serve (or cache and serve) static files like HTML, javascript, images, and CSS more efficiently than Node.js.
  • As the point of entry, Nginx provides better security because it is an older, proven web server solution. Nginx supports both the older SSL/TLS and newer HTTP/2 protocols.
  • Nginx can be used for port 80 and 433 binding to avoid having to run Node.js as a root user, which is bad practice and possible vulnerability. (Under Unix, the first 1024 ports require root privileges to bind to.)

Below are the steps I took to setup Node.js and configure a Nginx reverse proxy and cache. Though I’m doing the steps below on Mac OS X 10 Yosemite, the Node.js code and Nginx configuration should be applicable to other platforms.

Install Node.js

We will install Node.js using MacPorts. Launch the Terminal app and run these commands:

# Node.js uses python scripts; python 2.7 is included with Mac OS X since v10.8
python --version

# Install Node.js
sudo port install nodejs
node -v

# Install Node Package Manager
sudo port install npm
npm -v

# Create a project directory
mkdir myproject
cd myproject
mkdir static

# Create a NPM project package.json file
npm init

# Install Express package
npm install express --save

The “npm init” command will prompt for the project name, version, and description in order to generate a “package.json” file. You can accept the defaults and edit the “package.json” file later.

The “npm install express –save” command will download the Express package to a node_modules subdirectory. The optional “–save” flag will add the Express package and its version as a dependency in the “package.json” file. (The alternative “–save-dev” flag will save the package as a development dependency instead.)

The benefit of the above is that you can give the “package.json” file to another developer and they can run the “npm install” command to install the specific versions of all dependent packages (as listed in the “package.json”).

Express Server

Create a a file named “server.js” with the following content:

// Require Express package
var express = require('express');

// Create an Express app
var app = express();

// Serve static files from static dir
app.use(express.static('static'));

// Handle get on root / request
app.get('/', function (req, res) {
  res.send('Hello World!');
});

// Bind to port 8080
var server = app.listen(8080, function () {
  var port = server.address().port;
  console.log('Listening on port %s', port);
});

To test, do the following:

  1. Put an image file, say “earth.gif”, under the static subdirectory.
  2. In a Terminal window, launch the server with this command:
    node server.js
  3. Browse to http://localhost:8080/ and you will see a “Hello World!” response.
  4. Browse to http://localhost:8080/earth.gif to see the static image file.
  5. In the Terminal window running Node.js, press Ctrl-C to quit.

Instead of using the “node server.js” command, you can use the “npm start” command. If you look inside the “package.json” file, you will see that there exists a script target named “start” which runs the “node server.js” command.

Install Nginx

Install Nginx with this command:

sudo port install nginx

The Nginx configuration file is located at “/opt/local/etc/nginx/nginx.conf”. The default document root is set to “share/nginx/html”, which maps to the “/opt/local/share/nginx/html” directory.

You can start, reload, and stop Nginx using these commands:

# Start Nginx
sudo port load nginx

# Reload the config (actually restarts)
sudo nginx -s reload

# Stop Nginx
sudo port unload nginx

# Check to see if Nginx is running
ps -e | grep nginx

While Nginx is running, browse to http://localhost/ to see the Nginx welcome page.

If you need to troubleshoot, the Nginx error log file is located at “/opt/local/var/log/nginx/error.log”.

Nginx Reverse Proxy

When Nginx proxies a request to Node.js, it will optimized the request headers it receives from the client:

  • Nginx gets rid of any empty headers from the proxied request.
  • Nginx considers any header names with underscores as invalid. It will remove them. If you wish to preserve these headers, set the Nginx “underscores_in_headers” directive to “on”.
  • The “Host” header is re-written to the value defined by the $proxy_host variable. This will be the IP address or hostname and port number of the upstream, as defined by the “proxy_pass” directive.
  • The “Connection” header is changed to “close” to indicate to the upstream server that this connection will be closed once the original request is responded to.

Configure the Nginx reverse proxy by running “sudo nano /opt/local/etc/nginx/nginx.conf” and making the following changes to the root location:

    server {
        # ...

        # Helpful headers to pass to Node.js
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme; #http pr https
        proxy_set_header X-Real-IP $remote_addr; #client IP address
        # List of IP addresses client has been proxied through until now
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
            #root   share/nginx/html;
            #index  index.html index.htm;

            proxy_pass http://localhost:8080;
        }

Reload the Nginx config with the “sudo nginx -s reload” command. Browsing to http://localhost/ will now show the Node.js “Hello World!” message, instead of the Nginx welcome page.

By default, the “Host” header is set to “$proxy_host”, which is the upstream hostname or IP address and port defined in the “proxy_pass” definition. In the above, we have overridden it to be “$host” which is set to, in order of preference: the hostname from the request line itself, the optional “Host” header from the client request, or the server name matching the request. This is a best practice for Nginx and ensures that the “Host” header passed to the proxied server is as accurate as possible.

Note: The headers sent by the client are available in Nginx as variables. The variables start with an “$http_” prefix, followed by the header name in lowercase, and with any dashes replaced by underscores. So the client “Host” header is available in Nginx as “$http_host”.

If you wish to reverse proxy a non-root path location, use this Nginx location configuration:

        location /proxy/ {
            # Ending slash prevents passing /proxy/ path to Node.js
            proxy_pass http://localhost:8080/; # Ending slash required!
        }

Browse to http://localhost/proxy/ to test.

Nginx Serves Static Files

If Nginx has access to the Node.js project directory (for example, “/Users/myuser/myproject”), it is best to configure Nginx to serve the static files directly.

Run “sudo nano /opt/local/etc/nginx/nginx.conf” and add the following “/static/” location:

        location /static/ {
            root /Users/myuser/myproject; # Node.js project location
            expires 30d; # Cache-Control: client cache valid for 30 days
        }

Browse to http://localhost/static/earth.gif to test.

The “expires 30d” command adds a “Cache-Control” response header telling the browser client to only cache the static resource for 30 days maximum. Install Curl and dump the response header to see the “Cache-Control” value:

# Install Curl
sudo port install curl

# Run Curl to dump response headers
curl -X GET -I http://localhost/static/earth.gif
    # Cache-Control: max-age=2592000

Unfortunately, the above solution requires the URL to contain the “/static/” path. One workaround to avoid the “/static/” path is to have Nginx serve static files with specific extensions like so:

        # location ~* means to use case-insensitive match
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|bmp|js|html|htm)$ {
            root /Users/chvuong/nodejs/static;
            expires 30d;
        }

Because Node.js returns “Cache-Control” with an immediate expiration, we can verify that Nginx is serving the static file by doing the following:

# Get static image file from Nginx
curl -X GET -I http://localhost/earth.gif
    # Cache-Control: max-age=2592000

# Get static image file directly from Node.js
curl -X GET -I http://localhost:8080/earth.gif
    # Cache-Control: public, max-age=0

If we use Node.js to provide APIs only, we can configure Nginx to return static files only if they exist. Because API paths don’t usually correspond to existing directories and/or static files, Nginx will pass the API calls to Node.js. Here’s the Nginx configuration to use:

        location / {
            root /Users/chvuong/nodejs/static;
            expires 30d;

            # Return static file if exist; otherwise pass to Node.js            
            try_files $uri @nodejs;
        }

        location @nodejs {
            proxy_pass http://localhost:8080;
        }

Please remove or comment out the previous “location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|bmp|js|html|htm)$” block because it will interfere with the above configuration.

Test using the Curl commands above to get the “earth.gif” static file. You can also edit “server.js” to remove or comment out the line below to prevent Node.js from serving static files:

// Serve static files from static dir
//app.use(express.static('static'));

Nginx Cache

If Nginx does not have access to the static files (for example, Nginx is running on another server), you can configure Nginx to cache the static files returned by Node.js. If the browser client requests a static file which is already cached, Nginx will return it without having to request that file from Node.js again.

Run “sudo nano /opt/local/etc/nginx/nginx.conf” and add the following cache configuration:

http {
    # ...

    # Cache for static files
    proxy_cache_path /tmp/nginx-cache levels=1:2 keys_zone=staticcache:8m max_size=100m inactive=60m use_temp_path=off;
        # keyzone size 8MB, cache size 100MB, inactive delete 60min
    proxy_cache_key "$scheme$request_method$host$request_uri";
    proxy_cache_valid 200 302 60m; # cache successful responses for 60 minutes
    proxy_cache_valid 404 1m; # expire 404 responses 1 minute

    server {
        # ...

        location / {
            proxy_pass http://localhost:8080;
        }

        # Only cache static files; don't cache the dynamic API response!
        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|bmp|js|html|htm)$ {
            proxy_cache staticcache; # Use "staticcache" we defined above
            proxy_cache_bypass $http_cache_control; # Support client "Cache-Control: no-cache" directive
            add_header X-Proxy-Cache $upstream_cache_status; # Hit or Miss

            # Nginx cache to ignore Node.js default "Cache-Control: public, max-age=0"
            # and don't pass it on to clients
            proxy_ignore_headers Cache-Control;
            proxy_hide_header Cache-Control;
            expires 60m; # "Cache-Control: max-age=3600" tells client to cache for 60 minutes

            proxy_pass http://localhost:8080;
       }

Caveats:

  • Double-check that “server.js” is configured to serve static files:
    // Serve static files from static dir
    app.use(express.static('static'));
  • Nginx will create the “/tmp/nginx-cache” directory because “/tmp” allows write access to everyone. If you change the cache directory location, please make sure to manually create the necessary directories. You will see an error in the Nginx error log if Nginx can’t create or access the cache directory.

You can test the cache by using Curl and taking note of the “X-Proxy-Cache” response header:

# First try will result in cache miss
curl -X GET -I http://localhost/earth.gif
    # X-Proxy-Cache: MISS

# Second try will result in cache hit
curl -X GET -I http://localhost/earth.gif
    # X-Proxy-Cache: HIT

If you wish to cache a non-root path location, use this Nginx location configuration:

        location /proxy/ {
            proxy_pass http://localhost:8080/; # Ending slash required!        
        }

        # Match string changed to capture path after /proxy/
        location ~* ^/proxy/(.+\.(jpg|jpeg|gif|png|ico|css|bmp|js|html|htm))$ {
            proxy_cache staticcache;
            proxy_cache_bypass $http_cache_control;
            add_header X-Proxy-Cache $upstream_cache_status;

            proxy_ignore_headers Cache-Control;
            proxy_hide_header Cache-Control;
            expires 60m;

            # Pass captured path string without /proxy/ to Node.js
            proxy_pass http://localhost:8080/$1;
        }

Nginx Load Balancing

Once you have Nginx reverse proxy working, load balancing is very simple. Here’s the Nginx load balancing configuration:

http {
    # ...

    # Node.js servers for load balancing
    upstream nodejs-backend {
        least_conn; # Give new connection to backend with least active connections
        localhost:8080;
        nodejs2.example.com; # default port 80
        nodejs2.example.com:8080;
    }

    server {
        # ...

        location / {
            # Pass to the upstream name, instead of the specific nodejs hostname
            proxy_pass http://nodejs-backend;
        }

I only tested the above with one Node.js server in the upstream definition (because I only have one server). It worked for one server and it should work for more.

Most info derived from:

No Comments

Setup LAMP (Linux, Apache, MySQL, PHP) on Mac OS X 10.10 Yosemite

Mac OS X No Comments

I downloaded a HTML5 and Javascript demo. When I attempted to browse to it, I encountered the infamous “XMLHttpRequest cannot load file:///” error.  The latest Chrome (and other modern browsers) won’t allow cross domain (a.k.a. cross origin) communication, which would occur when a page from one website domain attempts to read data from another domain.   The demo Javascript code was attempting to read a text file in the same file location using GET, but the local “file:///” protocol was not recognized as a proper website domain and Chrome assumed it was a cross domain security violation.

The only certain solution to the above problem is to run a local web server to host the demo code.  I have a previous post on setting up Apache on Mac OS X (Install Apache, PHP, MySQL, and phpMyAdmin on Mac OS X 10.6 Snow Leopard) which looks to be helpful, but it was outdated.  I have adjusted the instructions for Mac OS X 10.10 Yosemite below.

Configure PHP and Start Apache HTTP Server

Mac OS X 10.10 Yosemite continues to ship with PHP and Apache installed.   (The Apache HTTP server is stopped by default.)  You can check their versions by opening the Terminal app and running these commands:

php -v
httpd -v

Before we start the Apache HTTP Server, enable PHP support by editing the Apache config file (“sudo nano /etc/apache2/httpd.conf”) and uncommenting this line (by removing the initial pound # character):

#LoadModule php5_module libexec/apache2/libphp5.so

The “Web Sharing” option was removed from the “System Preferences” dialog so we have to use the command line to start the Apache server.  You can start, stop, or restart using the following commands:

# Start, stop, or restart Apache HTTP Server
sudo apachectl start
sudo apachectl stop
sudo apachectl restart

# Check to see if Apache HTTP Server is running
ps -e | grep httpd

Note: The “apachectl start/restart” command will configure Apache to start on bootup. (Internally, “apachectl start” calls “launchctl load” and “apachectl stop” calls “launchctl unload”.)

Start the Apache HTTP Server. Browse to http://localhost/ and you should see the “It Works!” message.

Create a test PHP file under the Apache document root directory, “sudo nano /Library/WebServer/Documents/phpinfo.php”, with the following content:

<?php
// Show all information about PHP
phpinfo();
?>

Browse to http://localhost/phpinfo.php and you should see the PHP configuration information.

If you have problems, check the Apache error log file at “/var/log/apache2/error_log” directory.

You can change the Apache document root to point to a different directory by editing “/etc/apache2/httpd.conf” and modifying the values for these two declarations:

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">

Restart the Apache HTTP Server for the change to take effect. Make sure that your new document root directory and its contents have read permission set for others (for example, “chmod 755” for directories and “chmod 644” for files).

Install and Start MySQL Server

Download the free MySQL Community Server distribution; I selected the “Mac OS X 10.10 (x86, 64-bit), DMG Archive” package.  You don’t need to login or sign up; just select the “No thanks, just start my download” link at the bottom.  Open the downloaded “mysql-5.7.11-osx10.10-x86_64.dmg” disk image file and run the “mysql-5.7.11-osx10.9-x86_64.pkg” package inside to install MySQL Server. (Strangely, even though I downloaded the 10.10 version, the names of the disk image and package files refer to the 10.9 version.)

Note: When the installation completes, you will see a dialog containing the temporary password for the MySQL root user. Please make a copy of it because you will need it below. If you forget to do so, you can follow the MySQL website’s How to Reset the Root Password page to reset the root password.

mysql_sys_prefsThe MySQL Server will be installed under the “/usr/local/mysql-5.7.11-osx10.9-x86_64” directory. In addition, a symbolic link to that directory is created as “/usr/local/mysql”.

You can start the MySQL Server and configure whether it will run on bootup under “System Preferences, MySQL”. Alternatively, you can start and stop the MySQL Server from the command line:

# Start or stop MySQL Server
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop

# Check to see if MySQL Server is running
ps -e | grep mysql

Add the following line to your user environment profile, “nano ~/.profile”, to avoid inputting the full path when executing mysql commands:

export PATH=$PATH:/usr/local/mysql/bin

Start the MySQL Server and try these commands:

# Show MySQL version
mysql -u root --version

# Connect to MySQL Server
mysql -u root -p
# Input the temporary root password when prompted

# Reset the root password to blank
mysql> alter user 'root'@'localhost' identified by '';
# Put your password inside the '' at the end if you don't want a blank password

# Some example queries
mysql> show databases;
mysql> use mysql;
mysql> show tables;

# Exit the MySQL interpreter
mysql> quit

Additional info about LAMP setup can be found at Get Apache, MySQL, PHP and phpMyAdmin working on OSX 10.10 Yosemite.

No Comments

Windows 8.1 Boot Camp on 2015 Macbook Pro Retina 13 Inch

Mac OS X, Windows No Comments

I recently upgraded to a 2015 Macbook Pro Retina 13 inch laptop. I attempted to install Windows 7 using the Boot Camp Assistant, which immediately asked for a Windows 8 or later installation media to be inserted. Darn it. I managed to create and insert a USB flash drive containing the latest Windows 8.1 with Update. After that, the Boot Camp Assistant asked me for the Boot Camp Support Software (Windows drivers). I inserted a second USB flash drive containing the latest Boot Camp Support Software I had manually downloaded from the Apple website, but Boot Camp Assistant still complained that it couldn’t be found. It turned out that for newer Macbooks, I must download the Boot Camp Support Software using the Boot Camp Assistant.

After I overcame the above and other issues, I was able to get a Windows 8.1 Boot Camp working. I’ve documented the steps I took below.

Create a Windows 8.1 Install USB Flash Drive

I used my Windows 7 desktop to create a USB flash drive containing the 64-bit version of Windows 8.1 with Update. (2015 Macbooks only support 64-bit Windows 8 or later.) Because Windows 8.1 setup requires 4.5GB of space, you must use an 8GB or larger USB flash drive; I ended up using a spare 16GB flash drive that I had.

Update: Instead of using the WinToFlash utility below and dealing with its browser plugin spam, use Window’s built-in DiskPart command-line utility to create a bootable USB flash drive containing the Windows Setup.

NovicorpWinToFlashLiteI used the free Novicorp WinToFlash Lite utility to copy the contents of my Windows 8.1 with Update ISO file (alternatively, you can use a Windows 8.1 DVD) to the USB flash drive. WinToFlash will re-format the USB flash drive using FAT32 format before copying the content over.

Note: Strangely, WinToFlash won’t throw an error even if you use a USB flash drive that is too small. I tried a 1GB USB flash drive and WinToFlash completed successfully. So make sure to use an 8GB USB flash drive or larger.

Unfortunately, the first time you run the latest version of WinToFlash, it will install a browser plugin called “WinToFlash Suggestor” which adds advertisements to search suggestions. Go ahead and uninstall this unnecessary browser plugin using the Control Panel’s “Uninstall a program” function.

Note: The Microsoft website has a Windows USB/DVD Download Tool which can do what WinToFlash does. Unfortunately, that tool re-formats the USB flash drive as NTFS. Because the Macbook uses UEFI BIOS boot up which only works with FAT32, the USB flash drive created by the Windows USB/DVD Download Tool won’t be bootable.

Download The Boot Camp Support Software

For Macs released in 2014 and 2015, you must use the Boot Camp Assistant to download a specific version of the 64-bit Boot Camp Support Software for your Mac. Apple does not provide links to manually download all the available Boot Camp Support Software versions. (You can manually download the older Boot Camp Support Software 5.1.5640 64bit for Mid and Late 2013 Macs here and Boot Camp Support Software 5.1.5621 64bit for Early 2013 or previous Macs here.) For 32-bit Windows installation and other options, check Apple’s System requirements to install Windows on your Mac using Boot Camp page.

BootCampAssistantWindows8In order to install Windows 8.1, the Boot Camp Support Software needs to be incorporated into the Windows 8.1 Install USB flash drive. The simplest method is to have the Boot Camp Assistant download the Boot Camp Support Software directly to the Windows 8.1 Install USB flash drive.

Note: I tried installing with two USB flash drives, one containing the Windows 8.1 Install and the other containing the Boot Camp Support Software, but the Windows 8.1 setup threw a “No new devices drivers were found” error even after I had manually selected the I/O driver on the Boot Camp Support Software USB flash drive.

To download the latest Windows drivers from Apple:

  1. Insert the FAT32-formatted Windows 8.1 Install USB flash drive.
  2. Run Boot Camp Assistant.
  3. Select the “Download the latest Windows support software from Apple” option. Click Continue.
  4. Select the Windows 8.1 Install USB flash drive. (Boot Camp Assistant requires FAT32 format and at least 500MB free.) Click Continue.
  5. Boot Camp Assistant will copy all the Boot Camp Support Software content (“$WinPEDriver$” directory, “BootCamp” directory, and “AutoUnattend.xml” file) to the USB flash drive’s root directory (which is where the Windows 8.1 setup will expect them to be).

Install Windows 8.1

To install Windows 8.1, run the Boot Camp Assistant and select the option to “Install Windows 8 or later version”. Follow the instructions to create a BOOTCAMP partition. With the Windows 8.1 Install USB flash drive still inserted, agree to restart the Macbook.

On reboot, the Macbook will boot from the Windows 8.1 Install USB flash drive. (If it doesn’t, shutdown the Macbook and power it up while holding the alt/option key. When the boot screen appears, select the USB flash drive’s “EFI Boot” option.)

The Windows 8.1 setup will automatically use the Boot Camp Support Software’s I/O driver to access the hard drive and show the list of partitions. Select the BOOTCAMP partition and allow it to be re-formatted as NTFS. Windows 8.1 setup will then install itself onto that NTFS partition.

After reboot and once the Windows 8.1 initial setup is completed (can take several minutes), the Boot Camp Support Software installer will automatically execute to install the necessary Apple hardware drivers.

Note: The Windows 8 version of Windows Defender is different from the Windows 7 version. Windows 7 Defender only protects against spyware, so the recommendation is to disable it and install Microsoft Security Essentials which protects against virus, spyware, and malware. However, Windows 8 Defender protects against virus, spyware, and malware so there is no need to replace it. (Microsoft Security Essentials can’t be installed on Windows 8.)

All in all, the Windows 8.1 Boot Camp installation went smoothly once I knew to creat a USB flash drive containing both Windows 8.1 and the Boot Camp Support Software.

Some info above derived from:

No Comments

Revert Mac OS X Yosemite Core Storage Back to Mac OS Extended HFS+

Mac OS X 8 Comments

My Macbook Pro’s hard drive died recently, again. The Apple Store had to order the replacement Hitachi 750GB hard drive which took several days. I have a suspicion that Apple is using refurbished hard drives because it has just been two months since the last hard drive replacement. Hitachi is a brand I can trust… to fail quickly… because in addition to these two failures, when I first got my brand new Macbook years ago, the Hitachi drive died within three months. This time, I decided to install a Samsung EVO 850 500GB solid state hard drive to avoid having to visit the Apple Store again.

I also decided to do a fresh installation using the latest Mac OS X 10.10 Yosemite version. When I attempted to partition the hard drive into a Mac OS X Yosemite, a Windows 7 Boot Camp, and a shared FAT32 partition, I found that I couldn’t merge or resize the Mac partition to create the shared FAT32 partition using either Disk Utility or the diskutil command line.

The problem is that Yosemite installs the Mac OS X partition using a new Core Storage volume manager, which in turn uses the HFS+ (aka Mac OS Extended) file system. Unfortunately, Apple has not yet updated the Disk Utility or diskutil command line to resize, merge, or delete a Core Storage volume. Boot Camp does know how to resize the Core Storage volume correctly though. (Supposedly, there is an undocumented “diskutil coreStorage resizeVolume” command that supports resizing a Core Storage volume, but I hesitate to use it. And I couldn’t find an undocumented command to merge a Core Storage volume with a blank partition.)

Run the Terminal app and execute the “diskutil list” command to show the Core Storage volume (under “/dev/disk0”), which wraps the old HFS+ partition (under “/dev/disk1”).

yosemite_corestorage_1

The Core Storage volume manager is the basis for Apple’s Fusion Drive technology, which is used to present several partitions on multiple drives as a single logical volume. Because I had only one hard drive on my Macbook, I didn’t need that function. (I can see using the Fusion Drive feature on a server which usually has more than one hard drive.) Thankfully, I found a way to convert the Core Storage volume back to a plain old HFS+ partition. Note that this method only works if the Core Storage volume is not encrypted.

To start, you need to find the Core Storage Logical Volume identifier used by the wrapped HFS+ partition. It is the long alpha-numeric string (“1FC06AF9-EED2-4066-BE3F-FE47166A2190” on my machine) listed under the HFS+ partition (“/dev/disk1/”) in the “diskutil list” command output above.

You can also find the Logical Volume identifier and encryption status by running the “diskutil cs list” command in the Terminal app.

yosemite_corestorage_2

Locate the bottom-most “Logical Volume” entry which has the identifier listed. Underneath that is the “Revertible: Yes (no decryption required)” line which indicates that the volume is not encrypted and can be reverted.

Once you have the Logical Volume identifier, you can revert the Core Storage volume back to a plain HFS+ partition using the “diskutil coreStorage revert” command like so:

yosemite_corestorage_3

You will need to reboot the Macbook. If you don’t reboot and run the “diskutil list” command, it will incorrectly show the logical volume (under “/dev/disk1”) even though the Core Storage has been replaced by HFS+ (under “/dev/disk0”).

yosemite_corestorage_4

Once the old HFS+ partition was back in place, I was able to delete, merge, and resize to my heart’s content. The solid state hard drive makes Mac OS X blazing fast; I regret waiting so long before installing one.

8 Comments

Bootable USB Flash Drive to Install Mac OS X 10.10 Yosemite

Mac OS X No Comments

Update: Go to Install macOS Sierra Using Bootable USB Flash Drive if you want to install macOS 10.12 Sierra instead.

In this post, I will go over instructions on how to create a bootable USB flash drive containing the Mac OS X 10.10 Yosemite installer. These instructions will also work for Mac OS X 10.9 Mavericks (excluding a Yosemite-specific step) and differ significantly from the instructions for creating a Mac OS X 10.6 Snow Leopard installer. You will need an 8GB USB flash drive for Mac OS X Yosemite or Mavericks.

I tried several methods which failed to create a bootable USB flash drive before finding one that succeeded. The instructions I found that worked, using Disk Utility, were located at How to Make a Bootable OS X Mavericks USB Install Drive and How to Create a Bootable Install USB Drive of Mac OS X 10.10 Yosemite.

Download the Mac OS X 10.10 Yosemite

First, download the latest Mac OS X version, which is 10.10 Yosemite. It is the version currently available for download from the “App Store”. (If you want an earlier version like Mac OS X 10.9 Mavericks, you’ll need to get it from elsewhere.)

Launch “App Store” and search for “OS X Yosemite”. Download it. (It is 5.16GB in size.)

Note: If you run the Yosemite installer to upgrade your Mac, the downloaded installer file will be deleted automatically after the upgrade is completed. To keep that file, you will want to move it out of the Applications folder so it won’t be deleted after an upgrade. Launch the “Terminal” app and run this command to move the downloaded installer app to your user’s “Downloads” folder:

sudo mv /Applications/Install\ OS\ Yosemite.app/ ~/Downloads/

Create Bootable USB Flash Drive Installer

By default, the Finder will hide system files which we will need to see. Run these commands in the “Terminal” app to expose the hidden files:

# Configure Finder to show hidden system files.
defaults write com.apple.finder AppleShowAllFiles TRUE

# Close all Finder instances (and re-launch so settings take effect).
killall Finder

Prepare the USB flash drive:

  1. Plug in a USB flash drive of size 8GB or larger.
  2. Launch the “Disk Utility” to format the USB Flash drive.
  3. On the left-hand pane, select the USB drive (not the partition under it, if any).
  4. Click on the “Erase” tab, select “Mac OS Extended (Journaled)” for “Format” and input a name like “Install Yosemite” (or anything because this name will be overwritten later).
  5. Click the “Erase…” button at the bottom and then the “Erase” button in the popup dialog. This format operation should take less than a minute to complete.

Restore the Yosemite installation image to the USB flash drive:

    bootable_usb_yosemite_1

  1. Launch the Finder and locate the “Install OS Yosemite.app” file. Right-click (hold the “control” key and click) on it and select “Show Package Contents”.
  2. Open Contents, then SharedSupport, and double-click on the InstallESD.dmg (disk image) file to mount it. A volume called “OS X Install ESD” will show up on the desktop and under DEVICES in the Finder.
  3. In the “OS X Install ESD” volume, right-click on the “BaseSystem.dmg” file and select “Open” to mount it. (Double-click won’t perform any action because it is a hidden file.)
  4. Use Disk Utility to clone the “BaseSystem.dmg” to the USB flash drive:
      bootable_usb_yosemite_2

    1. Select the “BaseSystem.dmg” in the left-hand pane and click on the “Restore” tab. The “Source” field will be populated with “BaseSystem.dmg”.
    2. Drag the “Install Yosemite” partition under the USB flash drive to the “Destination” field.
    3. Click the Restore button and then the Erase button.
    4. The USB flash drive will be written with the contents of “BaseSystem.dmg” file. Depending on the speed of your USB flash drive, it may take several minutes or longer to complete this operation.
    5. Once complete, the “Install Yosemite” partition will be renamed to “OS X Base System”.

    bootable_usb_yosemite_3

  5. Use the Finder to navigate to the USB flash drive. You will see two “OS X Base System” volumes in the Finder’s left-hand pane. The USB flash drive is the last one.
  6. Under the USB flash drive’s “OS X Base System” partition, open the “System/Installation” folder. You will see an alias file named “Packages”. Delete it because we will replace it with a “Packages” folder below.
  7. Use a second Finder window to open the “OS X Install ESD” volume. (To open a second Finder window, you can use the Finder menu’s “File/New Finder Window” command.)
  8. Copy the “Packages” folder from the “OS X Install ESD” volume to the USB flash drive’s “System/Installation” folder.
    bootable_usb_yosemite_4

  9. Required for Yosemite (not required for Mavericks): Copy the “BaseSystem.chunklist” and “BaseSystem.dmg” files from the “OS X Install ESD” volume to the USB flash drive’s root “/” folder. If you don’t do this, you will get an “undefined error 0” when attempting to install Yosemite.
  10. The USB flash drive is now complete. You can use it to boot a Mac to install Mac OS X 10.10 Yosemite.
  11. Unmount all the Yosemite installer volumes by ejecting them; you must eject “OS X Base System” before “OS X Install ESD”.

Re-configure the Finder to hide system files. Run these commands in the “Terminal” app:

# Configure Finder to not show hidden system files.
defaults write com.apple.finder AppleShowAllFiles FALSE

# Close all Finder instances (and re-launch so settings take effect).
killall Finder

Boot With USB Flash Drive

To boot a Mac with the USB flash drive:

  1. Insert the USB flash drive.
  2. While holding the “option/alt” key down, turn on the Mac to display the boot Startup Manager.
  3. You should see one or two icons, one for the internal hard drive and/or another called “OS X Base System” for the USB flash drive. (The internal hard drive may not be visible if it does not have a bootable partition installed.)
    • Note: If you don’t see the USB flash drive’s “OS X Base System”, try removing and re-inserting the USB flash drive while viewing the Startup Manager screen. The USB flash drive should then appear after a few seconds.
  4. Select the “OS X Base System” and hit the “return/enter” key to boot from the USB flash drive.

Hopefully, this post will help you to create your own bootable USB flash drive installer for Mac OS X 10.10 Yosemite or Mac OS X 10.9 Mavericks.

No Comments

Update to Latest Subversion Using MacPorts

Mac OS X No Comments

Because I make use of MacPorts to install my developmental tools on Mac OS X, installing or updating Subversion is simple, consisting of a single command line.

Install MacPorts

If you don’t already have MacPorts, go ahead and install it. MacPorts depends upon Xcode and the Xcode Command Line Tool. Instructions for installing both are provided on the MacPorts website.

Notes:

  • MacPorts is specific to the Mac OS X version, so download and install the correct version.
  • After you install the Xcode Developer Tools (free from the Mac’s App Store), run this Terminal command to install the Command Line Developer Tools:
    xcode-select --install

Update MacPorts

Before installing or updating Subversion, you will want to update MacPorts by issuing this command:

sudo port -v selfupdate

Install Subversion

To install Subversion, issue a MacPorts command to install it like so:

sudo port install subversion subversion-javahlbindings

The Subversion JavaHL Bindings (“subversion-javahlbindings”) package is necessary to support integration with Eclipse, specifically using the Subclipse plugin. Thank heaven that MacPorts got around to supporting the Subversion JavaHL Bindings installation. Before, I had to manually find a compatible version of the JavaHL Bindings, download, and install it myself.

Note: When installing the Eclipse Subclipse plugin, you will need to select the specific Subclipse version that uses a Subversion version that is the same as your installed Subversion and JavaHL Bindings. The version numbers don’t match so you will need to look at the Subclipse documentation to determine which version of Subclipse to install. For example, Subclipse 1.10 uses the latest Subversion 1.8.

Update Subversion

You can update Subversion specifically or update all outdated MacPorts-installed packages by issuing these commands:

# Update only Subversion and JavaHL Bindings
sudo port –v upgrade subversion subversion-javahlbindings

# Update all outdated installed packages including Subversion
sudo port -v upgrade outdated

Install or Update Subclipse

To install or update the Eclipse Subclipse plugin, you will use the same installation instructions. Subclipse doesn’t have a separate update mechanism. To update Subclipse, you would basically install a newer version of it (without needing to remove the older version first).

Note: Eclipse has a menu item, Help->Check for Updates, which will update itself and supported plugins; unfortunately, Subclipse does not support this function.

To install or update Subclipse, follow these steps:

  1. Go to Eclipse menu: Help->Install New Software…
  2. Input “http://subclipse.tigris.org/update_1.10.x” into the “Work with” field and the table will be updated with installation packages available at that location. (Note: Subclipse 1.10 uses the latest Subversion 1.8.)
  3. Check just the Subclipse package and keep clicking Next until the end. Half-way through, you will be asked to accept the license agreement. Select the “I accept the terms of the license agreements” radio button and click Finish.
  4. You will get a security warning popup with the message, “Warning: You are installing software that contains unsigned content.” Click the OK button to proceed.
  5. Eclipse will need to restart. You will be prompted with a “Software Updates” popup asking “You will need to restart Eclipse for the changes to take effect. Would you like to restart now?” Answer Yes.

Use Older Subversion

MacPorts allows you to select an older version of its packages for use, instead of using the latest version. This is useful in case you do an update and realize that you can’t use the latest version of a particular package, perhaps due to software version incompatibility with one of your tools or applications. For example, because the latest version of Subclipse may not support the latest version of Subversion, you may need to force the use of the previous version of Subversion.

To see all the installed versions of Subversion, run this command:

sudo port installed | grep -i subversion

You should see something like the following output:

subversion @1.7.8_2
subversion @1.7.10_1
subversion @1.8.8_0 (active)
subversion-javahlbindings @1.7.8_2
subversion-javahlbindings @1.7.10_0
subversion-javahlbindings @1.8.8_0 (active)

To activate the previous version of Subversion, use these commands:

sudo port activate subversion @1.7.10_1
sudo port activate subversion-javahlbindings @1.7.10_0

If you are using the latest Subversion and want to uninstall all the older versions, run either of these commands:

# To uninstall a specific version of Subversion
sudo port uninstall subversion @1.7.10_1
sudo port uninstall subversion-javahlbindings @1.7.10_0

# To uninstall inactive versions for all packages including Subversion
sudo port uninstall inactive

I’m very glad that MacPorts exist to make installations and updates so painless.

Eclipse Keeps Asking For Subversion Password

I encountered a bug where Eclipse kept prompting me to input the Subversion password whenever I attempted to run a Subversion command such as update. Even though I checked the save password option, Eclipse would still prompt me each time. I did not encounter this issue using the command line Subversion, so I thought it was a Subclipse bug.

Turns out that this was an Eclipse bug, involving how Eclipse interacted with the Mac OS X Keychain where the subversion password was stored. I used the solution found at the bottom of this page, Subclipse 1.10.0 not saving passwords, to update the Eclipse code signature, which eliminated the password prompts.

Quit Eclipse and run this command:

codesign --force --sign - /Applications/eclipse/Eclipse.app

Run Eclipse and issue a Subversion command like update. If you get a Keychain access dialog, select “Always Allow”.

Note: The above command will also fix the problem where the latest Eclipse Mars.2 version keeps asking for permission to “Accept Incoming Network Connections” on startup. Just run the “codesign” command and you will need to answer that prompt once only.

codesign --force --sign - /Applications/Eclipse.app
No Comments

Make Mac Screen Lock Secure and Convenient

Mac OS X No Comments

The Macbook I got for work is configured to require the password after the screensaver turns on or the display goes to sleep. By default, the screen is set to sleep after 2 minutes of inactivity on battery and 10 minutes on power adapter. When I work on two computers, alternating between the Macbook and a desktop, I hate having to keep inputting the password on the Macbook to unlock it.

I understand the need for security, but I draw the line when it makes using the Macbook too inconvenient. I don’t want to eliminate the password requirement, I just want the screen locks (which require the password to exit from) not to occur so often.

I considered adjusting the power settings so that the Macbook won’t go to sleep until an hour of inactivity occurs on either battery or power adapter. (Likewise, changing the screen saver to wait an hour.) However, making such a change would cause the battery usage to increase (the display uses a lot of power) and require a shorter interval between charges. (To preserve the battery capacity, I usually use the battery until it is very low before charging. And when charging, I try to give it an opportunity to charge to 100 percent.) While I don’t use the Macbook differently on battery versus power adapter, having to charge and being tethered to the wall socket more often is inconvenient.

macbook_screen_lockI found the solution in “System Preferences”, under the “Security & Privacy” section. There is an option named “Require password [time interval] after sleep or screen saver beings” that controls when the screen lock activates. I changed the time interval from the initial 5 seconds to 1 hour. (There are 7 selectable time intervals ranging from immediately to “4 hours”.) Now, when the screen saver runs or the Macbook goes to sleep (for example, when I close the lid), I don’t need to input the password when I wake the Macbook before the 1 hour interval expires.

This setting gave me a good compromise between security and convenience. I am not required to input the password for any inactivity less than an hour and I can leave the power (and screen saver) settings on battery conservation mode.

But what if I need to put the Macbook immediately into screen lock mode? The answer surprisingly lies in the “Keychain Access” application. To support manually locking the Mac, do the following:

  1. Run the “Keychain Access” application (under /Applications/Utilities directory).
  2. Go to the “Keychain Access” menu, Preferences, General, and check the “Show keychain status in menu bar” option.

You should now see a lock icon on the top-right menu bar. When you want to manually lock the Mac, click on the lock icon and select “Lock Screen”.

Hopefully the above will help you to secure your Mac without making it too inconvenience to use.

Note: The “Lock Screen” method above was gotten from Quickly lock your screen. Unfortunately, on Mac OS X Mountain Lion, the re-arrange menu bar icon function (hold Cmd and drag icon left or right) didn’t work so I was not able to get a keyboard shortcut working for “Lock Screen”.

No Comments

« Previous Entries