0003-scripts-FEATURE-support-using-current-user-for-SR-mo.patch 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From 36ee1f33bceb0c2a7899e28d75c0d05408b561f1 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. Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
  9. [patch taken from upstream:
  10. https://github.com/CESNET/netopeer2/commit/12a82701e10651fbdedb1524b27edf3bb2377488]
  11. Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
  12. ---
  13. CMakeLists.txt | 10 +++++-----
  14. scripts/setup.sh | 23 +++++++++++++++++++----
  15. 2 files changed, 24 insertions(+), 9 deletions(-)
  16. diff --git a/CMakeLists.txt b/CMakeLists.txt
  17. index 2d4175e..95e7e61 100755
  18. --- a/CMakeLists.txt
  19. +++ b/CMakeLists.txt
  20. @@ -68,19 +68,19 @@ if(NOT MODULES_OWNER)
  21. OUTPUT_VARIABLE MODULES_OWNER OUTPUT_STRIP_TRAILING_WHITESPACE
  22. ERROR_VARIABLE ERROR_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
  23. if(RET)
  24. - message(FATAL_ERROR "Learning server module user failed: ${ERROR_STR}")
  25. + message(WARNING "Learning server module user failed (${ERROR_STR}), the current user will be used.")
  26. endif()
  27. endif()
  28. -set(MODULES_OWNER "${MODULES_OWNER}" CACHE STRING "System user that will become the owner of server modules")
  29. -if(NOT MODULES_GROUP)
  30. +set(MODULES_OWNER "${MODULES_OWNER}" CACHE STRING "System user that will become the owner of server modules, empty means the current user")
  31. +if(NOT MODULES_GROUP AND MODULES_OWNER)
  32. execute_process(COMMAND id -gn ${MODULES_OWNER} RESULT_VARIABLE RET
  33. OUTPUT_VARIABLE MODULES_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE
  34. ERROR_VARIABLE ERROR_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
  35. if(RET)
  36. - message(FATAL_ERROR "Learning server module group failed: ${ERROR_STR}")
  37. + message(WARNING "Learning server module group failed (${ERROR_STR}), the current user group will be used.")
  38. endif()
  39. endif()
  40. -set(MODULES_GROUP "${MODULES_GROUP}" CACHE STRING "System group that the server modules will belong to")
  41. +set(MODULES_GROUP "${MODULES_GROUP}" CACHE STRING "System group that the server modules will belong to, empty means the current user group")
  42. # set prefix for the PID file
  43. if(NOT PIDFILE_PREFIX)
  44. diff --git a/scripts/setup.sh b/scripts/setup.sh
  45. index 7175bc4..b5d1406 100755
  46. --- a/scripts/setup.sh
  47. +++ b/scripts/setup.sh
  48. @@ -1,7 +1,8 @@
  49. #!/bin/bash
  50. -# env variables NP2_MODULE_DIR, NP2_MODULE_PERMS, NP2_MODULE_OWNER, NP2_MODULE_GROUP must be defined when executing this script!
  51. -if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" -o -z "$NP2_MODULE_OWNER" -o -z "$NP2_MODULE_GROUP" ]; then
  52. +# env variables NP2_MODULE_DIR, NP2_MODULE_PERMS must be defined and NP2_MODULE_OWNER, NP2_MODULE_GROUP will be used if
  53. +# defined when executing this script!
  54. +if [ -z "$NP2_MODULE_DIR" -o -z "$NP2_MODULE_PERMS" ]; then
  55. echo "Required environment variables not defined!"
  56. exit 1
  57. fi
  58. @@ -33,7 +34,14 @@ MODULES=(
  59. # functions
  60. INSTALL_MODULE() {
  61. - $SYSREPOCTL -a -i $MODDIR/$1 -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2
  62. + CMD="'$SYSREPOCTL' -a -i $MODDIR/$1 -s '$MODDIR' -p '$PERMS' -v2"
  63. + if [ ! -z ${OWNER} ]; then
  64. + CMD="$CMD -o '$OWNER'"
  65. + fi
  66. + if [ ! -z ${GROUP} ]; then
  67. + CMD="$CMD -g '$GROUP'"
  68. + fi
  69. + eval $CMD
  70. local rc=$?
  71. if [ $rc -ne 0 ]; then
  72. exit $rc
  73. @@ -41,7 +49,14 @@ INSTALL_MODULE() {
  74. }
  75. UPDATE_MODULE() {
  76. - $SYSREPOCTL -a -U $MODDIR/$1 -s $MODDIR -p $PERMS -o $OWNER -g $GROUP -v2
  77. + CMD="'$SYSREPOCTL' -a -U $MODDIR/$1 -s '$MODDIR' -p '$PERMS' -v2"
  78. + if [ ! -z ${OWNER} ]; then
  79. + CMD="$CMD -o '$OWNER'"
  80. + fi
  81. + if [ ! -z ${GROUP} ]; then
  82. + CMD="$CMD -g '$GROUP'"
  83. + fi
  84. + eval $CMD
  85. local rc=$?
  86. if [ $rc -ne 0 ]; then
  87. exit $rc
  88. --
  89. 2.20.1