create_userprofile_json.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. export HUE_BIN=/opt/cloudera/parcels/CDH/share/hue/build/env/bin/hue
  18. export JSON_FILE=/tmp/authuser.json
  19. export TXT_FILE=/tmp/authuser.txt
  20. export METHOD="EXTERNAL"
  21. NEW="false"
  22. echo "["
  23. while read -r LINE
  24. do
  25. if [[ ${LINE} =~ '--' ]]
  26. then
  27. NEW="true"
  28. echo " {"
  29. echo " \"pk\": $ID,"
  30. echo " \"model\": \"useradmin.userprofile\","
  31. echo " \"fields\": {"
  32. echo " \"creation_method\": \"${METHOD}\","
  33. echo " \"user\": $ID,"
  34. echo " \"home_directory\": \"/user/$USERNAME\""
  35. echo " },"
  36. fi
  37. if [[ ${NEW} =~ "false" ]]
  38. then
  39. if [[ ${LINE} =~ "pk" ]]
  40. then
  41. ID=`echo ${LINE} | awk -F: '{print $2}' | awk -F, '{print $1}' | awk '{print $1}'`
  42. fi
  43. if [[ ${LINE} =~ "username" ]]
  44. then
  45. USERNAME=`echo ${LINE} | awk -F: '{print $2}' | awk -F, '{print $1}' | awk -F\" '{print $2}'`
  46. fi
  47. fi
  48. NEW="false"
  49. done < <(cat ${TXT_FILE})
  50. echo " {"
  51. echo " \"pk\": $ID,"
  52. echo " \"model\": \"useradmin.userprofile\","
  53. echo " \"fields\": {"
  54. echo " \"creation_method\": \"${METHOD}\","
  55. echo " \"user\": $ID,"
  56. echo " \"home_directory\": \"/user/$USERNAME\""
  57. echo " }"
  58. echo "]"