-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·135 lines (111 loc) · 3.49 KB
/
install.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
##
# The MIT License (MIT)
#
# Copyright (c) 2024 Jacky Xie
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##
FAIL='\033[91m'
CLEAR='\033[0m'
GREEN='\033[92m'
WARNING='\033[0;33m'
install_fzf_dep() {
if ! [ -d /tmp/fzf_install ]; then
mkdir /tmp/fzf_install
fi
wget https://github.com/junegunn/fzf/releases/download/v0.56.0/fzf-0.56.0-linux_amd64.tar.gz \
-O /tmp/fzf_install/fzf.tar.gz \
-q
if [ $? -ne 0 ]; then
echo "$ERROR failed to install fzf $CLEAR"
exit 1
fi
cd /tmp/fzf_install
# untar and cp to usr/bin
tar -xvf fzf.tar.gz
sudo cp fzf /usr/local/bin/fzf
if [ $? -ne 0 ]; then
echo "$ERROR failed to copy fzf to /usr/local/bin $CLEAR"
exit 1
fi
# cleanup
cd /tmp/fzf_install
rm -r /tmp/fzf_install
echo "cleaned up /tmp/fzf_install"
# done
echo -e "$GREEN DONE $CLEAR"
}
check_fzf_dep() {
echo "Checking for existance of fzf in /usr/local/bin/"
if ! [ -f "/usr/local/bin/fzf" ]; then
echo -e "$WARNING fzf not found, installing... $CLEAR"
# installing dep
install_fzf_dep
return
fi
echo -e "$GREEN found in /usr/local/bin/fzf $CLEAR"
}
install_fcd() {
if ! [ -d /tmp/fcd_install ]; then
mkdir /tmp/fcd_install
fi
wget https://raw.githubusercontent.com/fafnirZ/fuzz_cd/refs/heads/main/fcd \
-O /tmp/fcd_install/fcdbin \
-q
if [ $? -ne 0 ]; then
echo "$ERROR failed to install fcd $CLEAR"
exit 1
fi
# check bin checksum
original_checksum=$(curl https://raw.githubusercontent.com/fafnirZ/fuzz_cd/refs/heads/main/checksum)
new_checksum=$(cat /tmp/fcd_install/fcdbin | md5sum | cut -d' ' -f1)
diff <(echo $original_checksum) <(echo $new_checksum)
if [ $? -ne 0 ];then
echo "$ERROR ERROR CHECKSUMS DONT MATCH $CLEAR"
exit 1
fi
# move to /usr/local/bin
chmod +x /tmp/fcd_install/fcdbin
sudo cp /tmp/fcd_install/fcdbin /usr/local/bin
if [ $? -ne 0 ]; then
echo "$ERROR failed to copy fcd to /usr/local/bin $CLEAR"
exit 1
fi
# cleanup
cd /tmp/fcd_install
rm -r /tmp/fcd_install
echo "cleaned up /tmp/fcd_install"
}
inject_bashrc() {
fn_sig="#fcd"
fn='fcd() { cd $(fcdbin $@); }'
cat ~/.bashrc | grep '#fcd'
if [ $? -ne 0 ]; then
echo "fcd function doesnt exist in bashrc...adding"
# NOTE MAKE SURE THIS IS AN APPEND
echo "" >> ~/.bashrc
echo $fn_sig >> ~/.bashrc
echo $fn >> ~/.bashrc
fi
echo "Please run source ~/.bashrc for effects to take effect in your current terminal"
}
check_fzf_dep
install_fcd
inject_bashrc