Skip to content

Instantly share code, notes, and snippets.

@rcmdnk rcmdnk/linux_install.sh
Last active Aug 29, 2015

Embed
What would you like to do?
#!/usr/bin/env bash
# Settings {{{
TMPDIR=~/tmp
INSTALLDIR=$HOME/usr/local
STOWDIR=$HOME/usr/local/stow
IS_CLEANUP=1
XSTOW_VERSION=1.0.2
GIT=1
SCREEN=1
SCREEN_UTF8_PATCH=1
TEXINFO=1
VIM=1
EXPAT_VERSION=2.1.0
BZIP2_VERSION=1.0.6
TERMCAP_VERSION=1.3.1
PYTHON_VERSION=2.7.9
#}}}
# Global variables {{{
GITCMD=$(which git)
STOWCMD=xstow
LDL_PATHES=($(echo $LD_LIBRARY_PATH|tr : ' '))
TARGZ=""
PACKAGE=""
_CONFIGURE=""
_MAKE="make"
_MAKE_INSTALL="make install"
CONFIGURE="$_CONFIGURE"
MAKE="$_MAKE"
MAKE_INSTALL="$_MAKE_INSTALL"
# }}}
# functions {{{
search_library () {
for d in ${LDL_PATHES[@]};do
if [ -f "$d/${1}.so" ];then
return 0
elif [ -f "$d/${1}.a" ];then
return 0
fi
done
return 1
}
get_latest_targz () {
TARGZ=$(curl "$1/?C=M;O=A" 2>/dev/null|grep ".tar.gz<"|grep "$PACKAGE"|grep -v "\-doc\-"|tail -n1|
awk '{split($0, tmp, "</a>")}
{n=split(tmp[1], tmp2, ">")}{print tmp2[n]}')
}
wget_wrap () {
wget --no-check-certificate $1 >&/dev/null
if [ $? -ne 0 ];then
echo FAITAL ERROR: failed to get $1
exit 1
fi
}
get_pac () {
wget_wrap $1
file=${1##*/}
if [[ $file =~ .tar.gz$ ]] || [[ $file =~ .tgz$ ]];then
tar xzf $file
elif [[ $file =~ .tar.bz2$ ]];then
tar jxf $file
elif [[ $file =~ .zip$ ]];then
unzip -q $file
else
echo "$1: file type is unknown."
exit 1
fi
}
stow_install () {
if [ "$CONFIGURE" = "NONE" ];then
:
elif [ "$CONFIGURE" = "" ];then
CFLAGS="-L$INSTALLDIR/lib -I$INSTALLDIR/include" \
CPPFLAGS="-L$INSTALLDIR/lib -I$INSTALLDIR/include" \
LDFLAGS="-L$INSTALLDIR/lib" \
./configure --prefix="$STOWDIR/$1" >/dev/null
else
eval $CONFIGURE >/dev/null
fi
eval $MAKE >/dev/null
eval $MAKE_INSTALL >/dev/null
cd $STOWDIR
if [[ "$1" =~ stow-* ]];then
STOWCMD=$STOWDIR/$1/bin/xstow
fi
$STOWCMD -f $1
if [ $IS_CLEANUP -eq 1 ];then
rm -rf $TMPDIR/${1%%-*}*
fi
CONFIGURE="$_CONFIGURE"
MAKE="$_MAKE"
MAKE_INSTALL="$_MAKE_INSTALL"
}
install_pac () {
package=$(echo ${1##*/}|cut -d'-' -f1)
cd $TMPDIR
get_pac $1
v=`ls -d ${package}-*|grep -v tar.gz`
cd $v
stow_install $v
}
install_latest_targz () {
get_latest_targz $1
install_pac $1/$TARGZ
}
install_latest_gnu () {
set_package $1
install_latest_targz http://ftp.gnu.org/gnu/$1/
}
banner () {
echo
echo "#####################################################"
echo "# Installing $1..."
echo "#####################################################"
echo
}
set_package () {
PACKAGE=$1
banner $PACKAGE
}
#}}}
# First, prepare $TMPDIR {{{
mkdir -p $TMPDIR
# }}}
# Install stow {{{
if ! type -a $STOWCMD >& /dev/null;then
set_package xstow
install_pac \
http://downloads.sourceforge.net/xstow/xstow-${XSTOW_VERSION}.tar.bz2
fi
# }}}
# Install Git {{{
if [ $GIT -eq 1 ] && [ ! -f $STOWDIR/../bin/git ];then
if ! type -a m4 >& /dev/null;then
install_latest_gnu m4
fi
if ! type -a autoconf >& /dev/null;then
install_latest_gnu autoconf
fi
if ! search_library libcurl;then
set_package curl
install_latest_targz http://curl.haxx.se/download/
fi
if ! search_library libexpat;then
set_package expat
install_pac \
http://downloads.sourceforge.net/expat/expat-${EXPAT_VERSION}.tar.gz
fi
set_package git
cd $TMPDIR
wget_wrap https://github.com/git/git/archive/master.zip
unzip -q master.zip
cd git-master
make configure >/dev/null
v=git-`grep 'PACKAGE_VERSION=' configure|cut -d"'" -f2|sed s/.GIT//`
MAKE="make all"
stow_install $v
if [ $IS_CLEANUP -eq 1 ];then
rm -rf $TMPDIR/master.zip
fi
GITCMD="$INSTALLDIR/bin/git"
fi
#}}}
# Install GNU screen {{{
if [ $SCREEN -eq 1 ] && [ ! -f $STOWDIR/../bin/screen ];then
if ! type -a automake >& /dev/null;then
install_latest_gnu automake
fi
if ! type -a makeinfo >& /dev/null && [ $TEXINFO -eq 1 ];then
# To make information (not mandatory)
install_latest_gnu texinfo
fi
if ! search_library libncurses;then
install_latest_gnu ncurses
fi
set_package screen
cd $TMPDIR
$GITCMD clone git://git.sv.gnu.org/screen.git
cd screen
if [ $SCREEN_UTF8_PATCH -eq 1 ];then
wget_wrap https://gist.github.com/raw/626040/be6a04f0e64c56185ba5850415ac59dad4cd62a0/screen-utf8-nfd.patch
#wget_wrap http://zuse.jp/misc/screen-utf8-osc.diff
wget_wrap https://gist.githubusercontent.com/rcmdnk/143cb56d31335dbccf70/raw/4b3e175946f2366b4076088c1c8f2bbe65b32e16/screen-utf8-osc.diff
patch -p1 < screen-utf8-nfd.patch >/dev/null
patch -p1 < screen-utf8-osc.diff >/dev/null
fi
cd src/
v=screeen-$(grep Version ChangeLog |head -n1|cut -d' ' -f2)
./autogen.sh >/dev/null
CONFIGURE="CFLAGS=\"-L$INSTALLDIR/lib\" LDFLAGS=\"-L$INSTALLDIR/lib\"
./configure --prefix=\"$STOWDIR/$v\" --enable-colors256"
stow_install $v
fi
#}}}
# Install Vim {{{
if [ $VIM -eq 1 ] && [ ! -f $STOWDIR/../bin/vim ];then
if ! search_library libreadline;then
install_latest_gnu readline
fi
if ! python -c "import bz2" >&/dev/null;then
if ! search_library libbz2;then
# bzip2 library for Python, to install Mercurial
set_package bzip2
v=bzip2-${BZIP2_VERSION}
CONFIGURE="NONE"
MAKE="make -f Makefile-libbz2_so"
MAKE_INSTALL="make install PREFIX=$STOWDIR/$v"
install_pac \
http://www.bzip.org/${BZIP2_VERSION}/${v}.tar.gz
fi
# Need for Mercurial, too
set_package Python
install_pac http://www.python.org/ftp/python/$PYTHON_VERSION/Python-${PYTHON_VERSION}.tgz
fi
if ! type -a hg >& /dev/null;then
set_package Mercurial
cd $TMPDIR
get_pac http://selenic.com/repo/hg/archive/tip.tar.gz
cd Mercurial-*
v=Mercurial-$(tail -1 .hgtags|cut -d' ' -f2)
CONFIGURE="NONE"
MAKE="make build"
MAKE_INSTALL="python setup.py install --prefix=$STOWDIR/$v --force"
stow_install $v
if [ $IS_CLEANUP -eq 1 ];then
rm -rf $TMPDIR/tip.tar.gz
fi
fi
if ! search_library liblua;then
if ! search_library libtermcap;then
install_latest_gnu termcap
fi
set_package lua
lua_file=$(curl http://www.lua.org/ftp/ 2>/dev/null|grep -v all|grep "tar.gz"|head -1|
awk '{split($0, tmp, "</A>")}{n=split(tmp[1], tmp2, ">")}
{print tmp2[n]}')
CONFIGURE="NONE"
MAKE="make linux MYLIBS=\" -ltermcap\" MYLDFLAGS=\"
-L$INSTALLDIR/lib\" MYCFLAGS=\" -I$INSTALLDIR/include\""
MAKE_INSTALL="make install INSTALL_TOP=$STOWDIR/${lua_file%.tar.gz}"
install_pac \
http://www.lua.org/ftp/$lua_file
fi
set_package vim
cd $TMPDIR
hg clone https://vim.googlecode.com/hg/ vim
cd vim
v=vim-$(tail -n1 .hgtags|cut -d' ' -f2)
CONFIGURE="./configure LDFLAGS=\"-L$INSTALLDIR/lib/\"
--prefix=\"$STOWDIR/$v\" --with-lua-prefix=\"$INSTALLDIR\"
--with-local-dir=\"$INSTALLDIR\" --enable-luainterp=yes
--enable-perlinterp=yes --enable-pythoninterp=yes
--enable-python3interp=yes --enable-rubyinterp=yes --enable-cscope
--enable-multibyte --enable-gui=no"
stow_install $v
fi
#}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.