update_settings.sh 1.3 KB

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