-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·107 lines (85 loc) · 2.62 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
#!/bin/bash
cereal_dir_src="."
cereal_exe_src="$cereal_dir_src/cereal.sh"
cereal_com_src="$cereal_dir_src/cereal_complete.sh"
cereal_dir_dst=~/.cereal
cereal_exe_dst="$cereal_dir_dst/cereal"
cereal_com_dst="$cereal_dir_dst/cereal_complete"
cereal_glb_dst="/usr/local/bin/cereal"
entry=\
"
# cereal
if [ -r $cereal_com_dst ]
then
. $cereal_com_dst
fi
# cereal
"
function hightlight
{
if [ "$1" == ERROR ]
then
color=3
elif [ "$1" == "WARNING" ]
then
color=9
else
color=6
fi
echo "$(tput setaf $color)$2$(tput sgr0)"
}
function log
{
echo -e "$(hightlight "$1" "$(basename "$0")":~) $2"
}
function confirm
{
read -r -p "$(log "WARNING" "$1: ")" answer
if [[ "$answer" != [yY] ]] && [[ "$answer" != [yY][eE][sS] ]] && [ ! -z "${answer// }" ]
then
return 1
fi
return 0
}
echo \
"
$(tput setaf 5) X
$(tput setaf 5) //
$(tput setaf 5) 8o8o8o8o8o8o8o8// BBBBBBBB $(tput setaf 0)BBBBBBB BBBBBBB BBBBBBB BBBBB BB
$(tput setaf 5) o8o8o8o8o8o8o8o8o8o8 BB $(tput setaf 0)BB BB BB BB BB BB BB
$(tput setaf 5)========================== BB $(tput setaf 0)BBBBBBB BBBBBBB BBBBBBB BBBBBBB BB
$(tput setaf 5) \... .../ BB $(tput setaf 0)BB BB BBB BB BB BB BB
$(tput setaf 5) \________________/ BBBBBBBB $(tput setaf 0)BBBBBBB BB BBB BBBBBBB BB BB BBBBBBB
$(tput sgr0)
"
if [ "$1" == "--uninstall" ] && confirm "Are you sure you want to proceed"
then
log "WARNING" "Removing directory '$cereal_dir_dst'"
rm -riv "$cereal_dir_dst"
log "WARNING" "Removing cereal from your PATH"
sudo rm -iv "$cereal_glb_dst"
if confirm "Should any existing autocompletion entry be removed from '.bashrc'"
then
sed -i '/# cereal/,/# cereal/d' ~/.bashrc
fi
exit 0
fi
log "MESSAGE" "Creating directory '$cereal_dir_dst'"
mkdir -p "$cereal_dir_dst"
log "MESSAGE" "Installing cereal at '$cereal_dir_dst'"
cp -i "$cereal_exe_src" "$cereal_exe_dst"
log "MESSAGE" "Adding cereal to your PATH"
if [ ! -f "$cereal_glb_dst" ] || confirm "Should '$cereal_glb_dst' be overwritten"
then
sudo ln -sf "$cereal_exe_dst" "$cereal_glb_dst"
fi
if confirm "Should an autocompletion rule be added to '.bashrc'"
then
sed -i '/# cereal/,/# cereal/d' ~/.bashrc
echo -n "$entry" >> ~/.bashrc
if [ ! -w "$cereal_com_dst" ] || confirm "Should '$cereal_com_dst' be overwritten"
then
cp "$cereal_com_src" "$cereal_com_dst"
fi
log "MESSAGE" "Restarting your shell is probably required"
fi