-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.bash
executable file
·228 lines (204 loc) · 5.17 KB
/
setup.bash
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
# Setup Manubot
# Based on https://github.com/manubot/rootstock/blob/main/SETUP.md
# This is designed to be run from the bash terminal
# Stop on first error.
set -e
usage() {
echo "Usage: $0 [--owner text] [--repo text] [--yes]"
echo "Guides the user through the creation of a new Manubot repository for their manuscript."
echo
echo "If no options are supplied a fully interactive process is used."
echo "OWNER and REPO refer to the details of your manuscript repo location:"
echo "i.e. https://github.com/OWNER/REPO."
echo
echo "Options:"
echo " -o --owner GitHub user or organisation name."
echo " -r --repo Name of the repository for your new manuscript."
echo " -y --yes Non-interactive mode. Continue script without asking for confirmation that the repo exists."
echo " -s --ssh Use SSH to authenticate GitHub account. HTTPS is used by default."
echo " Option only effective if --yes is also set, otherwise answer given in user interaction takes precedence."
echo " -h --help Display usage information."
1>&2; exit 1; }
# Check if to continue
check(){
while true
do
echo "Once you have created your repo press enter to continue setup,"
read -r -p "or type exit to quit now: " input
case $input in
"")
echo
echo "Continuing Setup..."
echo
break
;;
[eE][xX][iI][tT])
exit 1
;;
*)
echo
echo "Invalid input, try again..."
echo
;;
esac
done
}
# Option strings
SHORT=o:r:hys
LONG=owner:,repo:,help,yes,ssh
YES=0 # continue when prompted
AUTH=0 # used https or ssh auth
# read the options
OPTS=$(getopt --options $SHORT --long $LONG --name "$0" -- "$@")
if [ $? != 0 ] ; then echo "Failed to parse options...exiting." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
# extract options and their arguments into variables.
while true ; do
case "$1" in
-o | --owner )
shift;
OWNER=$1
shift
;;
-r | --repo )
REPO="$2"
shift 2
;;
-y | --yes )
YES=1
shift
;;
-s | --ssh )
AUTH=1;
shift
;;
-- )
shift
break
;;
-h | --help )
shift
usage
exit 1
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
if [ -z "${OWNER}" ] || [ -z "${REPO}" ]; then
echo "This script will take you through the setup process for Manubot."
echo "First, we need to specify where to create the GitHub repo for your manuscript."
echo
echo "The URL will take this format: https://github.com/OWNER/REPO."
echo "OWNER is your username or organisation"
echo "REPO is the name of your repository"
echo
read -r -p "Type in the OWNER now:" input
OWNER=$input
read -r -p "Type in the REPO now:" input
REPO=$input
fi
# If using interactive mode, check remote repo exists.
if [[ "$YES" == '0' ]]; then
while true
do
echo
read -r -p "Have you manually created https://github.com/${OWNER}/${REPO}? [y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo
echo "Continuing Setup..."
echo
break
;;
[nN][oO]|[nN])
echo
echo "Go to https://github.com/new and create https://github.com/${OWNER}/${REPO}"
echo "Note: the new repo must be completely empty or the script will fail."
echo
check
break
;;
*)
echo
echo "Invalid input, try again..."
echo
;;
esac
done
else
echo "Setting up https://github.com/${OWNER}/${REPO}"
fi
# Clone manubot/rootstock
echo
echo "Cloning Rootstock..."
echo
git clone --single-branch https://github.com/manubot/rootstock.git ${REPO}
cd ${REPO}
echo
echo "Setup tracking of remote..."
# Configure remotes
git remote add rootstock https://github.com/manubot/rootstock.git
# Check auth method
if [[ "$YES" == '0' ]]; then
while true
do
echo
read -r -p "Would you like to use SSH to authenticate your GitHub account? [y/n] " input
case $input in
[yY][eE][sS]|[yY])
AUTH=1
break
;;
[nN][oO]|[nN])
AUTH=0
break
;;
*)
echo
echo "Invalid input, try again..."
echo
;;
esac
done
fi
case $AUTH in
0)
echo
echo "Seting origin URL using its https web address"
echo
git remote set-url origin https://github.com/${OWNER}/${REPO}.git
;;
1)
echo
echo "Seting origin URL using SSH"
echo
git remote set-url origin [email protected]:$OWNER/$REPO.git
;;
esac
git push --set-upstream origin main
# To use GitHub Actions only:
echo "Setup for GitHub Actions ONLY..."
# remove AppVeyor config
git rm .appveyor.yml
# remove ci/install.sh (only used by AppVeyor)
git rm ci/install.sh
# Update README
echo "Updating README..."
# Perform substitutions
sed "s/manubot\/rootstock/${OWNER}\/${REPO}/g" README.md > tmp && mv -f tmp README.md
sed "s/manubot\.github\.io\/rootstock/${OWNER}\.github\.io\/${REPO}/g" README.md > tmp && mv -f tmp README.md
echo "Committing rebrand..."
git add --update
git commit --message "Brand repo to $OWNER/$REPO"
git push origin main
echo
echo "Setup complete"
echo
echo "The new repo has been created at $(pwd)"
echo
echo "A good first step is to modify content/metadata.yaml with the relevant information for your manuscript."
echo