top_menu – Page 8 – jozefmares.com
Home top_menu
Category:

top_menu

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;

My post series about building true Mac-based workstation is coming to the end. Hack Pro has been working fine but one last thing was not done – sleep.

It wasn’t deal breaker but I like it when things work just like a charm. So I needed to add a little magic to boot process of my Hack Pro.

But first things first – check my hardware in this post as ways how to achieve correct sleep vary. This post is just about my motherboard and setup.

I hoped that my motherboard will work without patching DSDT but this is just not true. You need custom DSDT for Asrock Z68 Pro3-M, where you will patch wake function. Computer goes correctly to sleep but wont wake up.

First – make sure you have working hardware (sound card, ethernet, wifi, system definition and so on).

Second – try reboot few times to make sure everything is working. Boot with -v (check these boot flags) and check everything is working as expected.

Got it? Let’s go!

Get your copy DSDT Editor. You know what is DSDT is, right? You know how to work with it? If not, read something about it – you can harm your computer. :)

Patching DSDT for Asrock Z68 Pro3-M is very easy. Just extract DSDT from your machine, find line containing something like this:

PCI0.SBRG.SIOW (Arg0)

and delete it. Your line may vary, try search in file. Build DSDT.aml, copy it to /Extra and reboot.

Your machine should now sleep and resume like native Macs.

Today, I participated on Symantec Cyber Readiness challenge. These are my thoughts about competition.

Why is it cool?

As I am not allowed to disclose any competition questions and flags (competition is organised like capture the flag game) I will say only few brief informations.

Cool thing about this competition is that someone (thanks Symantec) created real hands-on hacking environment for relative wide audience. This kind of testing was domain of security certifications like CEH or privately provided trainings.

You will learn stuff about your tools – there is always a space for improvement. And – it is always good thing, knowing where are your limits. We all should master our tools.

Where it fails

Does not matter what people thing, this is not penetration testing nor hacking simulation. Real world compares with competition same way that ocean compares with pool. Yes, you can drown in both but swimming in pool is a lot simpler than swimming in ocean. Take it as a bootcamp testing environment.

Conclusion

If you have opportunity go for this event. You will learn something new, and you will have great fun.  Do not come unprepared. I came only with MacBook Air and some old Backtrack (I did not done my homework). My recommendation: test if your tools are working (my Metasploit was broken – usual Ruby, Gem lib stuff), test if you can use your tools (fcrackzip and nmap has segfaulted few times). Make sure your clipboard is working. It is really annoying to rewrite hashes from screen.

Oh btw: I’m glad I finished first. It means I’m going to Nice for next round. I am still worth something as security person. :)Symantec Cyber readiness challenge diploma