update_settings.sh 1.6 KB

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