-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·93 lines (78 loc) · 1.96 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
#!/bin/bash
SC_ROOT=${SC_ROOT:-~/.sc}
SC_REPO=${SC_REPO:-wingkwong/sc}
SC_REMOTE=${SC_REMOTE:-https://github.com/${SC_REPO}.git}
SC_BRANCH=${SC_BRANCH:-master}
clone_from_git()
{
cat << EOF
--------------------------------------------------------
Cloning sc from ${SC_REMOTE}
--------------------------------------------------------
EOF
git clone --depth=1 --branch "$SC_BRANCH" "$SC_REMOTE" "$SC_ROOT" ||
{
echo "Failed to git clone sc"
exit 1
}
}
create_sc_rc()
{
cat << EOF
--------------------------------------------------------
Creating RC file
--------------------------------------------------------
EOF
if [ -f $SC_ROOT/.sc_rc ] || [ -h $SC_ROOT/.sc_rc ]; then
echo ".sc_rc exists"
exit 1
fi
cp $SC_ROOT/.sc_rc.default $SC_ROOT/.sc_rc || {
echo "Failed to copy .sc_rc.default"
exit 1
}
chmod +x $SC_ROOT/sc.sh
cat << EOF
--------------------------------------------------------
Creating ~/.bash_profile backup
--------------------------------------------------------
EOF
cp ~/.bash_profile $SC_ROOT/.bash_profile.bak
cat << EOF
--------------------------------------------------------
Writing ~/.bash_profile
--------------------------------------------------------
EOF
# TODO: To check if it already exists
{
echo "if [ -f $SC_ROOT/.sc_rc ]; then";
echo " . $SC_ROOT/.sc_rc";
echo "fi"
} >> ~/.bash_profile
cat << EOF
--------------------------------------------------------
Source ~/.bash_profile
--------------------------------------------------------
EOF
source ~/.bash_profile
}
install()
{
cat << EOF
__________
/ ___/ ___/
(__ ) /__
/____/\___/
EOF
if [ -d "$SC_ROOT" ]; then
echo "You have already installed sc."
exit 1
fi
if [ ! command -v "git" >/dev/null 2>&1 ]; then
echo "Git is required. Please retry after you have installed it."
exit 1
fi
clone_from_git
create_sc_rc
}
install