0001-scripts-FEATURE-support-using-current-user-for-SR-mo.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From 4a950257fa353e27ef1bd753bca4d0279f41bc77 Mon Sep 17 00:00:00 2001
  2. From: Michal Vasko <mvasko@cesnet.cz>
  3. Date: Mon, 24 Aug 2020 13:47:40 +0200
  4. Subject: [PATCH] scripts FEATURE support using current user for SR modules
  5. Mostly for special cases user/group configuration
  6. when the user/group cannot be retrieved normally.
  7. Fixes #701
  8. ---
  9. CMakeLists.txt | 10 +++++-----
  10. scripts/setup.sh | 23 +++++++++++++++++++----
  11. 2 files changed, 24 insertions(+), 9 deletions(-)
  12. diff --git a/CMakeLists.txt b/CMakeLists.txt
  13. index 77aea1f..8fd6b43 100755
  14. --- a/CMakeLists.txt
  15. +++ b/CMakeLists.txt
  16. @@ -68,19 +68,19 @@ if(NOT MODULES_OWNER)
  17. OUTPUT_VARIABLE MODULES_OWNER OUTPUT_STRIP_TRAILING_WHITESPACE
  18. ERROR_VARIABLE ERROR_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
  19. if(RET)
  20. - message(FATAL_ERROR "Learning server module user failed: ${ERROR_STR}")
  21. + message(WARNING "Learning server module user failed (${ERROR_STR}), the current user will be used.")
  22. endif()
  23. endif()
  24. -set(MODULES_OWNER "${MODULES_OWNER}" CACHE STRING "System user that will become the owner of server modules")
  25. -if(NOT MODULES_GROUP)
  26. +set(MODULES_OWNER "${MODULES_OWNER}" CACHE STRING "System user that will become the owner of server modules, empty means the current user")
  27. +if(NOT MODULES_GROUP AND MODULES_OWNER)
  28. execute_process(COMMAND id -gn ${MODULES_OWNER} RESULT_VARIABLE RET
  29. OUTPUT_VARIABLE MODULES_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE
  30. ERROR_VARIABLE ERROR_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
  31. if(RET)
  32. - message(FATAL_ERROR "Learning server module group failed: ${ERROR_STR}")
  33. + message(WARNING "Learning server module group failed (${ERROR_STR}), the current user group will be used.")
  34. endif()
  35. endif()
  36. -set(MODULES_GROUP "${MODULES_GROUP}" CACHE STRING "System group that the server modules will belong to")
  37. +set(MODULES_GROUP "${MODULES_GROUP}" CACHE STRING "System group that the server modules will belong to, empty means the current user group")
  38. # set prefix for the PID file
  39. if(NOT PIDFILE_PREFIX)
  40. diff --git a/scripts/setup.sh b/scripts/setup.sh
  41. index 9591a49..b7c7ba4 100755
  42. --- a/scripts/setup.sh
  43. +++ b/scripts/setup.sh
  44. @@ -1,7 +1,8 @@
  45. #!/bin/bash
  46. -# env variables NP2_MODULE_DIR, NP2_MODULE_PERMS, NP2_MODULE_OWNER, NP2_MODULE_GROUP must be defined when executing this script!
  47. -if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" -o -z "$NP2_MODULE_OWNER" -o -z "$NP2_MODULE_GROUP" ]; then
  48. +# env variables NP2_MODULE_DIR, NP2_MODULE_PERMS must be defined and NP2_MODULE_OWNER, NP2_MODULE_GROUP will be used if
  49. +# defined when executing this script!
  50. +if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" ]; then
  51. echo "Required environment variables not defined!"
  52. exit 1
  53. fi
  54. @@ -37,7 +38,14 @@ MODULES=(
  55. # functions
  56. INSTALL_MODULE() {
  57. - "$SYSREPOCTL" -a -i $MODDIR/$1 -s "$MODDIR" -p "$PERMS" -o "$OWNER" -g "$GROUP" -v2
  58. + CMD="'$SYSREPOCTL' -a -i $MODDIR/$1 -s '$MODDIR' -p '$PERMS' -v2"
  59. + if [ ! -z ${OWNER} ]; then
  60. + CMD="$CMD -o '$OWNER'"
  61. + fi
  62. + if [ ! -z ${GROUP} ]; then
  63. + CMD="$CMD -g '$GROUP'"
  64. + fi
  65. + eval $CMD
  66. local rc=$?
  67. if [ $rc -ne 0 ]; then
  68. exit $rc
  69. @@ -45,7 +53,14 @@ INSTALL_MODULE() {
  70. }
  71. UPDATE_MODULE() {
  72. - "$SYSREPOCTL" -a -U $MODDIR/$1 -s "$MODDIR" -p "$PERMS" -o "$OWNER" -g "$GROUP" -v2
  73. + CMD="'$SYSREPOCTL' -a -U $MODDIR/$1 -s '$MODDIR' -p '$PERMS' -v2"
  74. + if [ ! -z ${OWNER} ]; then
  75. + CMD="$CMD -o '$OWNER'"
  76. + fi
  77. + if [ ! -z ${GROUP} ]; then
  78. + CMD="$CMD -g '$GROUP'"
  79. + fi
  80. + eval $CMD
  81. local rc=$?
  82. if [ $rc -ne 0 ]; then
  83. exit $rc
  84. --
  85. 2.20.1