common.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. NPMUSER=npm
  12. NPMGROUP=npm
  13. NPMHOME=/tmp/npmuserhome
  14. export NPMUSER NPMGROUP NPMHOME
  15. if [[ "$PUID" -ne '0' ]] && [ "$PGID" = '0' ]; then
  16. # set group id to same as user id,
  17. # the user probably forgot to specify the group id and
  18. # it would be rediculous to intentionally use the root group
  19. # for a non-root user
  20. PGID=$PUID
  21. fi
  22. export PUID PGID
  23. log_info () {
  24. echo -e "${BLUE}❯ ${CYAN}$1${RESET}"
  25. }
  26. log_error () {
  27. echo -e "${RED}❯ $1${RESET}"
  28. }
  29. # The `run` file will only execute 1 line so this helps keep things
  30. # logically separated
  31. log_fatal () {
  32. echo -e "${RED}--------------------------------------${RESET}"
  33. echo -e "${RED}ERROR: $1${RESET}"
  34. echo -e "${RED}--------------------------------------${RESET}"
  35. /run/s6/basedir/bin/halt
  36. exit 1
  37. }
  38. # param $1: group_name
  39. get_group_id () {
  40. if [ "${1:-}" != '' ]; then
  41. getent group "$1" | cut -d: -f3
  42. fi
  43. }