dlueth
12/8/2014 - 9:28 AM

Macports install, remove and update script

Macports install, remove and update script

#!/bin/bash

if [ ! $(whoami) = 'root' ]; then
	echo "This script should be run as root." > /dev/stderr
	exit 1
fi

if [ ! -f "/opt/local/bin/port" ] ; then
	echo "This script requires macports to be installed"
	exit 1
fi

LOG_INSTALL="./macports.install.`(date +"%Y%m%d%H%M")`.log"
LOG_UPDATE="./macports.update.`(date +"%Y%m%d%H%M")`.log"
LOG_REMOVE="./macports.remove.`(date +"%Y%m%d%H%M")`.log"
LOG_CLEAN="./macports.clean.`(date +"%Y%m%d%H%M")`.log"

spinner()
{
    local pid=$!
    local delay=0.75
    local spinstr='|/-\'
    local text=$1
    local count=0
    
    echo -ne "$text "
    while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
        local temp=${spinstr#?}
        printf "[%c]" "$spinstr"
        local spinstr=$temp${spinstr%"$temp"}
        sleep $delay
        printf "\b\b\b"
    done
    echo -ne "\b\b\b\n"
}

download()
{
    local url=$1
    echo -ne "     "
    wget --no-check-certificate --progress=dot $url 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo "DONE"
}

case "$1" in
	install)
		#port install py-ezpycrypto
		
		( port -f uninstall installed ) > $LOG_INSTALL 2>&1 & spinner "removing installed packages"
		( port clean all ) > $LOG_INSTALL 2>&1 & spinner "cleaning up"
		( port selfupdate ) > $LOG_INSTALL 2>&1 & spinner "updating package sources"
		
		( port fetch rdepof:gcc49 ) > $LOG_INSTALL 2>&1 & spinner "fetching gcc dependencies"
		( port install gcc49 && port select --set gcc mp-gcc49 ) > $LOG_INSTALL 2>&1 & spinner "installing gcc"
		( port fetch rdepof:git ) > $LOG_INSTALL 2>&1 & spinner "fetching git dependencies"
		( port install git ) > $LOG_INSTALL 2>&1 & spinner "installing git"
		# subversion dependency "serf1" does not compile under Yosemite atm
		#( port fetch rdepof:subversion ) > $LOG_INSTALL 2>&1 & spinner "fetching subversion dependencies"
		#( port install subversion ) > $LOG_INSTALL 2>&1 & spinner "installing subversion"
		( port fetch rdepof:dnsmasq ) > $LOG_INSTALL 2>&1 & spinner "fetching dnsmasq dependencies"
		( port install dnsmasq ) > $LOG_INSTALL 2>&1 & spinner "installing dnsmasq"
		#( port fetch rdepof:nodejs ) > $LOG_INSTALL 2>&1 & spinner "fetching nodejs dependencies"
		#( port install nodejs ) > $LOG_INSTALL 2>&1 & spinner "installing node"
		#( port fetch rdepof:npm ) > $LOG_INSTALL 2>&1 & spinner "fetching npm dependencies"
		#( port install npm ) > $LOG_INSTALL 2>&1 & spinner "installing npm"
		( port fetch rdepof:mariadb-server ) > $LOG_INSTALL 2>&1 & spinner "fetching mariadb dependencies"
		( port install mariadb-server && port load mariadb-server ) > $LOG_INSTALL 2>&1 & spinner "installing mariadb"
		#( port fetch rdepof:mongodb ) > $LOG_INSTALL 2>&1 & spinner "fetching mongodb dependencies"
		#( port install mongodb && port load mongodb ) > $LOG_INSTALL 2>&1 & spinner "installing mongodb"
		( port fetch rdepof:apache2 ) > $LOG_INSTALL 2>&1 & spinner "fetching apache2 dependencies"
		( port install apache2 && port load apache2 ) > $LOG_INSTALL 2>&1 & spinner "installing apache2"
		( port fetch rdepof:php53 php53-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "fetching php 5.3 dependencies"
		( port install php53 php53-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "installing php 5.3"
		( port fetch rdepof:php54 php54-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "fetching php 5.4 dependencies"
		( port install php54 php54-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "installing php 5.4"
		( port fetch rdepof:php55 php55-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "fetching php 5.5 dependencies"
		( port install php55 php55-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "installing php 5.5"
		( port fetch rdepof:php56 php56-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "fetching php 5.6 dependencies"
		( port install php56 php56-apache2handler ) > $LOG_INSTALL 2>&1 & spinner "installing php 5.6"
		( port fetch rdepof:php53-APC php53-curl php53-gd php53-iconv php53-imagick php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-sqlite php53-zip php54-APC php54-curl php54-gd php54-iconv php54-imagick php54-mbstring php54-mcrypt php54-mysql php54-openssl php54-sqlite php54-zip php55-APCu php55-curl php55-gd php55-iconv php55-imagick php55-mbstring php55-mcrypt php55-mysql php55-openssl php55-sqlite php55-zip php56-APCu php56-curl php56-gd php56-iconv php56-imagick php56-mbstring php56-mcrypt php56-mysql php56-openssl php56-sqlite php56-zip ) > $LOG_INSTALL 2>&1 & spinner "fetching additional php modules"
		( port install php53-APC php53-curl php53-gd php53-iconv php53-imagick php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-sqlite php53-zip php54-APC php54-curl php54-gd php54-iconv php54-imagick php54-mbstring php54-mcrypt php54-mysql php54-openssl php54-sqlite php54-zip php55-APCu php55-curl php55-gd php55-iconv php55-imagick php55-mbstring php55-mcrypt php55-mysql php55-openssl php55-sqlite php55-zip php56-APCu php56-curl php56-gd php56-iconv php56-imagick php56-mbstring php56-mcrypt php56-mysql php56-openssl php56-sqlite php56-zip ) > $LOG_INSTALL 2>&1 & spinner "installing additional php modules"
		# cd /opt/local/apache2/modules
		# sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php56.so
		# sudo /opt/local/apache2/bin/apxs -a -e -n php5 /opt/local/apache2/modules/mod_php56.so
		
		( port -f uninstall inactive ) > $LOG_INSTALL 2>&1 & spinner "removing inactive packages"
		( rm -rf /opt/local/var/macports/build/* ) > $LOG_REMOVE 2>&1 & spinner "removing partially completed builds"
		( port clean all ) > $LOG_INSTALL 2>&1 & spinner "cleaning up"
		;;
	update)
		( port selfupdate ) > $LOG_UPDATE 2>&1 & spinner "updating package sources"
		( port upgrade outdated ) > $LOG_UPDATE 2>&1 & spinner "updating outdated packages"
		( port -f uninstall inactive ) > $LOG_UPDATE 2>&1 & spinner "removing inactive packages"
		( rm -rf /opt/local/var/macports/build/* ) > $LOG_REMOVE 2>&1 & spinner "removing partially completed builds"
		( port clean --all installed ) > $LOG_UPDATE 2>&1 & spinner "cleaning up"
		#( port clean all ) > $LOG_UPDATE 2>&1 & spinner "cleaning up"
		;;
	remove)
		( port -f uninstall installed ) > $LOG_REMOVE 2>&1 & spinner "removing installed packages"
		( rm -rf /opt/local/var/macports/build/* ) > $LOG_REMOVE 2>&1 & spinner "removing partially completed builds"
		( port clean all ) > $LOG_REMOVE 2>&1 & spinner "cleaning up"
		;;
	clean)
		( port -f uninstall inactive ) > $LOG_CLEAN 2>&1 & spinner "removing inactive packages"
		( rm -rf /opt/local/var/macports/build/* ) > $LOG_REMOVE 2>&1 & spinner "removing partially completed builds"
		( port clean all ) > $LOG_CLEAN 2>&1 & spinner "cleaning up"
		( periodic daily weekly monthly ) > $LOG_CLEAN 2>&1 & spinner "running osx periodic maintenance"
		;;
	*)
		echo -e "Usage: macports.sh {install|update|remove|clean}"
		exit 1
		;;
esac
exit 0