-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_user.sh
51 lines (42 loc) · 1.2 KB
/
create_user.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
#!/bin/bash
echo "Enter details of user to be created."
# Loop until a non-blank name is provided
while true; do
read -rp "Enter user name: " name
if [ -n "$name" ]; then
break
else
echo "Error: User name cannot be blank. Please enter a valid user name."
fi
done
# Email validation loop
while true; do
read -rp "Enter user email: " email
if [[ "$email" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}$ ]]; then
break
else
echo "Error: Invalid email format. Please enter a valid email address."
fi
done
# Loop until a non-blank password is provided
while true; do
read -rp "Enter user password: " password
if [ -n "$password" ]; then
break
else
echo "Error: Password cannot be blank. Please enter a valid password."
fi
done
# Check all values are provided
if [ -z "$name" ] || [ -z "$email" ] || [ -z "$password" ]; then
echo "Error: Please provide valid inputs for all fields."
exit 1
fi
echo "create.sh pwd"
# Get the current working directory
current_dir=$(pwd)
# Move into the front directory
cd front || exit 1
yarn seed "$name" "$email" "$password"
# Return to the original directory
cd "$current_dir" || exit 1