-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclear.sh
More file actions
executable file
·96 lines (82 loc) · 3.47 KB
/
Copy pathclear.sh
File metadata and controls
executable file
·96 lines (82 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
#!/bin/bash
set -e
# Ushadow Admin Reset Script
# Removes admin users and secrets for fresh setup
echo "🧹 Ushadow Admin Reset"
echo "========================================"
# Check we're in the right directory (project root)
if [ ! -f "docker-compose.yml" ]; then
echo "❌ Error: Must be run from the project root directory"
echo " cd to the directory containing docker-compose.yml"
exit 1
fi
echo ""
echo "⚠️ WARNING: This will:"
echo " - Remove ALL admin users from the database"
echo " - Delete config/SECRETS/secrets.yaml (all API keys and credentials)"
echo " - Delete config/config.overrides.yaml (wizard state and service preferences)"
echo " - Allow you to run ./quick-start.sh for a fresh setup"
echo ""
read -p "Are you sure? (yes/no): " -r
echo ""
if [[ ! $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
echo "❌ Aborted"
exit 0
fi
# Get database name from .env
if [ -f .env ]; then
MONGODB_DATABASE=$(grep "^MONGODB_DATABASE=" .env | cut -d'=' -f2 | tr -d ' ')
fi
# Final fallback to backend's hardcoded default
if [ -z "$MONGODB_DATABASE" ]; then
MONGODB_DATABASE="ushadow"
fi
echo "📦 Database: ${MONGODB_DATABASE}"
echo ""
# Check if MongoDB is running
echo "🔍 Checking MongoDB connection..."
if ! docker ps | grep -q "mongo"; then
echo "⚠️ MongoDB container is not running"
echo " Starting MongoDB..."
docker compose -f compose/docker-compose.infra.yml up -d mongo
echo " Waiting for MongoDB to be ready..."
sleep 5
fi
# Remove admin users from MongoDB
echo "🗑️ Removing admin users from database..."
docker exec -i mongo mongosh "${MONGODB_DATABASE}" --quiet --eval '
const beforeCount = db.users.countDocuments({ is_superuser: true });
const result = db.users.deleteMany({ is_superuser: true });
const afterCount = db.users.countDocuments({ is_superuser: true });
print("✅ Removed " + result.deletedCount + " admin user(s). Remaining admins: " + afterCount);
' || echo "⚠️ MongoDB operation may have failed - check if container is running"
echo ""
echo "🗑️ Removing config/SECRETS/secrets.yaml..."
if [ -f "config/SECRETS/secrets.yaml" ]; then
rm "config/SECRETS/secrets.yaml"
echo " ✅ config/SECRETS/secrets.yaml removed"
else
echo " ℹ️ config/SECRETS/secrets.yaml not found (already clean)"
fi
echo ""
echo "🗑️ Removing wizard state (config.overrides.yaml)..."
if [ -f "config/config.overrides.yaml" ]; then
rm "config/config.overrides.yaml"
echo " ✅ config/config.overrides.yaml removed"
else
echo " ℹ️ config/config.overrides.yaml not found (already clean)"
fi
echo ""
echo "🔄 Restarting backend to invalidate active sessions..."
docker compose -f docker-compose.yml restart ushadow-backend 2>/dev/null || echo " ⚠️ Backend not running (that's ok)"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Admin reset complete!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "🚀 Next steps:"
echo " 1. Run ./dev.sh to regenerate secrets and setup"
echo " 2. Clear your browser cache (Cmd+Shift+R or hard refresh)"
echo " 3. Log in with your new admin credentials"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"