-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisable-cloud-init.sh
100 lines (88 loc) · 4.46 KB
/
disable-cloud-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
#===================================================================
# HEADER
#===================================================================
# DESCRIPTION
# Automate the process of disabling cloud-init in a
# non-interactive way.
# Based on https://gist.github.com/zoilomora/f862f76335f5f53644a1b8e55fe98320
#===================================================================
# IMPLEMENTATION
# Author Balzabu
# Copyright Copyright (c) https://www.balzabu.io
# License MIT
# Github https://github.com/balzabu
#===================================================================
# END_OF_HEADER
#===================================================================
# ==================================================================
# Useful ANSI codes
# ==================================================================
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
MAGENTA="\e[35m"
WHITE="\e[97m"
ENDCOLOR="\e[0m"
# ==================================================================
# Credits
# ==================================================================
echo -e "\n.-------------------------."
echo -e "| ${RED}disable${WHITE}-cloud-init${ENDCOLOR} |"
echo -e "| Made with ${RED}<3${ENDCOLOR} by ${GREEN}Balzabu${ENDCOLOR} |"
echo -e "'-------------------------'\n"
# ==================================================================
# Check if the script is run as root
# ==================================================================
if [ "$EUID" -ne 0 ]
then echo -e "${RED}{ERROR}${ENDCOLOR} The script must be ran as root, please try again.\n"
exit
fi
# ==================================================================
# Check if netplan.io is installed and hold it if so
# ==================================================================
NETPLAN_HELD=0
if dpkg-query -W -f='${Status}' netplan.io 2>/dev/null | grep -q "install ok installed"; then
echo -e "${YELLOW}{INFO}${ENDCOLOR} netplan.io is installed, holding the package to prevent it from being removed."
sudo apt-mark hold netplan.io
NETPLAN_HELD=1
else
echo -e "${YELLOW}{INFO}${ENDCOLOR} netplan.io is not installed, no need to hold the package."
fi
# ==================================================================
# Create an empty file to prevent the service from starting
# ==================================================================
sudo touch /etc/cloud/cloud-init.disabled
# ==================================================================
# Create a preseed file that deselects "-" all services expect the
# 'None' in /tmp
# ==================================================================
echo "cloud-init cloud-init/datasources multiselect None -NoCloud -ConfigDrive -OpenNebula -DigitalOcean -Azure -AltCloud -OVF -MAAS -GCE -OpenStack -CloudSigma -SmartOS -Bigstep -Scaleway -AliYun -Ec2 -CloudStack -Hetzner -IBMCloud -Oracle -Exoscale -RbxCloud -UpCloud -VMware -Vultr -LXD -NWCS -Akamai" > /tmp/cloud-init.preseed
# ==================================================================
# Load the preseed file from /tmp
# ==================================================================
sudo debconf-set-selections /tmp/cloud-init.preseed
# ==================================================================
# Clean any existing cloud-init data and logs
# ==================================================================
sudo cloud-init clean
# ==================================================================
# Run dpkg-configure in a noninteractive mode
# ==================================================================
sudo dpkg-reconfigure -fnoninteractive cloud-init
# ==================================================================
# Uninstall the package and delete the folders
# ==================================================================
sudo apt-get purge cloud-init
sudo rm -rf /etc/cloud/ && sudo rm -rf /var/lib/cloud/
# ==================================================================
# Unhold netplan.io if it was held
# ==================================================================
if [ $NETPLAN_HELD -eq 1 ]; then
echo -e "${YELLOW}{INFO}${ENDCOLOR} Unholding netplan.io package."
sudo apt-mark unhold netplan.io
fi
# ==================================================================
# Print a message on screen
# ==================================================================
echo -e "${YELLOW}{INFO}${ENDCOLOR} cloud-init should have been uninstalled; a manual reboot is required to complete. \n"