Macports through a proxy

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

Popularity: 100% [?]

This entry was written by Alex, posted on 18/03/2009 at 17:41, filed under OSX and tagged , , , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Related

Popular

Timeline

  • http://www.hacknack.com Chris Leonello

    Extremely useful tip!! Thanks! I’ve never been able to selfupdate my macports install while behind my work proxy until now!

    If you only want to do this occasionally (not edit your sudoers), just use this on the command line for selfupdate:

    sudo env http_proxy=login:password@proxy.example.com:proxy_port env RSYNC_PROXY=login:password@proxy.example.com:proxy_port port selfupdate

    or this for normal port installs:

    sudo env http_proxy=login:password@proxy.example.com:proxy_port port install some_port

    Selfupdate may not require setting the http_proxy. You may need additional settings depending on how your proxy handles ftp. This works for me.

  • Emmett Keyser

    Awesome. Thanks so much. I was getting tired of trying all the extra_env settings.

  • jeffschwab

    Thank you.

  • swidnikk

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

  • http://vladigor13.livejournal.com/ vladigor13

    Thanks a lot! That is what I am searching for!

  • Steve Witham

    Another reason for rsync errors in MacPorts is the same as for a lot of confusing errors in MacPorts: neglecting to say SUDO before PORT…
    $ port selfupdate
    Warning: port definitions are more than two weeks old, consider using selfupdate
    —> Updating the ports tree
    Error: Synchronization of the local ports tree failed doing rsync
    Error: /opt/local/bin/port: port selfupdate failed: Couldn’t sync the ports tree: Synchronization of 1 source(s) failed
    $ # port doh
    $ sudo port selfupdate
    Password:
    Warning: port definitions are more than two weeks old, consider using selfupdate
    —> Updating the ports tree
    —> Updating MacPorts base sources using rsync
    MacPorts base version 1.9.2 installed,
    MacPorts base version 1.9.2 downloaded.
    —> MacPorts base is already the latest version

    The ports tree has been updated. To upgrade your installed ports, you should run
    port upgrade outdated
    $

    btw
    $ sudo visudo
    Password:
    Unable to find application named ‘Aquamacs.app’
    visudo: /etc/sudoers.tmp unchanged
    $ # Don’t try to get Aquamacs.app working for sudo, just,
    $ sh
    $ export EDITOR=emacs
    $ export VISUAL=emacs
    $ sudo visudo

    $ exit
    $

  • Vijay

    Thanks a lot. What if the proxy server needs authentication like that we have in our institute (an user name and a password). How to include this? I am at the user end!

  • Vijay

    Vijays-MacBook-Pro:~ vj$ sudo port -v selfupdate
    Password:
    Warning: port definitions are more than two weeks old, consider using selfupdate
    —> Updating the ports tree
    Synchronizing local ports tree from rsync://rsync.macports.org/release/ports/
    bad response from proxy — HTTP/1.0 407 Proxy Authentication Required
    bad response from proxy — HTTP/1.0 407 Proxy Authentication Required
    bad response from proxy — HTTP/1.0 407 Proxy Authentication Required
    bad response from proxy — HTTP/1.0 407 Proxy Authentication Required
    receiving file list … done

    sent 53 bytes received 497626 bytes 76566.00 bytes/sec
    total size is 27950472 speedup is 56.16
    rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-40/rsync/main.c(1400) [generator=2.6.9]
    shell command “/usr/bin/rsync -rtzv –delete-after ‘–exclude=/PortIndex*’ rsync://rsync.macports.org/release/ports/ /opt/local/var/macports/sources/rsync.macports.org/release/ports” returned error 23
    Error: Synchronization of the local ports tree failed doing rsync
    Error: /opt/local/bin/port: port selfupdate failed: Couldn’t sync the ports tree: Synchronization of 1 source(s) failed

  • Anonymous

    As far as I know, you use http://username:password@proxy.host:port as your environment variable.

  • Anonymous

    Thanks! That’s also a good way.

  • https://me.yahoo.com/a/UC.Lg4YP3ZFE6bXlVGM5bKbA6XzUmfV6mw--#f8898 tony

    scrapebox / scrapeboard proxies
    http://proxiecentral.proboards.com/

  • Pingback: LLyuan's Weblog