update_settings.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. DEFAULT_TRUE="'default': true"
  2. DEFAULT_FALSE="'default': false"
  3. DEFAULT_ON="'default': TelemetryConfiguration.ON"
  4. DEFAULT_OFF="'default': TelemetryConfiguration.OFF"
  5. TELEMETRY_CRASH_REPORTER="'telemetry.enableCrashReporter':"
  6. TELEMETRY_CONFIGURATION=" TelemetryConfiguration.ON"
  7. # include common functions
  8. . ../utils.sh
  9. update_setting () {
  10. local FILENAME="${2}"
  11. # check that the file exists
  12. if [ ! -f "${FILENAME}" ]; then
  13. echo "File to update setting in does not exist ${FILENAME}"
  14. return
  15. fi
  16. # go through lines of file, looking for block that contains setting
  17. local SETTING="${1}"
  18. local LINE_NUM=0
  19. while read -r line; do
  20. local LINE_NUM=$(( $LINE_NUM + 1 ))
  21. if [[ "${line}" == *"${SETTING}"* ]]; then
  22. local IN_SETTING=1
  23. fi
  24. if [[ ("${line}" == *"${DEFAULT_TRUE}"* || "${line}" == *"${DEFAULT_ON}"*) && "${IN_SETTING}" == "1" ]]; then
  25. local FOUND=1
  26. break
  27. fi
  28. done < "${FILENAME}"
  29. if [[ "${FOUND}" != "1" ]]; then
  30. echo "${DEFAULT_TRUE} not found for setting ${SETTING} in file ${FILENAME}"
  31. return
  32. fi
  33. # construct line-aware replacement string
  34. if [[ "${line}" == *"${DEFAULT_TRUE}"* ]]; then
  35. local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_TRUE}/${DEFAULT_FALSE}/"
  36. else
  37. local DEFAULT_TRUE_TO_FALSE="${LINE_NUM}s/${DEFAULT_ON}/${DEFAULT_OFF}/"
  38. fi
  39. replace "${DEFAULT_TRUE_TO_FALSE}" "${FILENAME}"
  40. }
  41. update_setting "${TELEMETRY_CRASH_REPORTER}" src/vs/workbench/electron-sandbox/desktop.contribution.ts
  42. update_setting "${TELEMETRY_CONFIGURATION}" src/vs/platform/telemetry/common/telemetryService.ts