Skip to content

Instantly share code, notes, and snippets.

@fr3fou
Created December 5, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fr3fou/1d559364c08fcd274b9a33da44dbc57a to your computer and use it in GitHub Desktop.
Save fr3fou/1d559364c08fcd274b9a33da44dbc57a to your computer and use it in GitHub Desktop.
#!/bin/sh
# <UDF name="userdata" label="user-data file contents (base64 encoded)" />
set +e +x
FILE_USERDATA="/var/lib/cloud/seed/nocloud-net/user-data"
FILE_METADATA="/var/lib/cloud/seed/nocloud-net/meta-data"
# vendor-data and network-config are optional
echo "Configuring cloud-init..."
echo "set cloud-init/datasources NoCloud" | debconf-communicate
mkdir -p /etc/cloud/cloud.cfg.d /var/lib/cloud/seed/nocloud-net/
if [ -n "$LINODE_ID" ]; then
cat > /etc/cloud/cloud.cfg.d/01-instanceid.cfg <<'EOS'
datasource:
NoCloud:
meta-data:
instance-id: linode$LINODE_ID
EOS
fi
cat > /etc/cloud/cloud.cfg.d/99-warnings.cfg <<'EOS'
#cloud-config
warnings:
dsid_missing_source: off
EOS
UMASK=$(umask)
umask 0066
echo "Creating $FILE_METADATA..."
touch "${FILE_METADATA}"
echo "Creating $FILE_USERDATA..."
touch "${FILE_USERDATA}"
echo "${USERDATA}" | base64 -d > "${FILE_USERDATA}"
umask "${UMASK}"
echo "Installing cloud-init..."
apt -q=2 update
apt -q=2 install -y cloud-init
echo "Running cloud-init... (init, config, and final)"
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment