common.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. set -e
  3. CYAN='\E[1;36m'
  4. BLUE='\E[1;34m'
  5. YELLOW='\E[1;33m'
  6. RED='\E[1;31m'
  7. RESET='\E[0m'
  8. export CYAN BLUE YELLOW RED RESET
  9. PUID=${PUID:-0}
  10. PGID=${PGID:-0}
  11. # If changing the username and group name below,
  12. # ensure all references to this user is also changed.
  13. # See docker/rootfs/etc/logrotate.d/nginx-proxy-manager
  14. # and docker/rootfs/etc/nginx/nginx.conf
  15. NPMUSER=npm
  16. NPMGROUP=npm
  17. NPMHOME=/tmp/npmuserhome
  18. export NPMUSER NPMGROUP NPMHOME
  19. if [[ "$PUID" -ne '0' ]] && [ "$PGID" = '0' ]; then
  20. # set group id to same as user id,
  21. # the user probably forgot to specify the group id and
  22. # it would be rediculous to intentionally use the root group
  23. # for a non-root user
  24. PGID=$PUID
  25. fi
  26. export PUID PGID
  27. log_info () {
  28. echo -e "${BLUE}❯ ${CYAN}$1${RESET}"
  29. }
  30. log_error () {
  31. echo -e "${RED}❯ $1${RESET}"
  32. }
  33. # The `run` file will only execute 1 line so this helps keep things
  34. # logically separated
  35. log_fatal () {
  36. echo -e "${RED}--------------------------------------${RESET}"
  37. echo -e "${RED}ERROR: $1${RESET}"
  38. echo -e "${RED}--------------------------------------${RESET}"
  39. /run/s6/basedir/bin/halt
  40. exit 1
  41. }
  42. # param $1: group_name
  43. get_group_id () {
  44. if [ "${1:-}" != '' ]; then
  45. getent group "$1" | cut -d: -f3
  46. fi
  47. }
  48. # param $1: value
  49. is_true () {
  50. VAL=$(echo "${1:-}" | tr '[:upper:]' '[:lower:]')
  51. if [ "$VAL" == 'true' ] || [ "$VAL" == 'on' ] || [ "$VAL" == '1' ] || [ "$VAL" == 'yes' ]; then
  52. echo '1'
  53. else
  54. echo '0'
  55. fi
  56. }