-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.sh
153 lines (98 loc) · 3.51 KB
/
post.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#----------
# Written by: Kalcifer Kandari
# Date: 4 March 2016 06:32:29
#----------
# TODO Make sure these commands get run if they haven't already:
# eval "$(ssh-agent -s)"
# ssh-add ~/.ssh/kalciferkandari_rsa
#---------- == Section
#========== == Function
#----------
# Post
#----------
# Publish website.
# This script is useful because it is important that these commands run in order, otherwise the remote repositories will get out of sync, and typing the commands out takes a long time. The confirmations just allows errors to be corrected without other commands running after. The commands can be run without confirmation, which is very quick, but much less could result in problems if the commands fail.
#
# Run in '~/github/kalciferkandari/master' after updating the site.
#
# Example:
# sh post.sh "Commit message."
# `echo` a new line.
echo
#==========
# Confirm Do
#==========
# Ask the user if the command should be done.
function confirmDo() {
# Ask user to for a response.
echo "Run \`$1\`?"
read -p "[y/s/e (yes/skip/exit)] " text # `-p` adds a prompt as `echo -n ""` doesn't seem to work.
if [ "$text" == "y" ]; then
eval $1
echo "Done \`$1\`.\n"
elif [ "$text" == "e" ]; then
echo "Exiting."
exit 0
elif [ "$text" == "s" ]; then
echo "Skipping.\n"
else
echo "Enter a valid letter."
confirmDo "$1"
fi
}
#==========
# If All
#==========
function ifAll() {
if [ "$1" == "true" ]; then
echo "Running \`$2\`."
eval $2
echo "Done \`$2\`.\n"
else
confirmDo "$2"
fi
}
#==========
# Confirm All
#==========
# This needs to be a function because if the users inputs something invalid, then the function needs to be called within itself without calling the ifAll commands.
# Could probably merge confirmDo and confirmAll somehow.
function confirmAll() {
# Ask user to for a response.
echo "Do all commands with no confirmation? (Not recommended)."
read -p "[y/n/e (yes/no/exit)] " text1
if [ "$text1" == "y" -o "$text1" == "n" ]; then
# If the answer is either "y" or "n". These answers are the only one where the ifAll commands are applicable, so they need to be within this condition's block.
all=""
if [ "$text1" == "y" ]; then
echo "Doing all commands with no confirmation.\n"
all="true"
elif [ "$text1" == "n" ]; then
echo "Confirming commands.\n"
all="false"
fi
ifAll $all "git branch"
ifAll $all "git add ."
ifAll $all "git status"
ifAll $all "git commit -m \"$1\""
ifAll $all "git push origin master"
ifAll $all "jekyll build"
ifAll $all "cd ../gh-pages"
ifAll $all "git branch"
ifAll $all "git add ."
ifAll $all "git status"
ifAll $all "git commit -m \"$1\""
ifAll $all "git push origin gh-pages"
ifAll $all "cd ../master"
ifAll $all "git branch"
elif [ "$text1" == "e" ]; then
echo "Exiting."
exit 0
else
echo "Enter a valid letter."
confirmAll "$1"
fi
}
confirmAll "$1"
echo "Done. Exiting."
exit 0