-
Notifications
You must be signed in to change notification settings - Fork 3
/
installette.sh
112 lines (101 loc) · 3.56 KB
/
installette.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
#!/bin/bash
# Author: Nuno Carvalho (Kuninoto | nnuno-ca)
# LINUX
# ANSI COLOR CODES
CYAN='\033[0;36m'
BLUE='\033[1;34m'
RED='\033[0;31m'
GREEN='\033[0;32m'
WHITE='\033[0;37m'
RESET='\033[0m'
# UPDATE && UPGRADE SYSTEM
notify-send "Updating Your System. This may take some time..."
sudo apt update
sudo apt upgrade -y
echo -n -e "\n"
# PYTHON3 & PIP CHECK
if ! [ -x "$(command -v python3)" ]; then
echo -e "${RED}Error${RESET}: python3 is not installed."
echo -e "${CYAN}Proceeding to install python3...${RESET}"
sudo apt-get install -y python3
fi
if ! [ -x "$(command -v pip)" ]; then
echo -e "${RED}Error${RESET}: pip is not installed."
echo -e "${CYAN}Proceeding to install pip...${RESET}"
sudo apt-get install -y python3-pip
fi
for arg in "$@"
do
case "$arg" in
"-v" | "--vim"*)
echo -e "${BLUE}VIM${RESET}"
if [ -x "$(command -v vim)" ]; then
echo -e "${CYAN}Vim is already installed. Skipping...${RESET}"
else
echo "${CYAN}Installing Vim...${RESET}"
sudo apt-get install -y vim
fi;;
"-h" | "--header"*)
echo -e "${BLUE}42 HEADER${RESET}"
if [ -x "$(command -v vim)" ]; then
if grep -q 'MAIL=' "/home/$(whoami)/.bashrc"; then
echo -e "${CYAN}42Header is already installed. Skipping...${RESET}"
else
echo -e -n "${CYAN}Please insert your 42username${RESET}: "
read -r FT_User
{ echo "USER=$FT_User"
echo "MAIL=$FT_User@student.42.fr"
echo "export MAIL"; } >> ~/.bashrc
# mkdir with -p option creates dir if it doesnt exist; if it exists, does nothing."
mkdir -p ~/.vim/plugin
cp stdheader.vim ~/.vim/plugin/
echo "nmap <f1> :FortyTwoHeader<CR>" >> ~/.vimrc
echo -e "${GREEN}Sucessfully installed 42Header!${RESET}"
fi
else
echo -e "${RED}Error${RESET}: Vim is not installed."
echo -e "${CYAN}Run installette with the -v or --vim option${RESET}"
fi;;
"-n" | "--norminette"*)
echo -e "${BLUE}NORMINETTE${RESET}"
if [ -x "$(command -v norminette)" ]; then
echo -e "${CYAN}Norminette is already installed. Skipping...${RESET}"
else
echo -e "${CYAN}Installing Norminette...${RESET}"
python3 -m pip install --upgrade pip setuptools
python3 -m pip install norminette
if ! grep -q "/home/$(whoami)/.local/bin/" "/home/$(whoami)/.bashrc"; then
echo -e "${CYAN}Updating PATH...${RESET}"
echo -e "export PATH=\$PATH:/home/$(whoami)/.local/bin/" >> ~/.bashrc
source ~/.bashrc
fi
fi;;
"-f" | "--formatter"*)
echo -e "${BLUE}FORMATTER${RESET}"
if [ -x "$(command -v c_formatter_42)" ]; then
echo -e "${CYAN}c-formatter-42 is already installed. Skipping...${RESET}"
else
echo -e "${CYAN}Installing c_formatter_42...${RESET}"
pip3 install c-formatter-42
pip3 install --user c-formatter-42
if ! grep -q "/home/$(whoami)/.local/bin" "/home/$(whoami)/.bashrc"; then
echo -e "${CYAN}Updating PATH...${RESET}"
echo -e "export PATH=\$PATH:/home/$(whoami)/.local/bin/" >> ~/.bashrc
source ~/.bashrc
fi
fi;;
"-u" | "--uninstall"*)
echo -e "${BLUE}UNINSTALL${RESET}"
#sed's -i option edits files in place
sed -i '/^USER/d' ~/.bashrc
echo -e "${CYAN}Uninstalling 42Header...${RESET}"
sed -i '/^MAIL/d' ~/.bashrc
sed -i '/export MAIL/d' ~/.bashrc
sed -i '/nmap <f1> :Forty/d' ~/.vimrc
rm -rf ~/.vim/plugin/stdheader.vim
echo -e "${GREEN}Sucessfully uninstalled 42Header.${RESET}";;
esac
done
echo -e "\n${GREEN}Installette terminated!"
echo -e "${WHITE}Thanks for using Installette =)"
echo -e "Yours truly, ${CYAN}Nuno Carvalho (Kuninoto)\n${WHITE}nnuno-ca@student.42porto.com${RESET}"