forked from migrate-ease/migrate-ease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_to_CSP.sh
More file actions
executable file
·120 lines (109 loc) · 3.47 KB
/
Copy pathmigrate_to_CSP.sh
File metadata and controls
executable file
·120 lines (109 loc) · 3.47 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
#!/usr/bin/env bash
show_help() {
echo "Usage: migrate_to_CSP.sh [OPTIONS] [SCAN_PATH]"
echo "Migrate to ARM cloud instances with specified architecture."
echo
echo "Options:"
echo " -v, --vendor VENDOR Specify the cloud vendor (e.g., aliCloud, GCP)."
echo " -i, --instance TYPE Specify the instance type (e.g., g8y, c8y, r8y, g6r, c6r, C4A, N4A)."
echo " -h, --help Show help message."
echo
echo "SCAN_PATH is the path to the code directory that needs to be scanned."
}
migrate_to_aliCloud() {
local instance="$1"
local scan_path="$2"
declare -A instance_arch_map=(
["g8y"]="armv8.6-a+sve2"
["g6r"]="armv8-a"
["c8y"]="armv8.6-a+sve2"
["c6r"]="armv8-a"
["r8y"]="armv8.6-a+sve2"
)
local valid_instances=("${!instance_arch_map[@]}")
local arch="${instance_arch_map[$instance]}"
if [[ -z "$arch" ]]; then
echo "Error: No architecture mapping found for instance '$instance'."
echo "Supported instances are: ${valid_instances[*]}."
return 1
fi
local valid_scanners=("cpp" "docker" "go" "js" "java" "python" "rust")
echo "Run all scanners for instance '$instance' with architecture '$arch'."
for s in "${valid_scanners[@]}"; do
echo "Executing: python3 -m $s --march $arch --output migrate_to_${instance}_$s.json $scan_path"
python3 -m "$s" --march "$arch" --output migrate_to_"$instance"_"$s".json "$scan_path"
done
}
migrate_to_GCP() {
local instance="$1"
local scan_path="$2"
declare -A instance_arch_map=(
["C4A"]="armv9-a"
["N4A"]="armv9.2-a"
)
local valid_instances=("${!instance_arch_map[@]}")
local arch="${instance_arch_map[$instance]}"
if [[ -z "$arch" ]]; then
echo "Error: No architecture mapping found for instance '$instance'."
echo "Supported instances are: ${valid_instances[*]}."
return 1
fi
local valid_scanners=("cpp" "docker" "go" "js" "java" "python" "rust")
echo "Run all scanners for instance '$instance' with architecture '$arch'."
for s in "${valid_scanners[@]}"; do
echo "Executing: python3 -m $s --march $arch --output migrate_to_${instance}_$s.json $scan_path"
python3 -m "$s" --march "$arch" --output migrate_to_"$instance"_"$s".json "$scan_path"
done
}
vendor=""
instance=""
scan_path=""
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--vendor)
vendor="$2"
shift 2
;;
-i|--instance)
instance="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
-*)
echo "Unknown option: $1"
exit 1
;;
*)
if [[ -z "$scan_path" ]]; then
scan_path="$1"
else
echo "Unexpected argument: $1"
exit 1
fi
shift
;;
esac
done
if [[ -z "$instance" ]]; then
echo "Error: Missing required option -i|-instance (instance type)."
exit 1
fi
if [[ ! -d "$scan_path" ]]; then
echo "Error: Scan path '$scan_path' does not exist or is not a directory."
exit 1
fi
case "${vendor,,}" in
"alicloud")
migrate_to_aliCloud "$instance" "$scan_path"
;;
"gcp")
migrate_to_GCP "$instance" "$scan_path"
;;
*)
echo "Error: Unsupported vendor '$vendor'. Only 'aliCloud' and 'GCP' are supported."
exit 1
;;
esac