-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_client.sh
88 lines (77 loc) · 1.94 KB
/
create_client.sh
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
#!/bin/bash
# Script to create a client user in the P0cit application
# Show usage if --help flag is passed
if [[ "$1" == "--help" ]]; then
echo "Usage: $0 [--interactive]"
echo " --interactive: Run in interactive mode (ask for credentials)"
echo " --username NAME: Specify username"
echo " --password PASS: Specify password"
echo " --email EMAIL: Specify email (optional)"
exit 0
fi
# Docker container name
CONTAINER_NAME="p0cit-app"
# Check if Docker container is running
if ! docker ps | grep -q $CONTAINER_NAME; then
echo "Error: Docker container '$CONTAINER_NAME' is not running."
echo "Please start the application first with 'docker-compose up -d'"
exit 1
fi
# Default to non-interactive mode
INTERACTIVE=false
USERNAME=""
PASSWORD=""
EMAIL=""
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--interactive)
INTERACTIVE=true
shift
;;
--username)
USERNAME="$2"
shift 2
;;
--password)
PASSWORD="$2"
shift 2
;;
--email)
EMAIL="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Command to execute
CMD="python -m app.create_client"
# Add arguments based on mode
if [ "$INTERACTIVE" = true ]; then
CMD="$CMD --interactive"
else
# Check if username and password are provided
if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
echo "Error: Username and password are required in non-interactive mode"
echo "Use --username NAME --password PASS or use --interactive"
exit 1
fi
CMD="$CMD --username $USERNAME --password $PASSWORD"
# Add email if provided
if [ -n "$EMAIL" ]; then
CMD="$CMD --email $EMAIL"
fi
fi
echo "Creating client user..."
docker exec -it $CONTAINER_NAME $CMD
# Check exit status
if [ $? -eq 0 ]; then
echo "Client user creation completed."
else
echo "Error: Client user creation failed."
exit 1
fi