kuoe0
9/19/2013 - 7:47 AM

編譯採用 OpenSSL 的 git,避免某些網路環境下發生 gnutls_handshake() failed 的情況!

編譯採用 OpenSSL 的 git,避免某些網路環境下發生 gnutls_handshake() failed 的情況!

#!/usr/bin/env bash
# =============================================================================
#      FileName: Install_OpenSSL_GIT.sh
#          Desc: Build GIT with OpenSSL and Install it 
#   Environment: Ubuntu 13.04 amd64
#         Usage: ./Install_OpenSSL_GIT.sh
#        Author: KuoE0 <kuoe0.tw@gmail.com>
#      HomePage: http://kuoe0.tw/
#     Copyright: BSD License (C) 2013 KuoE0
# =============================================================================
work_path=/tmp/git-openssl
echo -e "\x1b[33msudo apt-get -y install build-essential fakeroot dpkg-dev\x1b[0m"
sudo apt-get -y install build-essential fakeroot dpkg-dev
mkdir $work_path
cd $work_path
echo -e "\x1b[33msudo apt-get source git\x1b[0m"
sudo apt-get source git
echo -e "\x1b[33msudo apt-get -y build-dep git\x1b[0m"
sudo apt-get -y build-dep git
echo -e "\x1b[33msudo apt-get -y install libcurl4-openssl-dev\x1b[0m"
sudo apt-get -y install libcurl4-openssl-dev

find . -name "*.dsc" | xargs sudo dpkg-source -x
dir=`find $work_path -maxdepth 1 -mindepth 1 -type d`
cd $dir

# replace gnutls with openssl
echo -e "\x1b[33mreplace gnutls with openssl\x1b[0m"
sudo sed --in-place 's/libcurl4-gnutls-dev/libcurl4-openssl-dev/g' debian/control

# remove TEST target
sudo sed --in-place '/TEST =test/d' debian/rules
echo -e "\x1b[33mbuild git...\x1b[0m"
sudo dpkg-buildpackage -rfakeroot -b
find $work_path -maxdepth 1 -name "git_*.deb" -exec sudo dpkg -i {} \;

echo -e "\x1b[33mset to not upgrade them\x1b[0m"
# prevent to upgrade from APT
dpkg --get-selections | grep git > $work_path/GIT
sed -e 's/install/hold/' $work_path/GIT | sudo dpkg --set-selections

cd /tmp
sudo rm -r $work_path