Skip to content

Instantly share code, notes, and snippets.

@robv
Created May 14, 2010 04:16
Show Gist options
  • Save robv/400805 to your computer and use it in GitHub Desktop.
Save robv/400805 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
#### User Configuration Options
# Temporary src directory - WARNING: This will be wiped clean.
SRCDIR=${HOME}/src
# Note: This *MUST* be set to your PHP5 installation directory!
PHPDIR=${HOME}/php5
PREFIXDIR=${HOME}/prefixdir
## Program Version Configuration
AUTOCONF="autoconf-2.61"
# Don't touch unless you know what you're doing!
LIBSSH2="libssh2-1.1"
LIBSSH2FEATURES="--prefix=${PREFIXDIR}"
SSH2="ssh2-0.11.0"
SSH2FEATURES="--prefix=${PREFIXDIR} --with-php-config=${PHPDIR}/bin/php-config --with-ssh2=${PREFIXDIR}"
#### END User Configuration Options
########## DO NOT MODIFY BELOW ##########
sleep 1s
# Push the install dir's bin directory into the path
export PATH=${PREFIXDIR}/bin:$PATH
export PHP_PREFIX=${PHPDIR}/bin
# Clear and/or create the src directory.
if [ -d ${SRCDIR} ]; then
echo "src directory already exists! Cleaning it..."
rm -rf $SRCDIR/*
else
echo "Creating src directory..."
mkdir -p ${SRCDIR}
fi
## Check if packages already exist and get packages the ones that don't.
cd ${SRCDIR}
# Wget options
WGETOPT="-t1 -T10 -w5 -q -c"
# Do some of our own error checking here too.
if [ -a ${SRCDIR}/${LIBSSH2}.tar.gz ]; then
echo "Skipping wget of ${LIBSSH2}.tar.gz"
else
wget $WGETOPT <a href="http://softlayer.dl.sourceforge.net/sourceforge/libssh2/%24%7BLIBSSH2%7D.tar.gz" target="_blank">http://softlayer.dl.sourceforge.net/sourceforge/libssh2/${LIBSSH2}.tar.gz</a>
if [ -a ${SRCDIR}/${LIBSSH2}.tar.gz ]; then
echo "Got ${LIBSSH2}.tar.gz"
else
echo "Failed to get ${LIBSSH2}.tar.gz. Aborting install!"
exit 0
fi
fi
if [ -a ${SRCDIR}/${AUTOCONF}.tar.gz ]; then
echo "Skipping wget of ${AUTOCONF}.tar.gz"
else
wget $WGETOPT <a href="ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/%24%7BAUTOCONF%7D.tar.gz" target="_blank">ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/${AUTOCONF}.tar.gz</a>
# If primary mirror fails, use the alternative mirror.
if [ -a ${SRCDIR}/${AUTOCONF}.tar.gz ]; then
echo "Got ${AUTOCONF}.tar.gz"
else
wget $WGETOPT <a href="ftp://ftp.gnu.org/gnu/autoconf/%24%7BAUTOCONF%7D.tar.gz" target="_blank">ftp://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz</a>
# Check to make sure the alternative mirror worked.
if [ -a ${SRCDIR}/${AUTOCONF}.tar.gz ]; then
echo "Got ${AUTOCONF}.tar.gz"
else
echo "Failed to get ${AUTOCONF}.tar.gz. Aborting install!"
exit 0
fi
fi
fi
if [ -a ${SRCDIR}/${SSH2}.tgz ]; then
echo "Skipping wget of ${SSH2}.tgz"
else
wget $WGETOPT <a href="http://pecl.php.net/get/%24%7BSSH2%7D.tgz" target="_blank">http://pecl.php.net/get/${SSH2}.tgz</a>
# If primary mirror fails, use the alternative mirror.
if [ -a ${SRCDIR}/${SSH2}.tgz ]; then
echo "Got ${SSH2}.tgz"
else
echo "Failed to get ${SSH2}.tgz. Aborting install!"
exit 0
fi
fi
# Extract the src files into the src directory.
cd ${SRCDIR}
echo "Extracting ${LIBSSH2}..."
tar xzf ${SRCDIR}/${LIBSSH2}.tar.gz > /dev/null
echo "Done."
cd ${SRCDIR}
echo "Extracting ${AUTOCONF}..."
tar xzf ${SRCDIR}/${AUTOCONF}.tar.gz > /dev/null
echo "Extracting ${SSH2}..."
tar xzf ${SRCDIR}/${SSH2}.tgz > /dev/null
echo "Done."
## Compile
#AUTOCONF
cd ${SRCDIR}/${AUTOCONF}
./configure --prefix=${PREFIXDIR}
make install
#LIBSSH2
cd ${SRCDIR}/${LIBSSH2}
./configure ${LIBSSH2FEATURES}
make all install
#SSH2
cd ${SRCDIR}/${SSH2}
$PHP_PREFIX/phpize
./configure ${SSH2FEATURES}
make
# Post install clean-up.
sleep 2s
cd ${SRCDIR} && clear
## End of Install
echo "Installation completed! Your php extension should be in ${SSH2}/modules" `date +%r`
#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment