-
Notifications
You must be signed in to change notification settings - Fork 75
/
task
executable file
·66 lines (56 loc) · 1.9 KB
/
task
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
#!/bin/bash -e
check_collect_opsfiles_params() {
if [ ! -d ${ROOT_DIR}/base-ops-files/${BASE_OPS_FILE_DIR} ]; then
echo "[ERROR] base-ops-files/${BASE_OPS_FILE_DIR} must exist in order to collect operations files."
exit 1
fi
if [ ! -z "${NEW_OPS_FILES}" ]; then
for OPERATION in ${NEW_OPS_FILES}; do
if [ ! -e "${ROOT_DIR}/new-ops-files/${OPERATION}" ]; then
echo "[ERROR] All files specified in NEW_OPS_FILES must exist. [ new-ops-files/${OPERATION} ] does not."
exit 1
fi
done
fi
}
# Create collection directory (task output)
create_collection_directory() {
mkdir -p ${ROOT_DIR}/collected-ops-files/${BASE_OPS_FILE_DIR}
}
set_collection_path() {
if [ -z "${BASE_OPS_FILE_DIR}" ]; then
COLLECTION_PATH="${ROOT_DIR}/collected-ops-files"
else
COLLECTION_PATH="${ROOT_DIR}/collected-ops-files/${BASE_OPS_FILE_DIR}"
fi
}
# Copy all base operations to collection
collect_base_operations() {
cp -r ${ROOT_DIR}/base-ops-files/${BASE_OPS_FILE_DIR}/ ${ROOT_DIR}/collected-ops-files
}
# Copy each new operation to collection
collect_new_operations() {
if [ -z "${NEW_OPS_FILES}" ]; then
# If we don't have a list of specific ops files to collect, then collect
# all of the files at the root
find ${ROOT_DIR}/new-ops-files -type f -maxdepth 1 | xargs -n1 -I{} cp {} ${COLLECTION_PATH}
else
# ... otherwise, add them one by one
for OPERATION in ${NEW_OPS_FILES}; do
# Get only the filename part of the specified ops file since we're putting all of them in
# the same "collected" directory
local target_filename
target_filename=$(basename "${OPERATION}")
cp ${ROOT_DIR}/new-ops-files/${OPERATION} ${COLLECTION_PATH}/${target_filename}
done
fi
}
main() {
ROOT_DIR="${1}"
check_collect_opsfiles_params
create_collection_directory
set_collection_path
collect_base_operations
collect_new_operations
}
main ${PWD}