-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_bagit_export_script.sh
executable file
·103 lines (89 loc) · 2.38 KB
/
run_bagit_export_script.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
#!/bin/bash
set -e
# Initialize variables
BUILD=""
UPLOAD_FILEPATH=""
CONF_FILE=""
HELP=""
ACTION=""
exit_code=0
# Function to display help
display_help() {
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -b, --build_number BUILD_NUMBER Specify the build number"
echo " -f, --upload-file UPLOAD_FILEPATH Specify the upload file path"
echo " -c, --config-file CONF_FILE Specify the config file path (optional)"
echo " -a, --action ACTION Specify the action"
echo " -h, --help Display this help message"
exit 1
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-b|--build_number)
BUILD="$2"
shift 2
;;
-f|--upload-file)
UPLOAD_FILEPATH="$2"
shift 2
;;
-c|--config-file)
CONF_FILE="$2"
shift 2
;;
-a|--action)
ACTION="$2"
shift 2
;;
-h|--help)
HELP="true"
shift
;;
*)
echo "Error: Invalid option: $1"
display_help
;;
esac
done
# Display help if requested
if [ -n "$HELP" ]; then
display_help
fi
# Check if required parameters are provided
if [ -z "$BUILD" ] || [ -z "$UPLOAD_FILEPATH" ] || [ -z "$ACTION" ]; then
echo "Error: BUILD, UPLOAD_FILEPATH, and ACTION parameters are required"
display_help
fi
if [ -n "$CONF_FILE" ]; then
CONFIG_OPTION="--config_path $CONF_FILE"
else
CONFIG_OPTION=""
fi
# Get the absolute path of the script
SCRIPT=$(readlink -f "$0")
# Get the directory where the script is located
APP_FOLDER=$(dirname "$SCRIPT")
VENV_PATH="venv"
echo -e "\n"
echo " ** Starting bagit export script with following parameters **"
echo "Build Number : $BUILD"
echo "App Path : $APP_FOLDER"
echo "Upload file path : $UPLOAD_FILEPATH"
echo "Action : $ACTION"
echo -e "\n\n"
cd "$APP_FOLDER" || exit 1
echo "Creating/Updating python virtual environment"
/bin/python3 -m venv "$VENV_PATH" || exit 1
./"$VENV_PATH"/bin/pip3 install -r requirements.txt || exit 1
if [ $? = 1 ]; then
exit 1
fi
echo -e "\n\n"
./"$VENV_PATH"/bin/python3 -u "$APP_FOLDER"/main.py $CONFIG_OPTION -b "$BUILD" -a "$ACTION" "$UPLOAD_FILEPATH" || exit 1
if [ $? -ne 0 ]; then
exit_code=1
fi
echo -e "\n\n"
echo "<<<< RUN COMPLETED! >>>>"