Update Makefile and install script

fzf may not run correctly on some OS even when the binary the platform
is successfully downloaded. The install script is updated to check if
the system has no problem running the executable and fall back to Ruby
version when necessary.
This commit is contained in:
Junegunn Choi 2015-01-05 12:21:26 +09:00
parent 4a5142c60b
commit 82156d34cc
2 changed files with 34 additions and 22 deletions

52
install
View File

@ -2,8 +2,8 @@
version=0.9.0 version=0.9.0
cd `dirname $BASH_SOURCE` cd $(dirname $BASH_SOURCE)
fzf_base=`pwd` fzf_base=$(pwd)
ask() { ask() {
read -p "$1 ([y]/n) " -n 1 -r read -p "$1 ([y]/n) " -n 1 -r
@ -11,15 +11,26 @@ ask() {
[[ ! $REPLY =~ ^[Nn]$ ]] [[ ! $REPLY =~ ^[Nn]$ ]]
} }
check_binary() {
echo "- Checking fzf executable"
echo -n " - "
if ! "$fzf_base"/bin/fzf --version; then
binary_error="Error occurred"
fi
}
download() { download() {
echo "Downloading fzf executable ($1) ..." echo "Downloading fzf executable ($1) ..."
if [ -x "$fzf_base"/bin/fzf ]; then if [ -x "$fzf_base"/bin/fzf ]; then
ask "- fzf already exists. Download it again?" || return 0 if ! ask "- fzf already exists. Download it again?"; then
check_binary
return
fi
fi fi
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "- Failed to create bin directory." binary_error="Failed to create bin directory"
return 1 return
fi fi
local url=https://github.com/junegunn/fzf-bin/releases/download/snapshot/${1}.tgz local url=https://github.com/junegunn/fzf-bin/releases/download/snapshot/${1}.tgz
@ -28,35 +39,36 @@ download() {
elif which wget > /dev/null; then elif which wget > /dev/null; then
wget -O - $url | tar -xz wget -O - $url | tar -xz
else else
echo "- curl or wget required to download fzf executable." binary_error="curl or wget not found"
return 1 return
fi fi
if [ ! -f $1 ]; then if [ ! -f $1 ]; then
echo "- Failed to download ${1}." binary_error="Failed to download ${1}"
return 1 return
fi fi
mv $1 fzf && chmod +x fzf && cd - > /dev/null && echo mv $1 fzf && chmod +x fzf && check_binary
} }
# Try to download binary executable # Try to download binary executable
archi=$(uname -sm) archi=$(uname -sm)
downloaded=0 binary_available=1
binary_available=0 binary_error=""
if [ "$archi" = "Darwin x86_64" ]; then if [ "$archi" = "Darwin x86_64" ]; then
binary_available=1 download fzf-$version-darwin_amd64
download fzf-$version-darwin_amd64 && downloaded=1
elif [ "$archi" = "Linux x86_64" ]; then elif [ "$archi" = "Linux x86_64" ]; then
binary_available=1 download fzf-$version-linux_amd64
download fzf-$version-linux_amd64 && downloaded=1 else
binary_available=0
fi fi
if [ $downloaded -ne 1 ]; then cd "$fzf_base"
if [ -n "$binary_error" ]; then
if [ $binary_available -eq 0 ]; then if [ $binary_available -eq 0 ]; then
echo -n "No prebuilt binary for $archi ... " echo "No prebuilt binary for $archi ... "
else else
echo -n "Failed to download binary executable ... " echo " - $binary_error ... "
fi fi
echo "Installing legacy Ruby version ..." echo "Installing legacy Ruby version ..."
@ -304,7 +316,7 @@ if [ -n "$(which fish)" ]; then
has_fish=1 has_fish=1
echo -n "Generate ~/.config/fish/functions/fzf.fish ... " echo -n "Generate ~/.config/fish/functions/fzf.fish ... "
mkdir -p ~/.config/fish/functions mkdir -p ~/.config/fish/functions
if [ $downloaded -eq 0 ]; then if [ -n "$binary_error" ]; then
cat > ~/.config/fish/functions/fzf.fish << EOFZF cat > ~/.config/fish/functions/fzf.fish << EOFZF
function fzf function fzf
$fzf_cmd \$argv $fzf_cmd \$argv

View File

@ -44,8 +44,8 @@ clean:
docker: docker:
docker build -t junegunn/ubuntu-sandbox . docker build -t junegunn/ubuntu-sandbox .
linux64: linux64: docker
docker run -i -t -u jg -v $(shell cd ..; pwd):/fzf junegunn/ubuntu-sandbox \ docker run -i -t -u jg -v $(shell cd ..; pwd):/fzf junegunn/ubuntu-sandbox \
/bin/bash -ci 'cd ~jg/go/src/github.com/junegunn/fzf/src; make' /bin/bash -ci 'cd ~jg/go/src/github.com/junegunn/fzf/src; make'
.PHONY: build release install linux64 clean docker run .PHONY: build release install linux64 clean docker