1 新建install.sh,内容如下

  1. #!/bin/bash
  2. set -e
  3. if [ ! $1 ] || [ "$1"x == "-h"x ] || [ "$1"x == "--help"x ];then
  4. echo -e "
  5. \033[32mone-click install samtools, bcftools and htslib\033[0m
  6. usage: \033[1m`basename $0` version [prefix]\033[0m
  7. version the version to install, eg. 1.9
  8. prefix the path to install, default: `dirname $(pwd)`/v\$version
  9. contact: suqingdong@novogene.com"
  10. exit
  11. fi
  12. VERSION=$1
  13. if [ $2 ];then
  14. INSTALL_DIR=$2
  15. else
  16. SOURCE_DIR=`pwd`
  17. INSTALL_DIR=`dirname $SOURCE_DIR`/v${VERSION}
  18. fi
  19. for name in samtools bcftools htslib;do
  20. if [ ! -f $name-$VERSION.tar.bz2 ];then
  21. wget -c https://github.com/samtools/$name/releases/download/$VERSION/$name-$VERSION.tar.bz2
  22. fi
  23. done
  24. tar -xf htslib-${VERSION}.tar.bz2
  25. cd htslib-${VERSION}
  26. ./configure --prefix=${INSTALL_DIR} --disable-lzma
  27. make && make install
  28. cd ..
  29. tar -xf bcftools-${VERSION}.tar.bz2
  30. cd bcftools-${VERSION}
  31. ./configure --prefix=${INSTALL_DIR} --disable-lzma \
  32. --with-htslib=${INSTALL_DIR}
  33. make && make install
  34. cd ..
  35. tar -xf samtools-${VERSION}.tar.bz2
  36. cd samtools-${VERSION}
  37. ./configure --prefix=${INSTALL_DIR} --disable-lzma \
  38. --with-htslib=${INSTALL_DIR}
  39. make && make install
  40. echo "
  41. export PATH=${INSTALL_DIR}/bin:\$PATH
  42. export LD_LIBRARY_PATH=${INSTALL_DIR}/lib:\$LD_LIBRARY_PATH
  43. " > ${INSTALL_DIR}/source_this
  44. chmod 755 ${INSTALL_DIR}/source_this
  45. cd ..
  46. rm -rf *-${VERSION}*
  47. echo -e '\033[1;32minstall done !\033[0m'

2 在软件安装目录执行以下命令

  1. sh install.sh 1.9

3 使用时,source一下source_this文件即可