-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsce.sh
executable file
·235 lines (207 loc) · 5.51 KB
/
sce.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
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
229
230
231
232
233
234
235
#!/bin/bash
function print_repo_nicknames {
echo
echo "each repo has nicknames:"
echo "Clark:clark, dog, clrk, ck, c"
echo "MongoDB (must have clark installed and linked):mongo, db, mongodb"
echo "Quasar:quasar, q, idsmile"
echo "SCE-discord-bot:sarah, sce-discord-bot, discord-bot, discord, bot, d"
echo "cleezy:cleezy url z"
echo "sceta:sceta, transit"
}
function print_usage {
echo "usage: sce {clone,run,link,setup} {repo name}"
echo
echo "clone: clone the given repo from github."
echo "run: run the repo using docker"
echo "link: tell the sce tool where to find the repo on your computer"
echo "create: create a user for the SCE website"
echo "setup: copy config.example.json in a repo to config.json"
print_repo_nicknames
exit 1
}
function print_missing_config {
echo
echo it seems like you forgot to create/configure the config.json file/files
echo follow the config.example.json as a template and add it at the following paths:
for str in ${missingPaths[@]}; do
echo $(readlink -f $REPO_LOCATION)/$str
done
echo
exit 1
}
function print_repo_not_found {
echo it looks like you havent linked $1 to the sce tool.
echo
echo either link the repo with sce link $1 or clone it first with sce link $1.
exit 1
}
SCE_COMMAND_DIRECTORY=$(echo $0 | rev | cut -c7- | rev)
GITHUB_BASE_HTTP_URL="https://github.com/SCE-Development/"
# sce clone <repo> --ssh
# sce clone <repo>
# [email protected]:SCE-Development/Clark.git
GITHUB_BASE_SSH_URL="[email protected]:SCE-Development/"
CLARK_REPO_NAME="Clark"
CLEEZY_REPO_NAME="cleezy"
QUASAR_REPO_NAME="Quasar"
SCE_DISCORD_BOT_REPO_NAME="SCE-discord-bot"
SCETA_REPO_NAME="SCEta"
CLARK_NAMES=("clark" "dog" "clrk" "ck" "c")
CLEEZY_NAMES=("cleezy" "url" "z")
MONGODB_NAMES=("mongo" "db" "mongodb")
QUASAR_NAMES=("quasar" "q" "idsmile")
SCE_DISCORD_BOT_NAMES=("sarah" "sce-discord-bot" "discord-bot" "discord" "bot" "s" "d")
SCETA_NAMES=("sceta" "transit")
VALID_COMMANDS=("link" "clone" "run" "setup" "completion" "create")
function contains_element {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
function contains_config {
# check file for each path in configPaths
for str in "${configPaths[@]}"; do
if [ ! -f "$str" ]; then
missingPaths+=($str)
fi
done
if [ ${#missingPaths[@]} -gt 0 ]; then
return 1
fi
return 0
}
function is_quasar_alias {
result=$(contains_element "$1" "${QUASAR_NAMES[@]}")
return $result
}
function is_clark_alias {
result=$(contains_element "$1" "${CLARK_NAMES[@]}")
return $result
}
function is_cleezy_alias {
result=$(contains_element "$1" "${CLEEZY_NAMES[@]}")
return $result
}
function is_mongodb_alias {
result=$(contains_element "$1" "${MONGODB_NAMES[@]}")
return $result
}
function is_discord_bot_alias {
result=$(contains_element "$1" "${SCE_DISCORD_BOT_NAMES[@]}")
return $result
}
function is_sceta_alias {
result=$(contains_element "$1" "${SCETA_NAMES[@]}")
return $result
}
function is_valid_command {
result=$(contains_element "$1" "${VALID_COMMANDS[@]}")
return $result
}
is_valid_command "$1"
if [ $? -eq 1 ]
then
print_usage
exit 1
fi
if [ $1 == "completion" ]
then
if [ -n "$FISH_VERSION" ]; then
# Fish shell detected
echo "function sce; bash $(pwd)/sce.sh \$argv; end"
exit 0
fi
# For other shells (Bash, Zsh, etc.)
echo "# for the sce dev tool"
echo "alias sce=\"$(pwd)/sce.sh\""
echo ""
exit 0
fi
if [ $1 == "create" ]
then
cat $SCE_COMMAND_DIRECTORY"create_user.txt" | docker exec -i sce-mongodb-dev mongosh --shell --norc --quiet
exit 0
fi
name=""
configPaths=()
missingPaths=()
is_quasar_alias "$2"
if [ $? -eq 0 ]
then
name=$QUASAR_REPO_NAME
configPaths+=("config/config.json")
fi
is_clark_alias "$2"
if [ $? -eq 0 ]
then
name=$CLARK_REPO_NAME
configPaths+=("src/config/config.json")
configPaths+=("api/config/config.json")
fi
is_cleezy_alias "$2"
if [ $? -eq 0 ]
then
name=$CLEEZY_REPO_NAME
fi
is_mongodb_alias "$2"
start_only_mongodb_container=$?
if [ $start_only_mongodb_container -eq 0 ]
then
name=$CLARK_REPO_NAME
fi
is_discord_bot_alias "$2"
if [ $? -eq 0 ]
then
name=$SCE_DISCORD_BOT_REPO_NAME
configPaths+=("config.json")
fi
is_sceta_alias "$2"
if [ $? -eq 0 ]
then
name=$SCETA_REPO_NAME
fi
if [ -z "$name" ]
then
print_usage
fi
if [ $1 == "clone" ]
then
# clone with the SSH URL if the user wanted to
# if the third argument is absent or anything else
# just default to the HTTPS url
if [[ ! -z "$3" ]] && [[ $3 == "--ssh" ]]
then
git clone "$GITHUB_BASE_SSH_URL$name.git"
else
git clone "$GITHUB_BASE_HTTP_URL$name.git"
fi
exit 0
elif [ $1 == "link" ]
then
sce_run_location=$(pwd)
# remove sim link if it exists, ignore any stderr/stdout
rm "$SCE_COMMAND_DIRECTORY$name" &> /dev/null
ln -s "$sce_run_location" "$SCE_COMMAND_DIRECTORY$name"
elif [ $1 == "run" ]
then
REPO_LOCATION="$SCE_COMMAND_DIRECTORY$name"
if [ ! -d "$REPO_LOCATION" ]
then
print_repo_not_found $name
fi
cd $REPO_LOCATION
contains_config $configPaths
if [ $? -eq 1 ]
then
print_missing_config $REPO_LOCATION $missingPaths
fi
if [ $start_only_mongodb_container -eq 0 ]
then
docker-compose -f docker-compose.dev.yml up mongodb -d
exit 0
fi
docker-compose -f docker-compose.dev.yml up --build
exit 0
fi