-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogSync
executable file
·61 lines (60 loc) · 1.28 KB
/
blogSync
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
#!/bin/bash
#-*-coding:UTF-8-*-
#Author: LeafLight
#Date: 2022-02-06
help(){
echo "Usage: Sychronize the blog data with github(when local data is more updated)"
echo "Syntax: blogSync [-h|m]"
}
# the comment message for `git commit -m`
MSG="nothing important or just forgotten"
MSG_flag=1
while getopts ":hm:" option; do
case $option in
h) #display help
help
exit;;
m) #commit message
MSG=$OPTARG
MSG_flag=0;;
\?)#invalid option
echo "Error: Invalid Option(s)"
help
exit;;
esac
done
########################################
#main
#check if the MSG remains unchanged
if [ $MSG_flag == $[1] ]; then
echo "Warning: MSG not defined manually"
echo "MSG: $MSG"
echo "__________________________________"
fi
#echo the command that will be executed for [Y/n]
echo "git add ."
echo "git commit -m "$MSG""
echo "git push origin hexo"
echo "hexo g"
echo "hexo d"
#[Y/n] before executing for security
# the while-case structure for [Y/n]
while true; do
read -r -p "Commands above will be executed, are u sure? [Y/n]" input
case $input in
[yY]) #yes
echo "Sychronization Starts!"
break;;
[nN]) #no
echo "Stopped!"
exit 0;;
*) #invalid input
echo "Invalid Input...try again"
esac
done
#Syc. Commands
git add .
git commit -m "$MSG"
git push origin hexo
hexo g
hexo d