-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·102 lines (93 loc) · 3.77 KB
/
setup.sh
File metadata and controls
executable file
·102 lines (93 loc) · 3.77 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
#!/bin/bash
# Download artifacts for a specific sample application
# by calling respective app's setup.sh script
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
MODEL_URL="https://github.com/open-edge-platform/edge-ai-resources/raw/06bb0d621cb14a1791672552a538beddddcc4066/models/INT8/worker-safety-gear-detection.zip"
VIDEO_URL="https://github.com/open-edge-platform/edge-ai-resources/raw/edd25f37c324a9ef73df1642354b2ba5fa7b7df5/videos/Safety_Full_Hat_and_Vest.avi"
err() {
echo "ERROR: $1" >&2
}
unzip_compressed_file() {
local zip_file=$1
local target_dir=$2
if [ ! -f "$zip_file" ]; then
err "Zip file '$zip_file' does not exist."
return 1
fi
if [ ! -d "$target_dir" ]; then
mkdir -p "$target_dir"
fi
echo "Unzipping $zip_file to $target_dir..."
if unzip -q "$zip_file" -d "$target_dir"; then
echo "Unzipped successfully."
else
err "Failed to unzip $zip_file."
return 1
fi
}
download_artifacts() {
local app_name=$1
echo "$SCRIPT_DIR"
if [ ! -d "$SCRIPT_DIR" ]; then
err "Application directory '$SCRIPT_DIR' does not exist."
return 1
fi
# Download model artifacts if not already present
LOCAL_MODEL_DIR="$SCRIPT_DIR/../../resources/$app_name/models/$app_name"
if [ ! -d $LOCAL_MODEL_DIR ] || [ -z "$(ls -A "$LOCAL_MODEL_DIR")" ]; then
# create the models directory if it does not exist
if ! mkdir -p $LOCAL_MODEL_DIR; then
err "Failed to create models directory for $app_name."
return 1
fi
echo "Downloading model artifacts for $app_name..."
# echo "Model XML: $MODEL_XML_URL"
echo "Model URL: $MODEL_URL"
# Check if Model URL is empty
if [ -z "$MODEL_URL" ]; then
echo "❌ Error: Model URL is empty. Please provide a valid URL." >&2
exit 1
fi
# Download model XML and BIN files
if curl -L "$MODEL_URL" -o "$LOCAL_MODEL_DIR/$(basename $MODEL_URL)"; then
echo "Model zip for $app_name downloaded successfully."
# Unzip the downloaded model file
if unzip_compressed_file "$LOCAL_MODEL_DIR/$(basename $MODEL_URL)" "$LOCAL_MODEL_DIR"; then
echo "Model artifacts for $app_name unzipped successfully."
# remove the zip file after unzipping
rm -f "$LOCAL_MODEL_DIR/$(basename $MODEL_URL)"
fi
else
err "Failed to download model for $app_name."
return 1
fi
else
echo "Model artifacts for $app_name already exist."
fi
# Download video artifacts if not already present
LOCAL_VIDEO_DIR="$SCRIPT_DIR/../../resources/$app_name/videos"
if [ ! -d $LOCAL_VIDEO_DIR ]; then
# create the videos directory if it does not exist
if ! mkdir -p $LOCAL_VIDEO_DIR; then
err "Failed to create videos directory for $app_name."
return 1
fi
echo "Downloading video artifacts for $app_name..."
if ! curl -L "$VIDEO_URL" -o "$LOCAL_VIDEO_DIR/$(basename $VIDEO_URL)"; then
err "Failed to download video for $app_name."
return 1
fi
echo "Video artifacts for $app_name downloaded successfully."
else
echo "Video artifacts for $app_name already exist."
fi
return 0
}
download_artifacts "worker-safety-gear-detection"
mkdir -p $SCRIPT_DIR/configs/nginx/ssl
cd $SCRIPT_DIR/configs/nginx/ssl
if [ ! -f server.key ] || [ ! -f server.crt ]; then
echo "Generate self-signed certificate..."
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -subj "/C=US/ST=CA/L=San Francisco/O=Intel/OU=Edge AI/CN=localhost"
chown -R "$(id -u):$(id -g)" server.key server.crt 2>/dev/null || true
fi