Skip to content

Instantly share code, notes, and snippets.

@fuho
Created October 11, 2012 04:46
Show Gist options
  • Save fuho/3870223 to your computer and use it in GitHub Desktop.
Save fuho/3870223 to your computer and use it in GitHub Desktop.
Compiling vips on Ubuntu 12.04 server LTS from source on github
#!/bin/bash
########################################################################
###################### VARIABLE DEFINITIONS ########################
########################################################################
DIR_CWD="$PWD" # Store current working directory
DIR_SRC="src" # Default source directory in your home folder
DIR_OS="openslide" # Openslide source directory
DIR_LV="libvips" # Libvips source directory
DIR_LT="tiff-4.0.3" # LibTiff source directory
# LibTiff source url
URL_LT="ftp://ftp.remotesensing.org/pub/libtiff/tiff-4.0.3.tar.gz"
FILE_LOG="${0%.*}.log" # Set log filename
# Openslide commit to use
#COMMIT_OS="7cbd007cb0423b0ab9b7d657d3781ca96aa308b5" #20121015-Works
COMMIT_OS="f1b104c3c93d35f3db91960d77d9d4e1509552a8" #vips-7.31.0-Sat Nov 3 16:36:57 EDT 2012
# Libvips commit to use
#COMMIT_LV="f65b07abb6a4701133a8420e7c4ce20b62b312f"
#COMMIT_LV="bf945dcdc5fd92b24ed25ab820d829e30d0d8086" #20121015-Works
COMMIT_LV="faf6e03381443ef70db9825906070adfe39c8dfd" #vips-7.31.0-Sat Nov 3 16:36:57 EDT 2012
SIMULATE= # Tell methods to try to simulate
DO_CLEANUP= # Clean up after myself, remove created dirs
SLP="2" # Sleep -n- seconds before commands
### # Packages
PKGS=()
PKGS+=( git autoconf automake libtool pkg-config )
PKGS+=( gtk-doc-tools gobject-introspection swig )
### # Color Constants
RED=31
RED_BG=41
GREEN=32
GREEN_BG=42
BLUE=34
BLUE_BG=44
YELLOW=33
YELLOW_BG=43
########################################################################
###################### FUNCTION DEFINITIONS ########################
########################################################################
usage()
{
cat << EOF
usage: $0 [-h] [-v] [-d directory] [-e commit_uuid] [-s commit_uuid] [-l [filename]]
This script attempts to install libvips with openslide support
OPTIONS:
-h Show this message
-d Save source in this dir, default is ~/Src
-r Remove all dirs created during script run
-e Openslide commit to checkout before compile
-s Libvips commit to checkout before compile
-l Log output $FILE_LOG
EOF
echo "Color test:"
cecho " RED" $RED
cecho " GREEN" $GREEN
cecho " BLUE" $BLUE
}
check_elevated(){ #check for elevated rights, root is 0, if not 0
if [ $UID -ne "0" ]; then
echo "This has to be run with elevated rights! Use sudo or login as root!"
exit 1
fi
}
cecho(){ #cecho = color echo ( <text>, <color id> )
echo "********************************************************************************"
if [ -z "$2" ]
then
echo -e "\e[31m$1\e[0m"
else
echo -e "\e[$2m$1\e[0m"
fi
echo "********************************************************************************"
}
cleanup(){ #Delete directories created during install
cecho "I will now remove these directories:" $BLUE
cecho " $DLV" $YELLOW
cecho " $DOS" $YELLOW
cecho " $DLT" $YELLOW
cd $DIR_CWD
if [! $SD_EXISTED]
then
cecho " $DS" $YELLOW
sleep $SLP
rm -rf $DS
else
sleep $SLP
fi
rm -rf -p $DLV
rm -rf -p $DOS
rm -rf -p $DLT
}
aptget_install(){
cecho "Installing $PACKAGE" $BLUE
if [ ! $1 ]
then
cecho "aptget_installed called without argument!" $RED
exit 1
else
PACKAGE=$1
fi
apt-get -y -q $SIM_APT install $PACKAGE
ERROR=$?
if [ $ERROR -ne "0" ]
then
cecho "ERROR: ${ERROR} - While installing ${PACKAGE}!" $YELLOW
else
cecho "Package $PACKAGE is installed." $GREEN
fi
}
aptget_build_deps(){
cecho "Attempting to build-dep for libtiff:" $BLUE
apt-get -y -q $SIM_APT build-dep tiff
cecho "Attempting to build-dep for openslide:" $BLUE
apt-get -y -q $SIM_APT build-dep openslide
cecho "Attempting to build-dep for vips:" $BLUE
apt-get -y -q $SIM_APT build-dep vips
}
aptget_all_the_things(){ #Try to apt-get all necessary packages
cecho "I will now install all necessary packages:" $BLUE
sleep $SLP
aptget_build_deps #Install dependencies from repositories
cecho "Checking for missing packages:" $BLUE
pkgs_check ${PKGS[@]}
cecho "INSTALLED PACKAGES:\n ${PKGS_INSTALLED[*]}" $GREEN
cecho "MISSING PACKAGES:\n ${PKGS_MISSING[*]}" $YELLOW
for PACKAGE in ${PKGS_MISSING[@]}
do
aptget_install $PACKAGE
done
}
attempt_uninstall(){ #Attempt to uninstall (<dir>)
if [ ! $1 ]
then
cecho "attempt_uninstall called without argument!" $RED
exit 1
else
DIR_UNINSTALL=$1
fi
if [ -d "$DIR_UNINSTALL" ]
then
cecho "Directory ${DIR_UNINSTALL} exists!\nWill try to uninstall and remove dir." $BLUE
sleep $SLP
cd $DIR_UNINSTALL
make uninstall
rm -rf $DIR_UNINSTALL
fi
}
#pkgs_check() PKGS_LIST -> PKGS_INSTALLED, PKGS_MISSING
pkgs_check(){
if [ ! $1 ]
then
echo "pkgs_installed: ERROR - Package list not supplied"
exit 1
else
PKGS_LIST=( "$@" )
PKGS_INSTALLED=()
PKGS_MISSING=()
fi
for PACKAGE in ${PKGS_LIST[@]}
do
dpkg -p $PACKAGE >/dev/null 2>&1
if [ $? -eq "0" ]
then
PKGS_INSTALLED+=( $PACKAGE )
else
PKGS_MISSING+=( $PACKAGE )
fi
done
}
########################################################################
###################### PARSE ARGUMENTS ########################
########################################################################
while getopts “hd:e:s:lnr” OPTION # Parse arguments
do
case $OPTION in
h)
usage
exit 1
;;
d)
DIR_SRC=$OPTARG
;;
e)
COMMIT_OS=$OPTARG
;;
s)
COMMIT_LIBVIPS=$OPTARG
;;
l)
if [ $OPTARG ]; then FILE_LOG=$OPTARG;fi
npipe=/tmp/$$.tmp
trap "rm -f $npipe" EXIT
mknod $npipe p
tee <$npipe ${FILE_LOG} &
exec 1>&-
exec 1>$npipe
exec 2>$npipe
;;
n) #No act flag, don't do anything just simulate
SIM_APT="--no-act"
SIMULATE=1
;;
r)
DO_CLEANUP=1
;;
?)
usage
exit
;;
esac
done
### # Compound directory varibles
DS="$HOME/$DIR_SRC" # Source directory
DOS="$DS/$DIR_OS" # Openslide directory name
DLV="$DS/$DIR_LV" # Libvips directory name
DLT="$DS/$DIR_LT" # Libvips directory name
### # Calculated varibles
SD_EXISTED= # Remember if source dir existed
if [ -d "$DS" ]; then SD_EXISTED=1; fi
########################################################################
######################### MAIN PROGRAM ###########################
########################################################################
check_elevated
aptget_all_the_things
attempt_uninstall $DLV
attempt_uninstall $DOS
attempt_uninstall $DLT
#create directories
cecho "I will now create directories:" $BLUE
cecho " $DLV" $YELLOW
cecho " $DOS" $YELLOW
cecho " $DLT" $YELLOW
sleep $SLP
mkdir -p $DLV
mkdir -p $DOS
mkdir -p $DLT
### CLONE REPOSITORIES ###
cecho "I will now clone Openslide and Libvips repositories from GitHub:" $BLUE
echo "git clone git://github.com/openslide/openslide.git $DOS"
echo "git clone git://github.com/jcupitt/libvips.git $DLV"
sleep $SLP
cd $DS
git clone git://github.com/openslide/openslide.git
git clone git://github.com/jcupitt/libvips.git
### DOWNLOAD libtiff SOURCE and untar
cecho "Downloading and unpacking libtiff:" $BLUE
sleep $SLP
wget -q -O ${DLT}/${URL_LT##*/} $URL_LT
tar xzf ${DLT}/${URL_LT##*/} -C "${DS}/"
#compile and install libtiff
cecho "I will now attempt to compile and install LibTiff:" $BLUE
sleep $SLP
cd $DLT
cecho "LibTiff: ./configure" $BLUE
./configure
cecho "LibTiff: make" $BLUE
make
cecho "LibTiff: make install" $BLUE
make install
ldconfig
#compile and install openslide
cecho "I will now attempt to compile and install OpenSlide:" $BLUE
sleep $SLP
cd $DOS
git reset --hard $COMMIT_OS
cecho "OpenSlide: autoreconf -i" $BLUE
autoreconf -i
cecho "OpenSlide: ./configure" $BLUE
./configure
cecho "OpenSlide: make" $BLUE
make
cecho "OpenSlide: make install" $BLUE
make install
ldconfig
# compile and install libvips
cecho "I will now attempt to compile and install LibVips:" $BLUE
sleep $SLP
cd $DLV
git reset --hard $COMMIT_LV
bash ./bootstrap.sh
export CFLAGS="-g -Wall"
export CXXFLAGS="-g -Wall"
cecho "LibVips: ./configure" $BLUE
./configure --enable-gtk-doc --enable-debug=no
cecho "LibVips: make" $BLUE
make
cecho "LibVips: make install" $BLUE
make install
ldconfig
unset CFLAGS
unset CXXFLAGS
#Cleanup if requested
if [ $DO_CLEANUP ]; then cleanup; fi
### DONE ###
cecho "Running: vips --version" $BLUE
sleep 1
vips --version
cd $DIR_CVD
cecho "FINISHED!" $BLUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment