-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_admin.sh
More file actions
48 lines (39 loc) · 932 Bytes
/
create_admin.sh
File metadata and controls
48 lines (39 loc) · 932 Bytes
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
#!/bin/bash
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: ./create_admin.sh <email> <password>"
exit 1
fi
ADMIN_EMAIL=$1
ADMIN_PASSWORD=$2
echo "Generating bcrypt hash for password..."
# Generate bcrypt hash using Go
HASHED_PASSWORD=$(python create_hash.py "$ADMIN_PASSWORD")
echo "Hashed password: $HASHED_PASSWORD"
# Load environment variables
if [ -f .env ]; then
export $(cat .env | grep -v '#' | awk '/=/ {print $1}')
fi
POSTGRES_USER=${POSTGRES_USER:-postgres}
POSTGRES_DB=${POSTGRES_DB:-filevault}
# Insert into database
docker-compose exec postgres psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "
INSERT INTO users (
id,
email,
password,
role,
plan,
created_at,
updated_at
) VALUES (
gen_random_uuid(),
'${ADMIN_EMAIL}',
'${HASHED_PASSWORD}',
'admin',
'premium',
now(),
now()
);
"
echo "Admin user '${ADMIN_EMAIL}' created successfully!"