add route and dns for VPN connection in Mac

VPN now becomes a ubiquitous way for climbing over GFW in China. However, once the Mac is connected with VPN and sends traffic thru it , VPN’s dns and route setting will take priority over the default network settings, which sometimes is quite inconvenient for fast accessing local sites and using other dedicated network like ipv6.

There’s a combination of configurations to work around the dns and route table of VPN:

1) when connected to the VPN, in Terminal, use the way described to find which VPN’s dns you want modify

2) in Terminal, sudo vi /etc/ppp/scutil_vpn.txt, add following lines, replace the GUID with your target GUID:

d.init
get State:/Network/Service/E6592FF4-8A4F-4C86-B1A2-F865D658D4FF/DNS
d.add ServerAddresses *
set State:/Network/Service/E6592FF4-8A4F-4C86-B1A2-F865D658D4FF/DNS

4) in Terminal, sudo vi /etc/ppp/ip-up,(make it executable), add following lines, and modify the TARGET_IPADDR and MASK of which network subnet you want to go thru the VPN:

#!/bin/sh
/sbin/route add TARGET_IPADDR/MASK $5
/usr/sbin/scutil < /etc/ppp/scutil_vpn.txt

5) install and use dnsmasq to direct wildcard dns resolving for target server names to the VPN dns server

6) in the VPN settings, uncheck “Send All Traffic” box

7) done.

Now when you are connected with the target VPN, you will only go through the VPN to visit target domain names and ip you’ve set, with all other network like ipv6 unchanged. Of course,  the settings could be reversed to send most traffic thru VPN, leaving a few sites accessing locally.

Fix TimeMachine on Buffalo LS-CHLv1

Since Lion, the TimeMachine support on the Buffalo LinkStation LS-CHL v1.0 was broken because the new Netatalk protocol is now used in Lion TimeMachine backup process which is not compatible with the old NAS firmware’s atalk version. With such a long time passing, Buffalo only updates a few products’ firmware (including LS-CHL v2.0) to support Lion’s TimeMachine, and leaves a lot of old NAS model unsupported. And according to this thread, there WILL NOT be any official firmware updates for my LS-CHL v1.0 in the future.

However, as user boing in the previous forum thread suggested, it could be done by self installing new netatalk protocol to your old NAS device. After two days of configuring, now my old LS-CHL v1.0 could successfully backup my MBP now. Here’s the detail steps:

1) use acp_command to allow telnetd on the LinkStation device, logon to it under root user

2) ipkg update, ipkg upgrade, and then ipkg install netatalk protocol, which should be version 2.2.0-2

3) stop old default atalk service by: /etc/init.d/atalk.sh stop, and killall cnid_dbd and cnid_metad service

