-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-fd.sh
executable file
·61 lines (55 loc) · 1.49 KB
/
install-fd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -euo pipefail
prefix=/usr/local
if [[ ${1:-} == -l ]]; then
prefix=~/.local
fi
if [[ $EUID != 0 && $prefix == /usr/local ]]; then
exec sudo "$0" "$@"
fi
use_deb=0
if grep -Pq '^ID=(debian|ubuntu)$' /etc/os-release 2>/dev/null; then
use_deb=1
fi
ver=$(curl -fsSL https://github.com/gitapi/repos/sharkdp/fd/releases/latest | grep -Po '(?<=/sharkdp/fd/releases/download/v)([0-9.]+)(?=/fd_\1_amd64\.deb)' | head -n1)
binname=fd
if (( $use_deb )); then
if type fdfind &>/dev/null; then
binname=fdfind
fi
fname=fd_${ver}_amd64.deb
else
dir=fd-v$ver-x86_64-unknown-linux-musl
fname=$dir.tar.gz
fi
url=https://github.com/sharkdp/fd/releases/download/v$ver/$fname
echo "Installed: $($binname --version 2>/dev/null | grep -Po '(?<= )[0-9.]+$' || echo "Not installed")"
echo "Remote latest: $ver"
if [[ ${1:-} == -n ]]; then
exit
fi
if [[ $binname == fdfind ]]; then
echo "You have to uninstall fd-find package to proceed installation. Exiting."
exit 1
fi
mkdir -p $prefix/src
cd $prefix/src
curl -fsSLo $fname $url
if (( $use_deb )); then
dpkg -i $fname || apt -f install fd
else
rm -rf $dir
tar -xf $fname
cd $dir
mkdir -p $prefix/bin
cp fd $prefix/bin/fd
mkdir -p $prefix/share/man/man1
cp fd.1 $prefix/share/man/man1/fd.1
if [[ $EUID == 0 ]]; then
mkdir -p /etc/bash_completion.d
cp autocomplete/fd.bash /etc/bash_completion.d/fd.bash
else
mkdir -p $prefix/share/bash-completion/completions
cp autocomplete/fd.bash $prefix/share/bash-completion/completions/fd.bash
fi
fi