-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
96 lines (84 loc) · 2.15 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
# Global variables
main_dir=~/.mew
main_executable=./bin/mew.sh
main_executable_c=./bin/mew
main_lib=./lib
bin_target=~/.mew/bin/
name=mew
go_faster=false
c_install=false
for i in "$@"; do
if [[ $i = "--fast" ]]; then
go_faster=true
elif [[ $i = "--c" ]]; then
c_install=true
fi
done
function hold() {
if $go_faster; then
return 0
fi
sleep ${1:-.2}
}
# Giving Executable permission to the mew.sh file
if [[ -f "./bin/mew.sh" ]]; then chmod +x ./bin/mew.sh; fi
# Giving Executable permission to the uninstall.sh file
if [[ -f "./uninstall.sh" ]]; then chmod +x ./uninstall.sh; fi
old_mew_flag=false
# Creating folder structure for mew
if [[ -f $main_dir || -d $main_dir ]]; then
echo "Old mew directory found"
hold
old_mew_flag=true
echo "Removing old mew directory"
hold
rm -rf $main_dir
fi
mkdir -p $main_dir
mkdir -p "$main_dir/bin/"
if $old_mew_flag; then
echo -e "\e[33mReinstalling mew...\e[0m"
else
echo -e "\e[33mInstalling mew...\e[0m"
fi
hold 1
if $c_install; then
if command -v shc > /dev/null 2>&1; then
shc -f ./bin/mew.sh -o ./bin/mew
mv ./bin/mew.sh.x.c ./bin/mew.c
else
echo "Please install 'csh' before continuing"
exit
fi
fi
# Copying mew binary and library to main directory
echo "Setting up Mew..."
hold
if $c_install; then
cp -rf -p $main_executable_c $bin_target
echo "Setting up c binary..."
else
cp -rf -p $main_executable $bin_target/$name
echo "Setting up script..."
fi
echo "Setting up library"
hold
cp -rf -p $main_lib $main_dir
# Setting environment variables for mew
echo "Adding environmental variables"
hold
export_query='export PATH="$PATH:$HOME/.mew/bin/"'
shell_targets=(~/.bashrc ~/.config/fish/config.fish ~/.zshrc ~/.kshrc ~/.tcshrc ~/.cshrc)
# Checking if SHELL available
for shell_target in ${shell_targets[@]}; do
if [[ -f $shell_target ]]; then
if ! grep -q "$export_query" $shell_target; then
{
echo -e "\n# mew path"
echo $export_query
} >> $shell_target
fi
fi
done
echo -e "\e[32mMew installed...\e[0m"
hold 0