4) copy old /etc/atalk/*.* to /opt/etc/netatalk/, but don’t overwrite new installed uams folder (before copy, backup the new installed ones for reference if you wish)

5) remove .AppleDB .AppleDesktop .AppleDouble in the root folder under your time machine backup volume, the new cnid_dbd service will recreate these database upon the first access

6) modify file AppleVolumes.default, find the time machine backup volume line, append “options:tm” to it

7) modify AppleVolumes.default, afpd.conf, netatalk.conf to change MAC_CHINESE_SIMP to MAC_ROMAN if these ones contain such localization encoding before

7.5) because I use guest account to access NAS time machine volume, new uams_dhx2.so in afpd.conf is added but not used and tested actually, try use old firmware’s uams if logon to your network volume fails

8) start /opt/sbin/cnid_metad , /opt/sbin/atalkd and /opt/sbin/afpd service, now TimeMachine on your mac should work to connect your old friend NAS backup volume. Try do a backup first, as the Lion will update the old backup sparsebundle a bit, and you could enter into the new Time Machine with all your old data out there!

9) if you want linkstation to have boot time new afp service, modify /etc/init.d/atalk.sh, copy or create symbolic link to use new installed atalk ones

10) if TimeMachine won’t connect but prompts you “must create new backups” dialog, try this method , it takes several hours but works.

It’s a bit tedious to figure out all the configure steps after trying with several different time machine failures, but it’s not so complicated after all, requiring no recompilation or coding. It’s a REAL SHAME for Buffalo to abandon its longtime users without giving any efforts and notice.

sunpinyin compile problem in Lion 10.7

Just encounter some build problem in 10.7 with latest sunpinyin git:

1)when compiling xib there’s a warning says TableViewColumns identifier expects NSString in 10.7, it could be fixed by manually set the TableViewColumn’s identifier to a string in Interface Builder. And note: manually set the english version xib, the zh_CN version will be auto generated

2)an build error suggest cp’s usage: in the build phrase, add quotation mark with the directory part, there could be space in the path

p.s. the diff file for the changes is here

Fix QSB Freeze with Lion

Google Quick Search Box will freeze in OS X Lion and alloc huge memory if you input long words in search box. Only forcing to kill the QSB process could free up the memory, which makes QSB almost unusable in Lion.

After a few trials and thoughts, I found that the issue seems related to spotlight integration, which is apparently upgraded in Lion. Try to deselect spotlight results and disable spotlight plugin in QSB preference to work around it.

Works for my QSB 2.0.0.3789 and freezes no more.

Lion Upgrade Issues

  1. Missing ~/Library folder in Finder: Use “chflags nohidden ~/Library” in terminal to show it back
  2. QSB huge memory alloc bug for more than 4 words input: NO FIX yet, disable spotlight plugin to work around
  3. XCode 4.1 launch crash: install standalone iTunes 10.4 after install XCode 4.1
  4. 3 finger swipe crash chrome/terminal/…: remove AirKeysInputManager.bundle from simbl, upgrade betterTouchTool to support customizable Lion multi-touches
  5. No Trim support for 3rd party ssd: Use Trim Enabler 1.2 to re-enable Trim support for SSD in Lion
  6. Alt+up/down doesn’t work any more to switch Spaces, now Mission Control only have left/right horizontal Desktops, which is ridiculous and lousy for switch more than 2 desktops; Workaround: arrange common applications to Desktop 2 so that only one left/right switch is needed for most used 3 desktops, alt+number to direct jump
  7. Time Machine backup with link station is BROKEN because Lion use new netatalk 2.2 and new security protocol. No quick fix seems to come from Buffalo 🙁 A firmware 1.53beta upgrade is provided by Buffalo to fix TimeMachine backup issue, but it’s only for LS-CHL-V2, the CHL revision 1 seems no quick fix before September! Wait Again!
  8. Preview constantly crashes upon launching if some folder in home folder is a symbolic link to external hard disk folder; remove the symbolic link, relaunch preview(won’t crash now), and relink the symbolic link, preview will work since then.
  9. Autojump broken in Terminal: Fix by replacing line 47 in autojump.bash with

    export PROMPT_COMMAND=”$AUTOJUMP ; ${PROMPT_COMMAND:-:}”

  10. TextEdit also keeps crash upon launching: Same issue with Preview, remake downloads symlink will fix it.
  11. Full screen apps doesn’t support second display. Only the primary display could show the apps in full screen mode leaving other displaying only blank linen. And because the system menu bar is also on primary display, some functions are also hard to use for app maximized window on second display. Workaround: use this hack for opening another app in full screen as well as REMEMBER the keyboard shortcuts!
  12. VMWare Fusion 4 introduce its bluetooth and broke previously self-customized bluetooth broadcom driver, now only usable in client windows system booted when bluetooth is turned on OR check share bluetooth device with windows, otherwise,  even though device manager has one bluetooth device listed, the broadcom bluetooth software won’t recognize it either.

fix adium spotlight log search

For Adium 1.4.2, the chat transcript log doesn’t appear in spotlight search result even though the word is exactly in the chat logs. Yeah, it’s no big deal, but a bit annoyance, especially when Adium’s own transcript search won’t return good results.

After some research, a few tryouts were taken: Using mdimport to force spotlight reindex the logs folder seems not work. Followed instruction of this ticket to move the chat logs folder to user documents folder, still not work. Then, this ticket has the culprit bug revealed. The
GetMetadataForXMLLog function doesn’t handle the chatlog bundle correctly. Just appending the xml path before parsing the xml file and rebuilding the project will exactly fix the spotlight search issue.

Therefore the reverse steps are the final solution:
1) Get my bug fixed version of AdiumSpotlightImporter (or compile the bugfix version by yourself), unzip and copy to /Applications/Adium.app/Contents/Library/Spotlight, and make sure the importer is used by spotlight in “mdimport -L”
2) Move the adium chat log folder to your documents folder as the above ticket shows, so that spotlight will not exclude it under the system library folder
3) mdimport “your new adium chat log folder” to merge into the spotlight index
4) Search words in spotlight, the adium result now will show in search results under the mail category

Good luck, Adium users!

QSB 2.0.3789 services plugin

It’s quite sad that QSB (Google Quick Search Box) doesn’t update anymore, according to this thread, it goes to maintain mode. QSB is quite intuitive and allows mutlibyte/unicode text input that Quick Silver lacks, and if you have the services plugin to utilize OSX’s services, you can almost do anything with QSB in Mac like with QuickSilver’s plugins. Especially, you can add your custom services with automator and apple script! However, the promised 2.0.3789 compatible services.hgs plugin might not come in a foreseeable future.

Well, Do It Yourself.

Just spent some efforts last week in figuring out how to make the old mkhl plugin to work in QSB 2.0. Although not well documented, QSB service plugin works finally. Thanks to mkhl and qsb-mac’s good coding. You can now download the release version from my following link.  In order to avoid constantly read service info, this plugin load info upon start, therefore restart QSB to load service info if new service is installed.

If you find QSB useful, you may also contribute to it and provide bugfixes. Have fun for the updated services plugin on QSB 2.0.3789!

release version of service.hgs for QSB 2.0.3789

Published
Categorized as Dev, Tips Tagged

Rar archive in mac finder with automator

用Mac的一个重要麻烦就是zip archive经常在windows下乱码,由于mac采用unicode编码,中文文件名zip压缩文件之后,在采用ansi编码格式的windows上就是乱码,往往无法解压还原。用stuffit,finder自带的压缩,都避免不了这个问题。

但rar文件就没有乱码问题,用betterzip之类的就可以归档rar文件,但大多需要打开betterzip程序,再选择文件等,多了好几个步骤,如何能在finder里选择目标文件直接生成rar文件?当然可以,用mac著名的automator!

在automator里,选择Service服务类型,选择接受文件和目录,然后拖进执行shell脚本,选择输入自变量,然后在脚本内容里输入:

#!/bin/bash
for f in “[email protected]
do
pp=`dirname “$f”`
ff=`basename “$f”`
cd “$pp”
/usr/local/bin/rar a -m5 -ep1 -o+ Archive.rar “$ff”
done

保存为建立rar的工作流服务,这样在finder选择多个文件或目录后,右键选择服务里直接可以把目标文件生成rar归档文件了。

wildcard dns for ipv6

ipv6目前是比较方便易用的绕墙的方法,但往往hosts文件里塞满了一大堆静态v6地址,而且不支持通配符,很难维护。

推荐使用dnsmasq,在loopback interface上绑定监听一个dns服务,既支持本地通配符的匹配解析,也可连接上游upstream dns服务器,提高dns解析速度,同时也完美支持ipv6的域名解析。

mac可通过macports: sudo port install dnsmasq, sudo port load/unload dnsmasq

upgrade mbp ssd into optical bay

买了个intel x25m 160G ssd升级一下macbook pro笔记本,没想到花了三四天。

首先想要修改一下ssd参数,但mac上不支持hdparm,光驱又不认盘,想通过usb启动,但结论是:基本不可能在mbp上从usb启动linux的。装了refit,能认出linux usb启动盘,但boot不了。不用refit,直接用grub-efi,option启动可以看到grub菜单,但同样boot错误。试了很多live方案,ubuntu, gparted, 甚至dos的hdat2没一个成功。最终放弃。在朋友的机器上接上ssd,用gparted启动,hdparm修改ssd的max size,因为intel号称减少size可以提升ssd硬盘性能和寿命,即over-provisioning,可结果mac上认出来的硬盘还是原来标称大小。

另外还需要确认买的硬盘盒托架能装进光驱那个位置,淘宝上买的托架,结果发货发错了,下端没有2个拧螺丝的脚,而是一个类似ibm笔记本材质的斜面,等花了好大力气拆下光驱结果没能装上托架,只好重新恢复原状,再联系重发货。其中,拆光驱一开始还比较麻烦,其实camera线不用拆下来,只要把边缘那个锁扣螺丝拧松,把固定线的胶水剥离,然后把SATA接口卡拨开,3个螺丝拧掉,左右动动,就可以拆下superdrive光驱。

好不容易正确的托架来了,发现原来的硬盘边缘的固定位置的螺丝拧不下来。这还有个复杂的背景:需要把ssd装在原先hdd硬盘的位置,而hdd则应放入托架里。这样snow leopard才可以正常休眠hibernate,否则会醒不过来,因为系统不会去第二个硬盘口唤醒,当然普通sleep是保存在内存中没此问题,但是总归不爽。于是,专门去市场买了梅花螺丝刀,才算ssd/hdd互换成功。

然后通过usb雪豹安装盘(可以option启动),重装系统,因为time machine备份太大超过ssd容量,恢复不了,只有通过Migration Assistant来做。由于空间限制问题,所以音乐/电影/文档都没有migrate。不过mac这个迁移的确很好用,基本所有的设置都原样恢复,非常给力。当然映射文件目录,权限设置等等又花了好几个小时,才算基本无缝切换到ssd。

目前ssd是系统盘,启动/应用为主,hdd则作为文件存储,邮件、音乐、电影、虚拟机都在这个上。系统启动基本10秒中,应用启动基本1-2秒,总算没有白花那么多时间。

update: 迁移后,facetime可以启动,但登录不了。帐号和密码都没问题,就老是报一个“服务器在处理注册过程中发生错误,稍后再试”的错误,查了大半天,发觉在keychain里把一个GUID名字的证书和下面的client push certificate给删了就好了,估计和迁移后的身份或权限不一致有关,删除后会自动重建,所以也不用备份。

update2: 出于保护ssd寿命,把swap file切换到原来硬盘上,可以参考superuser的这个帖子,另外还可以参考这个把swap文件大小改大点。貌似虚拟机vmware fusion 3.1以上运行时间长了会持续占用内存,很多人都降回3.0版,正在犹豫中。

update3: 10.6.7雪豹可以支持Trim了!访问http://forums.macrumors.com/showthread.php?t=1125400,下载enabler,运行一下再重启即可,系统信息显示支持Trim了。看上贴里评论性能的确有一定提升,估计是真的支持了。

Published
Categorized as ELife, Tips Tagged