From caba16ea0d3a4cc9ed6c91429a31dc7737cf8fea Mon Sep 17 00:00:00 2001 From: Thomas vO Date: Wed, 28 Nov 2018 11:02:51 +0100 Subject: [PATCH] add script + doc to remove everything --- docs/uninstalling.md | 5 ++- .../matrix-server/tasks/setup/setup_main.yml | 9 ++++- .../usr-local-bin/matrix-remove-all.j2 | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 roles/matrix-server/templates/usr-local-bin/matrix-remove-all.j2 diff --git a/docs/uninstalling.md b/docs/uninstalling.md index 3693ac1bf..7acb9bcc1 100644 --- a/docs/uninstalling.md +++ b/docs/uninstalling.md @@ -18,4 +18,7 @@ However, if you've installed this on some server where you have other stuff you - uninstall Docker itself, if necessary -- delete the `/matrix` directory (`rm -rf /matrix`) \ No newline at end of file +- delete the `/matrix` directory (`rm -rf /matrix`) + +The script `/usr/local/bin/matrix-remove-all` performs all these steps (**use with caution!**). + diff --git a/roles/matrix-server/tasks/setup/setup_main.yml b/roles/matrix-server/tasks/setup/setup_main.yml index a4da6986b..a147c862d 100644 --- a/roles/matrix-server/tasks/setup/setup_main.yml +++ b/roles/matrix-server/tasks/setup/setup_main.yml @@ -53,4 +53,11 @@ - name: Create Matrix network in Docker shell: cmd: "docker network create --driver=bridge {{ matrix_docker_network }}" - when: "result_check_docker_network.stdout == ''" \ No newline at end of file + when: "result_check_docker_network.stdout == ''" + +- name: Ensure matrix-remove-all script created + template: + src: "{{ role_path }}/templates/usr-local-bin/matrix-remove-all.j2" + dest: "/usr/local/bin/matrix-remove-all" + mode: 0750 + diff --git a/roles/matrix-server/templates/usr-local-bin/matrix-remove-all.j2 b/roles/matrix-server/templates/usr-local-bin/matrix-remove-all.j2 new file mode 100644 index 000000000..5614b0e37 --- /dev/null +++ b/roles/matrix-server/templates/usr-local-bin/matrix-remove-all.j2 @@ -0,0 +1,34 @@ +#!/bin/bash + +if [ "$(id -u)" != "0" ]; then + echo "This script must be executed as root! Aborting." + exit 1 +fi + +echo "WARNING! You are about to remove everything the playbook installs for matrix.{{ host_specific_hostname_identity }}: matrix, docker images,..." +echo -n "If you're sure you want to do this, type: 'Yes, I really want to remove everything!'" +read sure + +if [ "$sure" != "Yes, I really want to remove everything!" ]; then + echo "Good thing I asked, exiting" + exit 0 +else + echo "Stop and remove matrix services" + for s in $(find /etc/systemd/system/ -name "matrix-*" -printf "%f\n"); do + systemctl stop $s + rm -f /etc/systemd/system/$s + done + systemctl daemon-reload + echo "Remove matrix cronjobs" + find /etc/cron.d/ -name "matrix-*" -delete + echo "Remove matrix scripts" + find /usr/local/bin/ -name "matrix-*" -delete + echo "Remove every docker images" + docker rmi $(docker images -aq) + echo "Remove docker matrix network" + docker network rm matrix + echo "Remove /matrix directory" + rm -fr /matrix + exit 0 +fi +