-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·133 lines (116 loc) · 4.68 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
#!/usr/bin/env bash
cols=$(tput cols) # ───────────── Get the width of the terminal.
cols=$(($cols - 3)) # ─────────── Substract 3 to prevent overflow.
echo -n '┌' # ──────────────────┐ Print upper part of load bar box.
printf '─%.0s' $(seq 0 $cols) # ┤ String multiplication in bash.
echo '┐' # ─────────────────────┘
echo -n '│' # ──────────────────┐
printf ' %.0s' $(seq 0 $cols) # │ Print middle part uf load bar box.
echo '│' # ─────────────────────┘
echo -n '└' # ──────────────────┐
printf '─%.0s' $(seq 0 $cols) # │ Print bottom part uf load bar box.
echo -ne '┘\r' # ───────────────┘
echo -ne '\033[1A\033[2C' # ───── Set cursor to begining of loading bar.
cols=$(($cols - 1)) # ─────────── Substract one to account for padding.
# Start main installation loop to draw progress bar.
echo -en '\033[s' # Save cursor's position to start of load bar.
installed=0
i=0
cols=$(($cols - 1))
size=$(($cols / 3))
while [ $installed != 1 ]; do
# 1 . Create install directory for files.
if sudo mkdir /opt/checker 2> /dev/null ; then
echo -ne '\033[92m'
printf '█%.0s' $(seq 0 $size)
echo -ne '\033[m'
echo -en '\033[s' # Store cursor's position progrss in loading bar.
echo ""
echo ""
echo -en "\t🔥 Created installation dir \033[92m/opt/checker\033[m "
else
echo -ne '\033[91m'
printf '█%.0s' $(seq 0 $size)
echo -ne '\033[m'
echo -en '\033[s'
echo ""
echo ""
echo -en "\t🤢 Dir \033[91m/opt/checker\033[m already exists."
fi
# echo -en '\033[u' # Reset cursor to saved position above.
# Due to zsh not working with the command above... this below...
echo -en '\r'
echo -en '\033[2A'
echo -en '\033[3C'
echo -en "\033[${size}C"
# 2. Clone repository into installation directory.
if sudo git -C /opt/checker clone https://github.com/Mahiuha/alx-cheker.git 2> /dev/null; then
echo -ne '\033[92m'
printf '█%.0s' $(seq 0 $size)
echo -ne '\033[m'
echo -en '\033[s'
echo ""
echo ""
echo ""
echo -en "\t🔥 Cloned repository into \033[92m/opt/checker\033[m"
else
echo -ne '\033[91m'
printf '█%.0s' $(seq 0 $size)
echo -ne '\033[m'
echo -en '\033[s'
echo ""
echo ""
echo ""
echo -en "\t🤮 Couldn't clone repository in \033[91m/opt/checker.\033[m"
fi
# echo -en '\033[u' # Reset cursor to saved position above.
# Due to zsh not working with the command above... this below...
echo -en '\r'
echo -en '\033[3A'
echo -en '\033[3C'
echo -en "\033[${size}C"
echo -en "\033[${size}C"
# 3. Create symbolic link to script for running checker command.
#
# This is done to allow you to run the checker command
# from anywhere in your machine.
#
if sudo ln -s /opt/checker/alx_checker/checker /usr/local/bin/checker 2> /dev/null ; then
echo -ne '\033[92m'
printf '█%.0s' $(seq 0 $(($size - 2)))
echo -ne '\033[m'
echo ""
echo ""
echo ""
echo ""
echo -en "\t🔥 Created symlink file:\n" \
"\t\tfrom : \033[92m/usr/local/bin/checker ────────────┐\033[m\n" \
"\t\tto : \033[92m/opt/checker/alx_checker/checker ──┘\033[m\n"
else
echo -ne '\033[91m'
printf '█%.0s' $(seq 0 $(($size - 2)))
echo -ne '\033[m'
echo -en '\033[s'
echo ""
echo ""
echo ""
echo ""
echo -e "\t🥶 Couldn't create Symbolic \033[91m/usr/local/bin/checker\033[m file.\n"
break
fi
(( installed++ ))
echo ""
echo -e "X_Checker \033[92mv0.01\033[m has been installed \033[92msuccesfully\033[m."
echo -e "You may now run:\n"
echo -e "\t\033[92mchecker\033[m\n"
echo -e "In order to start the checker console."
done
# Error if Not installed or already installed.
if [ $installed != 1 ]; then
echo -e " This could be caused by many reasons...\n"
echo " The main one is that the checker is already installed."
echo " If you are unable to launch the console."
echo -e " Please run these commands to erase the installation files and try installing again.\n"
echo -e "\tsudo rm /opt/checker/ -rf"
echo -e "\tsudo rm /usr/local/bin/checker\n"
fi