uninstall.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env bash
  2. # installation script for note - must be ran as root
  3. # Copyright ©2013-2023 Jason Trunks
  4. # https://notabug.org/JasKinasis/note
  5. # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  7. # You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  8. # NOTE: This script is still very much a WIP!
  9. # I'm still working out what I want to do with it.
  10. # TODO: The backup and remove option does not work when the uninstall is performed as root.
  11. # Instead - it tries to remove the root users personal notes.
  12. # So we need to find each users notes, back them up and then remove all of them.
  13. # In other words - search home for folders called .note (maxdepth of 2)
  14. # If found - tar.gz them and copy them to the appropriate users /home/
  15. # Installation paths
  16. INSTALLDIR="/usr/local/bin"
  17. MANDIR="/usr/local/share/man"
  18. COMPLETIONDIR="/etc/bash_completion.d"
  19. USERDATADIR=$HOME/.note/
  20. function _areYouSure()
  21. {
  22. local USEROPTION=
  23. echo $1
  24. while :
  25. do
  26. read -r -p "Please press y/n : " -n 1 USEROPTION
  27. case ${USEROPTION} in
  28. y|Y)
  29. return 0
  30. ;;
  31. n|N)
  32. return 1
  33. ;;
  34. *)
  35. esac
  36. echo
  37. done
  38. }
  39. function _removeUserData()
  40. {
  41. local USEROPTION=
  42. echo;echo
  43. echo "What do you want to do with your notes and settings?"
  44. echo " - Backup and delete (b)"
  45. echo " - Delete (d)"
  46. echo " - Keep (k)"
  47. echo " - Quit (q) - quit the uninstaller"
  48. echo " - Cancel (c) - cancel the uninstaller"
  49. while :
  50. do
  51. read -r -p "Please press b, d, k, q or c : " -n 1 USEROPTION
  52. case $USEROPTION in
  53. b|B)
  54. echo;echo
  55. echo "Backing up notes:"
  56. note --backup
  57. echo "Removing users notes and settings:"
  58. rm ${USERDATADIR} -rf
  59. return
  60. ;;
  61. d|D)
  62. echo;echo
  63. echo "Removing .note directory:"
  64. rm ${USERDATADIR} -rf
  65. return
  66. ;;
  67. k|K)
  68. echo;echo
  69. echo "Keeping users notes and settings"
  70. return;
  71. ;;
  72. q|Q|c|C)
  73. return 1;
  74. ;;
  75. *)
  76. echo;
  77. echo "ERROR: Invalid option selected, please try again!"
  78. esac
  79. echo
  80. done
  81. }
  82. echo "Note uninstaller V0.1"
  83. echo "©2023 Jason Trunks"
  84. echo "Blah blah blah licency bollocks... etc"
  85. echo
  86. echo
  87. echo "This script will completely uninstall all components of note"
  88. _areYouSure "Do you wish to continue?"
  89. if [[ $? -eq 0 ]]; then
  90. _removeUserData
  91. if [[ $? -eq 0 ]]; then
  92. echo "Removing note and notesettings"
  93. rm ${INSTALLDIR}/note ${INSTALLDIR}/notesettings
  94. echo "Removing documentation"
  95. rm ${MANDIR}/man1/note.1 ${MANDIR}/man1/notesettings.1
  96. echo "Removing bash_completion file"
  97. rm ${COMPLETIONDIR}/note
  98. echo
  99. echo "Uninstall complete!"
  100. echo;echo
  101. exit
  102. fi
  103. fi
  104. echo;echo
  105. echo "Uninstall cancelled - no changes have been made to your system!"
  106. echo;echo
  107. exit