Wednesday, May 26, 2010

Mac|Macports through a proxy

Macports through a proxy

March18

We have a proxy in work that prevents connections from being made out directly. I found out about the awesome MacPorts program, which is a bit like apt for OSX. It pulls backports from a repository and installs them for you.

There's not a lot to the tool's installation if you live on the open web, but I needed to do some stuff to get it working with our squid proxy.

If you run sudo port selfupdate, and get an error that says 'port selfupdate failed: Couldn't sync the ports tree' or something like that, chances are your proxy is blocking rsync.

There are three steps. The prerequisites required for this to work are that you have the proxy address, admin access to your mac, and that the proxy supports the rsync port (873/tcp).

You can test the connectivity by going to http://rsync.macports.org:873, you should get the following error:

@RSYNCD: 30.0
@ERROR: protocol startup error

Step 1

If that works ok, then you need to set up the sudo environment for osx to let proxy environment settings through. First, edit your sudoers file with:
sudo visudo
Do not just edit /etc/sudoers

You need to append these lines:

Defaults env_keep += "http_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY RSYNC_PROXY"
Defaults env_keep += "ALL_PROXY NO_PROXY"

Step 2

Now, you need to set your http proxy
export http_proxy=http://proxy.example.com:8080
where 8080 is the port number of the proxy

Step 3

By Default, port uses rsync to manage its updates. RSync can use a proxy environment setting (man rsync for mre)
export RSYNC_PROXY=proxy.example.com:8080
Note the rsync proxy capitalisation, and the fact that it does not need http://

That should do it. You can then run selfupdate to get port to the latest version.

The hard way

If that doesn't work, you can have a look at these instructions for replace rsync with subversion:
Syncing with SVN in Macports


Another way:
edit /opt/local/etc/macports/macports.conf
at the bottom there are options to set all the proxy variables just for macports.

How to sync your ports tree using Subversion (over HTTP)

  • Audience: end users who cannot use rsync (873/tcp) due to firewalls, proxies, policy, etc.
  • Requires: MacPorts
  • Requires: Subversion

Leopard comes with subversion already installed. If you are using Tiger, or some other system which does not provide a subversion client, you will need to install subversion yourself. If you have a copy of the ports tree already, just run:

sudo port install subversion

If you do not have a copy of the ports tree, you can download the daily tarball by following the tarball howto.

Introduction

Some people live and work behind a firewall or proxy that block or otherwise break rsync, which is the primary means of getting updated portfiles in MacPorts. The following steps will switch your tree over to using subversion (over http) for syncing.

Note: replace "$prefix" with the location of your MacPorts install, which defaults to /opt/local.

Installation

Step 1: Checkout Initial Copy

cd $prefix/var/macports/sources
mkdir -p svn.macports.org/trunk/dports
cd svn.macports.org/trunk/dports
svn co http://svn.macports.org/repository/macports/trunk/dports/ .

Configuration

Step 2: Configure MacPorts

Edit $prefix/etc/macports/sources.conf to comment out the rsync entry and add the "file" entry:

Note: don't forget to replace $prefix.

#rsync://rsync.macports.org/release/ports/ [default]
file:///$prefix/var/macports/sources/svn.macports.org/trunk/dports/ [default]

Optional Parts

Step 3: Test Sync

Run sync in debug mode and watch for "svn update" instead of "rsync" being used:

port -d sync 

<- Back to the HOWTO section

No comments: