admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
642 B

  1. #!/bin/bash
  2. SCRIPTNAME="postgres_add"
  3. USERNAME="micro"
  4. function usage () {
  5. echo "Usage: $SCRIPTNAME [ -u | --username ] user"
  6. echo "eg. $SCRIPTNAME -u $USERNAME"
  7. echo " $SCRIPTNAME --username $USERNAME"
  8. echo ""
  9. }
  10. if [[ $# -eq 0 ]]; then
  11. echo "Enter the user to create the db for"
  12. read -r USER
  13. fi
  14. while [[ $# -gt 1 ]]; do
  15. key="$1"
  16. case $key in
  17. -u|--username)
  18. USER="$2"
  19. shift
  20. ;;
  21. -h|--help)
  22. usage
  23. ;;
  24. *)
  25. echo Unrecognised flag
  26. usage
  27. ;;
  28. esac
  29. shift
  30. done
  31. su postgres -c "createuser --no-superuser --no-createdb --no-createrole $USER; createdb $USER -O $USER"