_hacks – Page 2 – jozefmares.com
Home top_menu _hacks
Category:

_hacks

So you have iLO (I’m working with version 3 – UPDATE: works with version 2 – console is accessed over port 23/tcp) and want to use it over SSH tunnel? No problem but you need to know which ports to forward instead of default 80/443 TCP. According to iLO documentation and nmap you need to forward these if you want to use whole iLO functionality:

22, 23, 80, 443, 17988, 9300, 17990, 3002

Example command for SSH forward command (obviously replace ILO_IP and ROUTER_IP):

sudo ssh -L 22:ILO_IP:22 -L 23:ILO_IP:23 -L 80:ILO_IP:80 -L 443:ILO_IP:443 -L 17988:ILO_IP:17988 -L 9300:1ILO_IP:9300 -L 17990:ILO_IP:17990 -L 3002:ILO_IP:3002 root@ROUTER_IP

You need to use sudo because you are forwarding privileged ports (ports under 1024). Now you should be able to access iLO by going to http://localhost and execute Java console.

When I’m trying to create bootable Linux stick on Mac OS X (yes, I’m doing it) I usually get this error on PC (during boot attempt):

Missing operating system

This is because Unetbootin fails to set partition on USB stick as active and also somehow (I’m lazy to do code review) fails to install mbr.bin from syslinux.

This is how I fix it:

1. plug USB stick to Mac
2. list devices:

diskutil list

3. unmount usb stick (no, eject from Finder is not right thing to do):

diskutil unmountDisk /dev/disk2

4. fix problem with active partition:

sudo fdisk -e /dev/disk2
f 1
write
exit
diskutil unmountDisk /dev/disk2

5. download syslinux

6. write mbr.bin to USB stick (locate mbr.bin first):

sudo dd conv=notrunc bs=440 count=1 if=mbr.bin of=/dev/disk2

7. write distribution as usual using Unetbootin.

Introduction

It really sucks to keep two computers in sync. I am personally not able to keep anything in sync – that’s why I have to always find way how to automate stuff.

So, I have MacBook Air and Hack Pro. Both of computers are in active service (e.g. every day use). Hack Pro is utilised for very serious work which require at least dual-head, Air for creative (coffee shop) and external work. I want them in sync but not in full sync.

In my case there is also issue that Hack Pro have plenty of power to handle all tasks like filtering 10 000 of incoming mails from automated systems, build some of my software, play music with iTunes and even play full-hd video in the same time. On contrary, Air is just road warrior thing. Not so much of power but great portability. Thus, I do not want to do exactly same things on both but there are some essential things like keychain, some app configuration and so on which I want on both of them.

Prerequisites

  1. two Macs;
  2. own server / VPS, NAS, whatever;
  3. spare time;
  4. you are not afraid of terminal.

Basically we are going to setup ownCloud, setup sync via Unison and enjoy simpler life.

Unison

I talked about Unison before – check it here. It is very cool tool, and if you are user of some sort of Unix OS you really should check it!

When I talked about ownCloud I did not mentioned why I’m setting it up. If there is Unison, why do I need ownCloud? Simple answer – I want web access to data and I am using ownCloud for calendar and contacts synchronisation. Other cool thing is one-click sharing with ownCloud – I’m using it extensively.

Let’s go to terminal. Open your terminal emulator:

cd
mkdir .unison

Start your favourite text editor and go to .unison folder. We are going to create Unison configuration files. I have two profiles: dotfiles and files. These two profiles shares some common configuration.

common.prf

# Common options for Unison
fastcheck               = true
sortnewfirst            = true
rsrc                    = true
auto                    = true
confirmbigdeletes       = true
silent                  = true

# What to ignore
ignore = Name *~
ignore = Name *.lock
ignore = Name .DS_Store
ignore = Name .tmp
ignore = Name *.swp
ignore = Name *._localized

dotfiles.prf

# Sync roots
root = /Users/$USERNAME
root = ssh://YOUR-USER@YOUR-SERVER//home/USERNAME/TrustedPoint/dotfiles
include common

