4 source $(dirname $PWD)/../lib/common.sh
5 source $(dirname $PWD)/../lib/logging.sh
7 if [[ $EUID -ne 0 ]]; then
8 echo "This script must be run as root"
13 rm -rf /etc/apt/sources.list.d/*
16 function clean_essential_packages {
18 for package in crudini curl dnsmasq figlet golang nmap patch psmisc \
19 python3-pip python3-requests python3-setuptools vim wget; do
20 apt-get remove $package -y
22 update-alternatives --remove python /usr/bin/python3
23 update-alternatives --remove pip /usr/bin/pip3
28 function check_prerequisite {
30 apt-get install python3-pip -y
32 update-alternatives --install /usr/bin/python python /usr/bin/python3 1
33 update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
35 if !(which curl); then
36 apt-get install curl -y
39 if !(which add-apt-repository); then
40 apt-get install software-properties-common -y
44 function clean_ironic_packages {
45 for package in python3-ironicclient \
46 python3-ironic-inspector-client \
47 python3-openstackclient genisoimage; do
48 apt-get remove $package -y
52 function clean_docker_packages {
53 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
55 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
59 docker rmi -f $(docker image ls -a -q)
60 apt-get remove docker-ce -y
61 apt-get remove -y docker \
67 apt-get purge docker-* -y --allow-change-held-packages
71 function clean_kubernetes_packages {
72 #Just to make sure kubernetes packages are removed during the download
73 curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
74 bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
75 deb https://apt.kubernetes.io/ kubernetes-xenial main
78 apt-get remove kubelet kubeadm kubectl -y
81 function clean_apt_cache {
83 pushd /var/cache/apt/archives
85 if [ $(ls -1q . | wc -l ) -ge 3 ]; then
86 $(rm !("lock"|"partial"))
92 if [ "$1" == "--only-packages" ]; then
94 clean_docker_packages || true
101 clean_kubernetes_packages
102 clean_docker_packages
103 clean_ironic_packages
104 clean_essential_packages