create-user 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env bash
  2. # Function to create admin user
  3. create_admin_user() {
  4. USERNAME="admin"
  5. EMAIL="admin@example.com"
  6. FIRSTNAME="Admin"
  7. LASTNAME="Admin"
  8. PASSWORD="Admin123"
  9. bin/magento admin:user:create \
  10. --admin-user="${USERNAME}" \
  11. --admin-password="${PASSWORD}" \
  12. --admin-email="${EMAIL}" \
  13. --admin-firstname="${FIRSTNAME}" \
  14. --admin-lastname="${LASTNAME}"
  15. if [ $? -eq 0 ]; then
  16. echo "Admin account created successfully."
  17. echo "Username: ${USERNAME}"
  18. echo "Email: ${EMAIL}"
  19. echo "Firstname: ${FIRSTNAME}"
  20. echo "Lastname: ${LASTNAME}"
  21. echo "Password: ${PASSWORD}"
  22. else
  23. echo "Error creating admin user."
  24. fi
  25. }
  26. # Function to create customer account
  27. create_customer_account() {
  28. EMAIL="${EMAIL:-customer@example.com}"
  29. PASSWORD="${PASSWORD:-customer123QWERTY}"
  30. FIRSTNAME="${FIRSTNAME:-Customer}"
  31. LASTNAME="${LASTNAME:-Customer}"
  32. WEBSITE="${WEBSITE:-1}"
  33. bin/n98-magerun2 customer:create "${EMAIL}" "${PASSWORD}" "${FIRSTNAME}" "${LASTNAME}" "${WEBSITE}"
  34. if [ $? -eq 0 ]; then
  35. echo "Customer account created successfully."
  36. echo "Email: ${EMAIL}"
  37. echo "Firstname: ${FIRSTNAME}"
  38. echo "Lastname: ${LASTNAME}"
  39. echo "Password: ${PASSWORD}"
  40. else
  41. echo "Error creating customer account."
  42. fi
  43. }
  44. # Check if n98-magerun2.phar exists, if not download and install
  45. if ! bin/cliq ls bin/n98-magerun2; then
  46. echo "Checking if n98-magerun2.phar exists, just a moment..."
  47. bin/clinotty curl -sS -O https://files.magerun.net/n98-magerun2.phar
  48. bin/clinotty curl -sS -o n98-magerun2.phar.sha256 https://files.magerun.net/sha256.php?file=n98-magerun2.phar
  49. bin/clinotty shasum -a 256 -c n98-magerun2.phar.sha256
  50. [ $? != 0 ] && echo "sha256 checksum do not match!" && exit
  51. bin/cliq chmod +x n98-magerun2.phar
  52. bin/cliq mkdir -p bin
  53. bin/cliq mv n98-magerun2.phar bin
  54. fi
  55. # Prompt user for type of account to create
  56. read -r -p "Do you want to create an admin (A) or a customer (C) account? [A/C]: " account_type
  57. if [[ "$account_type" == "A" || "$account_type" == "a" ]]; then
  58. create_admin_user
  59. elif [[ "$account_type" == "C" || "$account_type" == "c" ]]; then
  60. read -r -p "Do you want to use default values for customer account? (Y/N): " use_defaults
  61. if [[ "$use_defaults" == "Y" || "$use_defaults" == "y" ]]; then
  62. create_customer_account
  63. elif [[ "$use_defaults" == "N" || "$use_defaults" == "n" ]]; then
  64. read -r -p "Enter customer email: " EMAIL
  65. read -r -p "Enter customer password: " PASSWORD
  66. read -r -p "Enter customer firstname: " FIRSTNAME
  67. read -r -p "Enter customer lastname: " LASTNAME
  68. read -r -p "Enter customer website: " WEBSITE
  69. create_customer_account
  70. else
  71. echo "Invalid option. Please choose either Y or N."
  72. fi
  73. else
  74. echo "Invalid option. Please choose either A or C."
  75. fi