# What to synchronize
path = .bin
path = .ssh
path = .bashrc
path = .bash_profile
path = .gnupg
path = Library/Application Support/Adium 2.0
path = Library/Keychains/login.keychain
path = Library/Application Support/NetNewsWire

# Ignore these paths
ignore = Path {.gnupg/S.gpg-agent}

# Keep backup copy of every file on server
backuplocation = central
backup = Name *
backupprefix = $VERSION.
backupsuffix =

# Log actions
logfile = /Users/USERNAME/.unison/sync-dotfiles.log

files.prf

Sync roots
root = /Users/USERNAME
root = ssh://YOUR-USER@YOUR-SERVER//home/USERNAME/TrustedPoint/files
include common

# What to synchronize
path = Documents
path = Downloads

# Ignore these paths
ignore = Path Documents/Virtual Machines.localized

# Keep backup copy of every file on server
backuplocation = central
backup = Name *
backupprefix = $VERSION.
backupsuffix =

# Log actions
logfile = /Users/USERNAME/.unison/sync-files.log

Login via SSH to your server, install Unison (same version as you have on your Mac), create folder structure:

mkdir -p TrustedPoint/files
mkdir -p TrustedPoint/dotfiles

Please notice, I’m using SSH access – for automation use keys and password-less login.

ownCloud

I recommend use your own server or NAS or something like that because I’m assuming that you can use SSH and install Unison. Consider buying VPS if you do not have your own server.

About ownCloud installation: installation is simple as uploading application to web hosting folder, visiting folder in browser and fill your desired login info and optional MySQL database login info. Just check it for yourself.

After installation keep only these modules enabled:

  • Archive support;
  • Calendar (if you want to use it);
  • Contacts (same as calendar);
  • Share files;

It is good idea to disable Versions plugin. Unison keeps own versions (and I think Unison does it better) so it is redundant. For me it is even more useless because I use owncloud only as a web front-end to my data.

You might ask why I’m not using ownCloud native clients? Simple reason –Inotify and FSEvents.
There is problem with way how ownCloud client works – it polls and scans whole synchronised file tree which is CPU heavy and thus is eating my in MacBook Air battery. Using ownCloud native client can drain my Air battery in one hour. Guys from ownCloud project are currently implementing two technologies mentioned above, so there is a hope that Unison step will be unnecessary soon. But for now – it is a must.

Your data on ownCloud server are located in folder:

$INSTALL_DIR/data/$USERNAME

Go to folder and create symlink:

ln -s /home/$USERNAME/TrustedPoint/files files

Fire it up!

Pre-flight check list:

  1. ownCloud is running;
  2. you have tested Unison;
  3. you have enough of space on your server/NAS/whatever;
  4. you backed up your files;

Go for it:

unison dotfiles
unison files

Everything working? Congratulations! Run it on second Mac.

Create script to run it in batch

Put it whenever you want, I have mine in $HOME/.bin/.

#!/usr/bin/env bash

PID=$(pgrep unison)

[ -z $PID ] && unison dotfiles -batch && [ -z $PID ] && unison files -batch

Create boot plist files

Now to automate Unison via Launchd

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>
<key>Label</key>
<string>org.azoy.Unison_sync</string>

<key>Program</key>
<string>/Users/$USERNAME/.bin/unison_sync.sh</string>

<key>LowPriorityIO</key>
<true/>

<key>RunAtLoad</key>
<true/>

<key>StartInterval</key>
<integer>1200</integer>

</dict>
</plist>

And save it to /Users/USERNAME/Library/LaunchAgents/unison_sync.plist.

Load it with plutil:

plutil -lint ~/Library/LaunchAgents/unison_sync.plist

You can try to reboot to check if everything is working as expected.

Conclusion

So you are in the end and this setup is working for you? I’m glad to hear it. I’m using it over 3 months I’m pretty happy with it.

To answer few questions:

  • Yes, you can achieve same thing with DropBox – I’m not using public “cloud” services;
  • Yes, you do not need Unison if you do not care about your battery. It’s up to you;
  • Yes, I enjoy DIY;