-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_user_data.sh
More file actions
executable file
·63 lines (55 loc) · 2.1 KB
/
init_user_data.sh
File metadata and controls
executable file
·63 lines (55 loc) · 2.1 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
#!/usr/bin/env bash
set -e
# Colors
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
DIM='\033[2m'
NC='\033[0m' # No Color
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_CORE_DIR="$ROOT_DIR/core"
APP_CORE_DATA_DIR="$APP_CORE_DIR/data"
APP_USER_DATA_DIR="$ROOT_DIR/user_data"
echo -e "${YELLOW}>> Setting up user_data directory...${NC}"
mkdir -p "$APP_USER_DATA_DIR"
mkdir -p "$APP_USER_DATA_DIR/policies"
mkdir -p "$APP_USER_DATA_DIR/examples"
mkdir -p "$APP_USER_DATA_DIR/db"
echo -e " ${DIM}Created directory structure${NC}"
# Copy policies only if missing
if [ -d "$APP_CORE_DATA_DIR/policies" ]; then
if [ ! -d "$APP_USER_DATA_DIR/policies" ] || [ -z "$(ls -A "$APP_USER_DATA_DIR/policies" 2>/dev/null)" ]; then
cp -r "$APP_CORE_DATA_DIR/policies/"* "$APP_USER_DATA_DIR/policies"/ || true
echo -e " ${DIM}Copied default policies${NC}"
else
echo -e " ${DIM}Policies already present, skipping${NC}"
fi
fi
# Copy examples only if missing
if [ -d "$APP_CORE_DATA_DIR/examples" ]; then
if [ ! -d "$APP_USER_DATA_DIR/examples" ] || [ -z "$(ls -A "$APP_USER_DATA_DIR/examples" 2>/dev/null)" ]; then
cp -r "$APP_CORE_DATA_DIR/examples/"* "$APP_USER_DATA_DIR/examples"/ || true
echo -e " ${DIM}Copied example files${NC}"
else
echo -e " ${DIM}Examples already present, skipping${NC}"
fi
fi
# Handle edgemining.db
# If a pre-existing database exists under core/, copy it once.
# Otherwise, create an empty file in user_data (only if it doesn't exist) so the app can initialize it.
if [ -f "$APP_CORE_DATA_DIR/db/edgemining.db" ]; then
if [ ! -f "$APP_USER_DATA_DIR/db/edgemining.db" ]; then
cp "$APP_CORE_DATA_DIR/db/edgemining.db" "$APP_USER_DATA_DIR/db/edgemining.db"
echo -e " ${DIM}Copied existing database${NC}"
else
echo -e " ${DIM}Database already present, skipping${NC}"
fi
else
if [ ! -f "$APP_USER_DATA_DIR/db/edgemining.db" ]; then
touch "$APP_USER_DATA_DIR/db/edgemining.db"
echo -e " ${DIM}Created empty database${NC}"
else
echo -e " ${DIM}Database already present, skipping${NC}"
fi
fi
echo -e "${GREEN} User data ready.${NC}"