Last active
October 13, 2015 16:38
-
-
Save 4np/4224699 to your computer and use it in GitHub Desktop.
Bash alias to list and install older versions of ports in macports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# alias for bash to install older ports in macports | |
# (several port versions can live next to each other) | |
# add this code to your ~/.profile to have the | |
# oldports command / alias available in terminal. | |
# | |
# Usage: oldport portname | |
# oldport portname version | |
# | |
# author Jeroen Wesbeek <work@osx.eu> | |
oldport() { | |
if [ ${#@} -lt 1 ]; then | |
# show help | |
echo "You need to specify the port and version to install" | |
echo "" | |
echo "Usage:" | |
echo " oldport portname : list all versions of a particular port" | |
echo " oldport portname version : install this version of a particular port" | |
echo "Example:" | |
echo " oldport grails 1.3.9 : install grails 1.3.9" | |
else | |
# search for this port and find the categories it belongs to | |
PORT_CATEGORY=`port search $1|grep -i "^$1 @"|sed -e 's/.*(//' -e 's/)//' -e 's/, /\//'` | |
PORT_DIR=`echo $PORT_CATEGORY|sed -e 's/\/.*//'` | |
PORTFILE_URL="http://svn.macports.org/repository/macports/trunk/dports/$PORT_DIR/$1" | |
# do we have one or two arguments? | |
if [ ${#@} -eq 1 ]; then | |
echo "The following version for $1 are available for install:" | |
svn log -l 100000 $PORTFILE_URL|grep -i -e "version" -e "update"|grep "\([0-9\.]\{2,\}\)"|sed -e 's/#[0-9]\{1,\}//' -e 's/\([0-9\.]\{1,\}\)/#\1#/' -e 's/^[^#]\{0,\}#//' -e 's/#.*$//' | |
else | |
PORT_INSTALLED=`port installed $1|grep -i $2|wc -l` | |
PORT_ACTIVE=`port installed $1|grep -i $2|grep -i "active"|wc -l` | |
PORT_FULL=`port installed $1|grep -i $2|sed -e 's/.*@/@/'` | |
if [ $PORT_INSTALLED -gt 0 ]; then | |
if [ $PORT_ACTIVE -gt 0 ]; then | |
echo "Port $1 version $2 is already installed and active." | |
echo "Other installed inactive $1 versions available are:" | |
echo "" | |
port installed $1|grep -vi -e "(active)" -e "the following" | |
echo "" | |
echo "Activate another version by typing:" | |
echo "" | |
echo " sudo port activate $1 @<version>" | |
echo "" | |
else | |
echo "Port $1 version $2 is already installed but is not the" | |
echo "active version. You can activate it by typing:" | |
echo "" | |
echo " sudo port activate $1 $PORT_FULL" | |
echo "" | |
fi | |
else | |
REVISION=`svn log -l 1000 $PORTFILE_URL|grep --before-context=3 -i $2|grep "^r[0-9]\{1,\}"|sed -e 's/ .*//'` | |
if [ $REVISION ]; then | |
echo "installing $1 version $2..." | |
MY_PATH=`pwd` | |
cd /tmp | |
rm -rf $1 | |
svn co -r $REVISION $PORTFILE_URL | |
cd $1 | |
echo "enter your administrator password:" | |
sudo port install | |
port installed $1 | |
echo "switch active version by typing:" | |
echo " sudo port activate $1 @a.b.c" | |
cd $MY_PATH | |
else | |
echo "I am sorry, there does not seem to be a $1 release for version $2 available in macports..." | |
echo "You can try to install it manually by finding the changelist yourself at:" | |
echo " $PORTFILE_URL" | |
echo "And use it in the steps listed here:" | |
echo " https://trac.macports.org/wiki/howto/InstallingOlderPort" | |
fi | |
fi | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment