-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·79 lines (68 loc) · 1.59 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
#!/usr/bin/env bash
GITHUB_URL="https://raw.githubusercontent.com/abhi-g80/baksho/main/baksho-theme.sh"
BASHRC_BCK=$HOME/.bashrc.backup.$(date +"%Y-%m-%d")
usage() {
echo "Usage: $(basename $0) [-hu]" 2>&1
echo ' -h shows help'
echo ' -u updates baksho (does not append to bashrc)'
exit 1
}
check_curl() {
if [ "$(command -v curl)" ]; then
echo "curl found ✔"
else
echo "curl command not found, exiting ✗"
exit 1
fi
}
download() {
echo -n "downloading baksho theme"
curl -fsSL $GITHUB_URL -o "$HOME"/.baksho-theme.sh
if [ $? -eq 0 ]; then
echo " ✔"
else
echo " ✗"
echo "could not download, please run the curl command manually"
exit 1
fi
}
backup() {
echo -n "making a backup of your current bashrc"
cp "$HOME"/.bashrc "$BASHRC_BCK"
if [ $? -eq 0 ]; then
echo " ✔"
echo "backup created at $BASHRC_BCK"
else
echo " ✗"
echo "could not created backup"
exit 1
fi
}
append() {
echo -n "appending to bashrc"
echo "if [ -f ~/.baksho-theme.sh ]; then source ~/.baksho-theme.sh; fi" >> "$HOME"/.bashrc
if [ $? -eq 0 ]; then
echo " ✔"
echo "done... enjoy!"
else
echo " ✗"
echo "could not append"
exit 1
fi
}
if [ ${#} -gt 1 ]; then
usage
fi
while getopts ":hu" o; do
case "${o}" in
h)
usage
;;
u)
check_curl && download
;;
*)
check_curl && download && backup && append
;;
esac
done