Skip to content

Commit 8843ab3

Browse files
committed
Add script to run d2d
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 3ab67d9 commit 8843ab3

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

etc/scripts/d2d/run_d2d.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
set -e
3+
4+
FROM_PATH="$1"
5+
TO_PATH="$2"
6+
D2D_OPTIONS="$3"
7+
OUTPUT_FILE="$4"
8+
SPIN_DB="$5"
9+
DB_PORT="$6"
10+
11+
if [ -z "$FROM_PATH" ] || [ -z "$TO_PATH" ] || [ -z "$OUTPUT_FILE" ]; then
12+
echo "Missing required arguments!"
13+
echo "Usage: $0 <from-path> <to-path> [options] <output-file> <spin-db(true|false)> [db-port]"
14+
exit 1
15+
fi
16+
17+
if [ -z "$DB_PORT" ]; then
18+
DB_PORT=5432
19+
fi
20+
21+
echo "Arguments:"
22+
echo "FROM_PATH: $FROM_PATH"
23+
echo "TO_PATH: $TO_PATH"
24+
echo "D2D_OPTIONS: $D2D_OPTIONS"
25+
echo "OUTPUT_FILE: $OUTPUT_FILE"
26+
echo "SPIN_DB: $SPIN_DB"
27+
echo "DB_PORT: $DB_PORT"
28+
29+
DB_STARTED=false
30+
31+
if [ "$SPIN_DB" = "true" ]; then
32+
echo "Starting Postgres container on port $DB_PORT..."
33+
34+
docker run -d \
35+
--name scancodeio-run-db \
36+
-e POSTGRES_DB=scancodeio \
37+
-e POSTGRES_USER=scancodeio \
38+
-e POSTGRES_PASSWORD=scancodeio \
39+
-e POSTGRES_INITDB_ARGS="--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8" \
40+
-v scancodeio_pgdata:/var/lib/postgresql/data \
41+
-p "${DB_PORT}:5432" \
42+
postgres:17 || {
43+
echo "Failed to start DB container. Cleaning up…"
44+
docker rm -f scancodeio-run-db >/dev/null 2>&1 || true
45+
exit 1
46+
}
47+
48+
DB_STARTED=true
49+
echo "DB container started"
50+
fi
51+
52+
WORKDIR="d2d"
53+
mkdir -p "$WORKDIR"
54+
55+
cp "$FROM_PATH" "$WORKDIR/"
56+
cp "$TO_PATH" "$WORKDIR/"
57+
58+
FROM_FILENAME=$(basename "$FROM_PATH")
59+
TO_FILENAME=$(basename "$TO_PATH")
60+
61+
echo "Running ScanCode.io mapping..."
62+
63+
if [ -z "$D2D_OPTIONS" ]; then
64+
docker run --rm \
65+
-v "$(pwd)/$WORKDIR":/code \
66+
--network host \
67+
-e SCANCODEIO_NO_AUTO_DB=1 \
68+
ghcr.io/aboutcode-org/scancode.io:latest \
69+
run map_deploy_to_develop \
70+
"/code/${FROM_FILENAME}:from,/code/${TO_FILENAME}:to" \
71+
> "$OUTPUT_FILE"
72+
else
73+
docker run --rm \
74+
-v "$(pwd)/$WORKDIR":/code \
75+
--network host \
76+
-e SCANCODEIO_NO_AUTO_DB=1 \
77+
ghcr.io/aboutcode-org/scancode.io:latest \
78+
run map_deploy_to_develop:"$D2D_OPTIONS" \
79+
"/code/${FROM_FILENAME}:from,/code/${TO_FILENAME}:to" \
80+
> "$OUTPUT_FILE"
81+
fi
82+
83+
echo "Output saved to $OUTPUT_FILE"
84+
85+
86+
rm -rf "$WORKDIR"
87+
echo "Temporary directory cleaned up"
88+
89+
if [ "$DB_STARTED" = true ]; then
90+
echo "Stopping DB container..."
91+
docker rm -f scancodeio-run-db >/dev/null 2>&1 || true
92+
echo "DB container removed"
93+
fi
94+
95+
echo "Done!"

0 commit comments

Comments
 (0)