windows-uninstall.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env bash
  2. #####################################################################
  3. ## __ __ _ ___________ ##
  4. ## \ \ / /| |____ ____| ##
  5. ## \ \ / / | | | | ##
  6. ## \ \ /\ / / | | | | ##
  7. ## \ \/ \/ / | | | | ##
  8. ## \ /\ / | | | | ##
  9. ## \/ \/ |_| |_| ##
  10. ## ##
  11. ## Wiimms ISO Tools ##
  12. ## https://wit.wiimm.de/ ##
  13. ## ##
  14. #####################################################################
  15. ## ##
  16. ## This file is part of the WIT project. ##
  17. ## Visit https://wit.wiimm.de/ for project details and sources. ##
  18. ## ##
  19. ## Copyright (c) 2009-2021 by Dirk Clemens <wiimm@wiimm.de> ##
  20. ## ##
  21. #####################################################################
  22. ## ##
  23. ## This file installs the distribution on a windows system. ##
  24. ## ##
  25. #####################################################################
  26. #------------------------------------------------------------------------------
  27. # simple cygwin check
  28. if [[ $1 != --cygwin ]]
  29. then
  30. echo "Option --cygwin not set => exit" >&2
  31. exit 1
  32. fi
  33. #------------------------------------------------------------------------------
  34. # pre definitions
  35. BIN_FILES="@@BIN-FILES@@"
  36. WDF_LINKS="@@WDF-LINKS@@"
  37. SHARE_FILES="@@SHARE-FILES@@"
  38. WIN_INSTALL_PATH="@@WIN-INSTALL-PATH@@"
  39. #------------------------------------------------------------------------------
  40. # setup
  41. echo "* setup"
  42. export PATH=".:$PATH"
  43. key="/machine/SOFTWARE/Microsoft/Windows/CurrentVersion/ProgramFilesDir"
  44. if ! WIN_PROG_PATH="$(regtool get "$key")" || [[ $WIN_PROG_PATH = "" ]]
  45. then
  46. echo "Can't determine Windows program path => abort" >&2
  47. exit 1
  48. fi
  49. #CYGWIN_PROG_PATH="$( realpath "$WIN_PROG_PATH" )"
  50. CYGWIN_PROG_PATH="${WIN_PROG_PATH//\\//}"
  51. WDEST="$WIN_PROG_PATH\\${WIN_INSTALL_PATH//\//\\}"
  52. CDEST="$CYGWIN_PROG_PATH/$WIN_INSTALL_PATH"
  53. #------------------------------------------------------------------------------
  54. # remove application pathes
  55. for tool in $BIN_FILES $WDF_LINKS
  56. do
  57. key="/machine/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/$tool.exe"
  58. if regtool check "$key" >/dev/null 2>&1
  59. then
  60. echo "* remove application path for '$tool.exe'"
  61. regtool unset "$key/" "${WDEST}\\${tool}.exe"
  62. regtool unset "$key/Path" "${WDEST}\\"
  63. regtool remove "$key"
  64. fi
  65. done
  66. #------------------------------------------------------------------------------
  67. # remove WIT path to environment 'Path'
  68. echo "* remove WIT path from environment 'Path'"
  69. function set_path()
  70. {
  71. local key="$1"
  72. local p=
  73. local count=0
  74. local new_path=
  75. # split at ';' & substitute ' ' temporary to ';' to be space save
  76. for p in $( regtool --quiet get "$key" | tr '; ' '\n;' )
  77. do
  78. p="${p//;/ }"
  79. #echo " -> |$p|"
  80. [[ "$p" = "$WDEST" ]] || new_path="$new_path;$p"
  81. done
  82. [[ $new_path = "" ]] || regtool set -e "$key" "${new_path:1}"
  83. }
  84. set_path '/machine/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/Path'
  85. set_path '/user/Environment/Path'
  86. #------------------------------------------------------------------------------