2020-05-16 22:19:48 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-02-26 21:05:38 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
set -xeuo pipefail
|
2020-02-25 18:29:39 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
[[ "$(id -u)" -eq 0 ]] || exec sudo "${0}" "${@}"
|
2020-02-25 18:29:39 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
remove_uninstall() {
|
|
|
|
[ -f "${0}" ] && rm -- "${0}"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
trap remove_uninstall EXIT
|
|
|
|
|
|
|
|
/usr/local/bin/k3s-killall.sh ; echo "k3s-killall.sh exited ${?} ..."
|
|
|
|
|
|
|
|
WSYSCTL=$(which systemctl || true)
|
|
|
|
|
|
|
|
if [[ "${WSYSCTL}" != "" ]] ; then
|
2020-02-25 18:29:39 +01:00
|
|
|
systemctl disable k3s
|
|
|
|
systemctl reset-failed k3s
|
|
|
|
systemctl daemon-reload
|
|
|
|
fi
|
2020-02-26 21:05:38 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
WRCUPD=$(which rc-update || true)
|
|
|
|
|
|
|
|
if [[ "${WRCUPD}" != "" ]] ; then
|
2020-02-25 18:29:39 +01:00
|
|
|
rc-update delete k3s default
|
|
|
|
fi
|
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
K3SSVC=$(ls /etc/systemd/system/k3s*.service || true)
|
2020-02-25 18:29:39 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
if [[ "${K3SSVC}" != "" ]] ; then
|
|
|
|
for unit in /etc/systemd/system/k3s*.service ; do
|
2020-07-25 21:42:26 +02:00
|
|
|
unit_name="$(basename "${unit}")"
|
|
|
|
systemctl stop "${unit_name}"
|
2020-05-16 22:19:48 +02:00
|
|
|
[ -f "${unit}" ] && rm -f "${unit}"
|
|
|
|
done
|
2020-07-25 21:42:26 +02:00
|
|
|
systemctl daemon-reload
|
2020-05-16 22:19:48 +02:00
|
|
|
fi
|
2020-02-25 18:29:39 +01:00
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
K3SINIT=$(ls /etc/init.d/k3s* || true)
|
|
|
|
|
|
|
|
if [[ "${K3SINIT}" != "" ]] ; then
|
2020-02-25 18:29:39 +01:00
|
|
|
set +x; echo 'Additional k3s services installed, skipping uninstall of k3s'; set -x
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2020-05-16 22:19:48 +02:00
|
|
|
for cmd in {kubectl,crictl,ctr} ; do
|
2020-07-25 21:42:26 +02:00
|
|
|
if [ -f "{{ k3s_install_dir }}/${cmd}" ]; then
|
2020-05-16 22:19:48 +02:00
|
|
|
rm -f "{{ k3s_install_dir }}/${cmd}"
|
2020-02-25 18:29:39 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-02-26 21:05:38 +01:00
|
|
|
for bin in {{ k3s_install_dir }}/k3s*; do
|
2020-05-16 22:19:48 +02:00
|
|
|
[ -f "${bin}" ] && rm -f "${bin}"
|
2020-02-26 21:05:38 +01:00
|
|
|
done
|
2020-05-16 22:19:48 +02:00
|
|
|
|
2020-07-25 21:42:26 +02:00
|
|
|
[ -d /etc/rancher/k3s ] && rm -rf /etc/rancher/k3s
|
2020-10-22 20:26:15 +02:00
|
|
|
[ -d {{ k3s_runtime_config['data-dir'] | default('/var/lib/rancher/k3s') }} ] && rm -rf {{ k3s_runtime_config['data-dir'] | default('/var/lib/rancher/k3s') }}
|
2020-07-25 21:42:26 +02:00
|
|
|
[ -d /var/lib/kubelet ] && rm -rf /var/lib/kubelet
|
|
|
|
|
2020-02-26 22:52:56 +01:00
|
|
|
[ -f /usr/local/bin/k3s-killall.sh ] && rm -f /usr/local/bin/k3s-killall.sh
|