You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.6 KiB

  1. #!/bin/sh
  2. if [ ! -e /var/lib/dpkg/status ]; then
  3. echo "This script only works on Ubuntu"
  4. exit 1
  5. fi
  6. if [ "$(id -u)" != 0 ]; then
  7. echo "This script needs to be run as root"
  8. exit 1
  9. fi
  10. echo "This script will permanently destroy and reset all state in snapd"
  11. echo "You will loose all of your installed snaps"
  12. echo
  13. echo "Type REMOVE to remove all of your snap state"
  14. echo
  15. read consent
  16. if [ "$consent" != "REMOVE" ]; then
  17. echo "No consent, aborting"
  18. exit 0
  19. fi
  20. echo
  21. echo "ABOUT TO REMOVE ALL OF STATE OF SNAPD"
  22. echo
  23. echo "Interrupt the script in 10 seconds to abort"
  24. sleep 10 || exit
  25. echo
  26. echo "REMOVING ALL STATE OF SNAPD"
  27. if systemctl is-active --quiet snapd.service snapd.socket; then
  28. snapd_was_active=yes
  29. echo
  30. echo "Stoping snapd..."
  31. echo
  32. (
  33. set -x
  34. systemctl stop snapd.socket snapd.service
  35. )
  36. else
  37. echo "Skipping stopping snapd as systemctl reports it's inactive."
  38. fi
  39. echo
  40. echo "Unmounting all snaps..."
  41. echo
  42. (
  43. set -x
  44. umount /var/lib/snapd/snaps/*.snap
  45. )
  46. echo
  47. echo "Removing all support files and state..."
  48. echo
  49. (
  50. set -x
  51. rm -rvf /var/lib/snapd/*
  52. )
  53. echo
  54. echo "Removing generated systemd units..."
  55. echo
  56. (
  57. set -x
  58. rm -vf /etc/systemd/system/snap-*.mount
  59. rm -vf /etc/systemd/system/snap-*.service
  60. rm -vf /etc/systemd/system/multi-user.target.wants/snap-*.mount
  61. )
  62. echo
  63. echo "Removing generated executable wrappers..."
  64. echo
  65. (
  66. set -x
  67. rm -vrf /snap/*
  68. )
  69. if [ "$snapd_was_active" = "yes" ]; then
  70. echo
  71. echo "Starting snapd"
  72. (
  73. set -x
  74. systemctl start snapd.socket
  75. )
  76. fi