install-users.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # -*- coding: utf-8 -*-
  3. info()
  4. {
  5. echo "--- $*"
  6. }
  7. error()
  8. {
  9. echo "=== ERROR: $*" >&2
  10. }
  11. warning()
  12. {
  13. echo "=== WARNING: $*" >&2
  14. }
  15. die()
  16. {
  17. error "$*"
  18. exit 1
  19. }
  20. sys_groupadd()
  21. {
  22. local args="--system"
  23. info "groupadd $args $*"
  24. groupadd $args "$@" || die "Failed groupadd"
  25. }
  26. sys_useradd()
  27. {
  28. local args="--system -s /usr/sbin/nologin -d /nonexistent -M -N"
  29. info "useradd $args $*"
  30. useradd $args "$@" || die "Failed useradd"
  31. }
  32. do_usermod()
  33. {
  34. info "usermod $*"
  35. usermod "$@" || die "Failed usermod"
  36. }
  37. # Stop the daemons.
  38. systemctl stop cms-fsd.socket >/dev/null 2>&1
  39. systemctl stop cms-fsd.service >/dev/null 2>&1
  40. systemctl stop cms-postd.socket >/dev/null 2>&1
  41. systemctl stop cms-postd.service >/dev/null 2>&1
  42. systemctl stop cms-backd.socket >/dev/null 2>&1
  43. systemctl stop cms-backd.service >/dev/null 2>&1
  44. # Delete all existing users, if any.
  45. userdel cms-fsd >/dev/null 2>&1
  46. userdel cms-postd >/dev/null 2>&1
  47. userdel cms-backd >/dev/null 2>&1
  48. # Delete all existing groups, if any.
  49. groupdel cms-fsd >/dev/null 2>&1
  50. groupdel cms-postd >/dev/null 2>&1
  51. groupdel cms-backd >/dev/null 2>&1
  52. groupdel cms-fs-ro >/dev/null 2>&1
  53. groupdel cms-fs-x >/dev/null 2>&1
  54. groupdel cms-sock-db >/dev/null 2>&1
  55. groupdel cms-sock-post >/dev/null 2>&1
  56. groupdel cms-sock-back >/dev/null 2>&1
  57. # Create system groups.
  58. sys_groupadd cms-fsd
  59. sys_groupadd cms-postd
  60. sys_groupadd cms-backd
  61. sys_groupadd cms-fs-ro
  62. sys_groupadd cms-fs-x
  63. sys_groupadd cms-sock-db
  64. sys_groupadd cms-sock-post
  65. sys_groupadd cms-sock-back
  66. # Create system users.
  67. sys_useradd -G cms-sock-db,cms-fs-ro -g cms-fsd cms-fsd
  68. sys_useradd -G cms-sock-post,cms-fs-x -g cms-postd cms-postd
  69. sys_useradd -G cms-sock-back,cms-sock-db,cms-sock-post -g cms-backd cms-backd
  70. # Add the communication socket to the web server process user.
  71. if grep -q '^www-data:' /etc/passwd; then
  72. do_usermod -a -G cms-sock-back www-data
  73. fi
  74. # The git-user shall be able to give group permissions in db.
  75. if grep -q '^git:' /etc/passwd; then
  76. do_usermod -a -G cms-fs-ro,cms-fs-x git
  77. fi
  78. # vim: ts=4 sw=4 expandtab