-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
first_commit.sh
executable file
·56 lines (46 loc) · 1.44 KB
/
first_commit.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
#!/usr/bin/env bash
# check git
command -v git >/dev/null 2>&1 || {
echo >&2 "I require git but it's not installed!"; exit 1;
}
# check username
user_name=$(git config user.name)
if [[ ${user_name}_x != "_x" ]]; then
echo "Get github's username: ${user_name}."
else
echo "Please set github's username firstly!"
command -v open >/dev/null 2>&1 || {
echo >&2 "FYI, https://yuzhouwan.com/posts/30041/#Git-Config"; exit 1;
}
open "https://yuzhouwan.com/posts/30041/#Git-Config"
exit 1
fi
# check SSH
# shellcheck disable=SC2126
ssh_succ=$(ssh -T [email protected] 2>&1 | grep "successfully" | wc -l)
if [[ $(echo "${ssh_succ}" | bc) -eq 1 ]]; then
echo "You've successfully authenticated."
else
echo "Please set SSH to github!"
command -v open >/dev/null 2>&1 || {
echo >&2 "FYI, https://yuzhouwan.com/posts/30041/#SSH-%E5%85%8D%E5%AF%86"; exit 1;
}
open "https://yuzhouwan.com/posts/30041/#SSH-%E5%85%8D%E5%AF%86"
exit 1
fi
# build project
mkdir algorithm
cd algorithm || {
echo >&2 "Unable to create the algorithm directory!"; exit 1;
}
git init
git remote add origin [email protected]:"${user_name}"/algorithm.git
git remote add upstream [email protected]:asdf2014/algorithm.git
git pull upstream master:master
# build commit
mkdir -p Codes/"${user_name}"
echo "${user_name}" > Codes/"${user_name}"/README.md
git add .
git commit -m "Add ${user_name}'s first commit"
# push commit
git push upstream master