Repository navigation
Expand file tree
/
Copy pathdbwebb2
More file actions
executable file
·294 lines (222 loc) · 5.57 KB
/
Copy pathdbwebb2
File metadata and controls
executable file
·294 lines (222 loc) · 5.57 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
#
# Specify the utilities used
#
ECHO="printf"
GIT="git"
RSYNC="rsync"
SSH="ssh"
SED="sed"
WGET="wget"
CURL="curl"
BASH="bash"
FIND="find"
# Revise these
UPLOAD="$RSYNC -av --delete --exclude literature --exclude .git -e \"ssh $SSH_KEY_OPTION\" \"$SOURCE\" \"$DESTINATION\""
UPLOAD_MINIMAL="$RSYNC -av --delete --exclude me --exclude tutorial --exclude example --exclude literature --exclude .git -e \"ssh $SSH_KEY_OPTION\" \"$SOURCE\" \"$DESTINATION\""
#
# Find my environment, before any work can be done
#
# For early error messages, also exists in .dbwebb.config
MSG_FAILED="\033[0;37;41mFAILED.\033[0m"
# What was the command issued?
DBW_EXECUTABLE="$( basename "$0" )"
# Where is the executable
DBW_EXECUTABLE_DIR="$( dirname "$0" )"
# Where is the installation directory
if [ -f "$DBW_EXECUTABLE_DIR/.dbwebb.version" ]; then
DBW_INSTALL_DIR="$DBW_EXECUTABLE_DIR"
elif [ -d "$DBWEBB_HOME" ]; then
DBW_INSTALL_DIR="$DBWEBB_HOME"
elif [ -d "$HOME/dbwebb-kurser/dbwebb-cli" ]; then
DBW_INSTALL_DIR="$HOME/dbwebb-kurser/dbwebb-cli"
else
$ECHO "$MSG_FAILED Could not determine the installation directory.\n"
exit 1
fi
# Get the current version installed as $DBW_VERSION
DBW_VERSION_FILE="$DBW_INSTALL_DIR/.dbwebb.version"
if [ ! -f "$DBW_VERSION_FILE" ]; then
$ECHO "$MSG_FAILED Missing file .dbwebb.version. The installation directory does not contain a valid installation.\n"
exit 1
fi
source "$DBW_VERSION_FILE"
# Include the functions needed
DBW_FUNCTIONS_FILE="$DBW_INSTALL_DIR/dbwebb2-functions"
source "$DBW_FUNCTIONS_FILE"
# What is the current directory
DBW_CURRENT_DIR="$( pwd )"
# What is the directory of the current course repo, find recursivly up the tree
DBW_COURSE_FILE_NAME=".dbwebb.course"
dir="$DBW_CURRENT_DIR/."
while [ "$dir" != "/" ]; do
dir=$( dirname "$dir" )
found="$( find "$dir" -maxdepth 1 -name $DBW_COURSE_FILE_NAME )"
if [ "$found" ]; then
DBW_COURSE_DIR="$( dirname $found )"
break
fi
done
# Get the name of the course as $DBW_COURSE
DBW_COURSE_FILE="$DBW_COURSE_DIR/$DBW_COURSE_FILE_NAME"
DBW_COURSE_REPO_VALID="no"
if [ -f "$DBW_COURSE_FILE" ]; then
DBW_COURSE_REPO_VALID="yes"
source "$DBW_COURSE_FILE"
fi
# Where is the .dbwebb.config-file
DBW_CONFIG_DEFAULT_FILE="$DBW_INSTALL_DIR/dbwebb2-config-sample"
DBW_CONFIG_FILE_NAME=".dbwebb2.config"
DBW_CONFIG_FILE="$HOME/$DBW_CONFIG_FILE_NAME"
if [ ! -f "$DBW_CONFIG_FILE" ]; then
# If the command is to init-repo, then execute that and create a config-file
if [ "$1" = "init-repo" ]; then
createConfig
exit 0
fi
else
source "$DBW_CONFIG_FILE"
fi
# Check OS
DBW_OS="$( uname -a )"
# Create the ssh-command with details from the config-file
SSH_CMD="$SSH ${DBW_USER}@${DBW_HOST} $DBW_SSH_KEY_OPTION"
# Create the basis for the upload command
RSYNC_CMD="$RSYNC -av --delete --exclude .git --exclude .gitignore -e \"ssh $DBW_SSH_KEY_OPTION\""
#
# Main, start by checking basic usage
#
if [ $# -lt 1 ]
then
dbwebb2PrintShortUsage
exit 0
elif [ "$1" == "help" ]; then
dbwebb2PrintUsage
exit 0
elif [ "$1" == "create-config" ]; then
createConfig
exit 0
fi
# Check if config file is up to date
updateConfigIfNeeded "update"
#
# Get options
#
SKIP_READLINE="no"
IGNORE_FAULTS="-i"
VERY_VERBOSE="no"
while getopts "hivwy" opt
do
case $opt in
h)
dbwebb2PrintUsage
exit 0
;;
i)
dbwebb2PrintUsageInspect
exit 0
;;
# i)
# IGNORE_FAULTS="-i"
# ;;
v)
$ECHO "$VERSION\n"
exit 0
;;
w)
VERY_VERBOSE="yes"
;;
y)
SKIP_READLINE="yes"
;;
\?)
dbwebb2Usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
#$ECHO "$MSG_FAILED Could not find file $DBW_COURSE_FILE_NAME, this is not a valid course repo.\n"
#exit 1
#$ECHO "$MSG_FAILED Missing the file $DBW_CONFIG_FILE_NAME. This does NOT appear to be a valid course repo.\nHave you initiated this as a course repo? Run the following command in the root of the course repo:\n$DBW_EXECUTABLE init-repo\n\n"
#exit 1
#
# Execute command
#
CMD=$1
case $CMD in
init-repo)
createConfig
;;
init-me)
createDefaultFiles
;;
init-server)
initServer
;;
env|environment)
environment
;;
config)
createConfig "create"
;;
test)
testConnection
;;
status)
status
;;
login)
loginToServer
;;
push)
pushToServer "$DBW_COURSE_DIR" "$DBW_REMOTE_DESTINATION" "$2"
;;
pull)
pullFromServer
;;
sshkey)
installSshKeys
;;
init)
initServer
createDefaultFiles
#uploadToServer
;;
update)
updateFromMaster
;;
upload)
setChmod
uploadToServer
;;
download)
downloadFromServer
;;
create)
LAB="$2"
if [ -z "$LAB" ]
then
echo "Missing name for lab, perhaps use lab1, lab2 or lab3?"
exit 1
fi
createLab "$LAB"
;;
validate)
WHICH=$2
validateUploadedResults ${WHICH:=all}
;;
publish)
WHICH=$2
publishResults ${WHICH:=all}
;;
inspect)
WHICH=$2
WHO=$3
inspectResults ${WHICH:=all} ${WHO:=$USER}
;;
*)
dbwebb2PrintShortUsage
exit 1
;;
esac