-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraphjs_docker.sh
More file actions
executable file
·84 lines (74 loc) · 2.43 KB
/
graphjs_docker.sh
File metadata and controls
executable file
·84 lines (74 loc) · 2.43 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
#!/bin/bash
# Get current and parent dir
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PARENT_DIR=$(dirname "${SCRIPT_DIR}")
# Display help
Help()
{
echo "Usage: ./graphjs_docker.sh -i <path> [options]"
echo "Description: Run Graph.js for a given input path <path> in a Docker container."
echo ""
echo "Required:"
echo "-i <path> Input path (filename to run specific file or directory to run package level)."
echo ""
echo "Options:"
echo "-o <path> Path to store analysis results."
echo "-e Create exploit template."
echo "-s Silent mode: Does not save graph .svg."
echo "-h Print this help."
echo
}
# Default values
SILENT_MODE=false
EXTENDED_SUMMARY=false
FLAGS=""
while getopts i:o:esh flag; do
case "${flag}" in
i) input_path=$OPTARG
input_path="$( realpath "$input_path" )"
if [ ! -f "$input_path" ] && [ ! -d "$input_path" ]; then
echo "File $OPTARG does not exist."
exit 1
fi;;
o) output_path=$OPTARG
output_path="$( realpath "$output_path" )"
if [ ! -d "$output_path" ]; then
echo "Output path $OPTARG does not exist. Creating new directory."
mkdir -p $output_path
fi;;
e) FLAGS+=" -e";;
s) FLAGS+=" -s";;
:?h) Help
exit;;
esac
done
# Check if the required input path is provided
if [ ! -f "$input_path" ] && [ ! -d "$input_path" ]; then
echo "Option -i is required."
Help
exit 1
fi
# If output_path is not provided, use default
if [ ! -d "$output_path" ]; then
# Generate output file
# If path is a directory, go up one level only
if [ -d "$input_path" ]; then
file_parent_dir=$(dirname "$input_path")
else
file_parent_dir=$(dirname "$(dirname "$input_path")")
fi
output_path="$file_parent_dir/tool_outputs/graphjs"
mkdir -p ${output_path}
fi
input_dir=$(dirname "$input_path")
fname=$(basename "$input_path")
# Build docker image if it does not exist
if [ -z "$(docker images -q graphjs)" ]; then
docker build . -t graphjs
fi
docker run -it \
-v "${input_dir}":/input \
-v "${output_path}":/output_path \
graphjs \
/bin/bash -c "sudo chown graphjs:graphjs -R /output_path; python3 graphjs -f /input/$fname -o /output_path ${FLAGS}; chmod 777 -R /output_path;"
#docker system prune -f