Skip to content

Instantly share code, notes, and snippets.

@kylemanna
Created December 29, 2020 17:10
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 kylemanna/99bf5d0f1001bc9bfcdb3065a741f2e1 to your computer and use it in GitHub Desktop.
Save kylemanna/99bf5d0f1001bc9bfcdb3065a741f2e1 to your computer and use it in GitHub Desktop.
From e685e2ee9ce193d573e571e3be353af48ea371ac Mon Sep 17 00:00:00 2001
From: Kyle Manna <kyle@kylemanna.com>
Date: Tue, 29 Dec 2020 09:10:32 -0800
Subject: [PATCH] digitalocean-synchronize 2.7-1
* Bump to latest version.
* Resolved issue with IPv6 config not working for me.
---
.SRCINFO | 8 ++++----
PKGBUILD | 10 ++++++----
digitalocean-synchronize.sh | 32 +++++++++++++++++---------------
3 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/.SRCINFO b/.SRCINFO
index 43ab1b8..6293bf9 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,16 +1,16 @@
pkgbase = digitalocean-synchronize
pkgdesc = DigitalOcean Synchronization (passwords, keys, networks)
- pkgver = 2.6
- pkgrel = 3
+ pkgver = 2.7
+ pkgrel = 1
url = https://github.com/gh2o/digitalocean-debian-to-arch
arch = any
license = GPL
- depends = wget
+ depends = curl
options = !strip
source = digitalocean-synchronize.sh
source = digitalocean-synchronize.service
source = 90-dosync-virtio-no-rename.link
- sha256sums = 521e9ec8c6382151313b8bd936450d8a3bc56c052f1bad4b74777ebc4900af53
+ sha256sums = d6fe6486e0313b576e7cf226ae50f341cfd2c49b27855c55015cdf43d1390700
sha256sums = 25e28f7b3351662b8e2da71aee38a1131df2568177e676e49f47a75d33894d64
sha256sums = d85cde96e602a4ff296d18a7769c683a66feffe5db35a03cdeab651922681f85
diff --git a/PKGBUILD b/PKGBUILD
index df58b4c..d87ec2f 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -2,8 +2,8 @@
# Contributor: Kyle Manna <kyle at kylemanna dot com>
pkgname=digitalocean-synchronize
-pkgver=2.6
-pkgrel=3
+pkgver=2.7
+pkgrel=1
pkgdesc='DigitalOcean Synchronization (passwords, keys, networks)'
url='https://github.com/gh2o/digitalocean-debian-to-arch'
@@ -11,13 +11,15 @@ arch=(any)
license=(GPL)
options=(!strip)
-depends=(wget)
+depends=(
+ curl # For requests to metadata service
+)
source=(digitalocean-synchronize.sh
digitalocean-synchronize.service
90-dosync-virtio-no-rename.link)
-sha256sums=('521e9ec8c6382151313b8bd936450d8a3bc56c052f1bad4b74777ebc4900af53'
+sha256sums=('d6fe6486e0313b576e7cf226ae50f341cfd2c49b27855c55015cdf43d1390700'
'25e28f7b3351662b8e2da71aee38a1131df2568177e676e49f47a75d33894d64'
'd85cde96e602a4ff296d18a7769c683a66feffe5db35a03cdeab651922681f85')
diff --git a/digitalocean-synchronize.sh b/digitalocean-synchronize.sh
index 5de4bca..34ca52d 100644
--- a/digitalocean-synchronize.sh
+++ b/digitalocean-synchronize.sh
@@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+# DigitalOcean metadata API
+# https://developers.digitalocean.com/documentation/metadata/
meta_base=http://169.254.169.254/metadata/v1/
set -eu
@@ -74,8 +76,8 @@ update_shadow_if_changed() {
process_interface() {
local url=$1
local attrs=$2
- local mac=$(curl -Ssf ${url}mac)
- local type=$(curl -Ssf ${url}type)
+ local mac=$(curl -LSsf ${url}mac)
+ local type=$(curl -LSsf ${url}type)
local interface=
local cand path
for cand in $(ls /sys/class/net); do
@@ -95,26 +97,26 @@ process_interface() {
[Network]
EOF
if [[ " ${attrs} " =~ " ipv4/ " ]]; then
- local address=$(curl -sf ${url}ipv4/address)
- local prefix=$(netmask_to_prefix $(curl -sf ${url}ipv4/netmask))
+ local address=$(curl -Lsf ${url}ipv4/address)
+ local prefix=$(netmask_to_prefix $(curl -Lsf ${url}ipv4/netmask))
echo "Address=${address}/${prefix}"
if [ "${type}" != "private" ]; then
- echo "Gateway=$(curl -sf ${url}ipv4/gateway)"
+ echo "Gateway=$(curl -Lsf ${url}ipv4/gateway)"
fi
log "Added IPv4 address ${address}/${prefix} on ${interface}."
fi
if [[ " ${attrs} " =~ " anchor_ipv4/ " ]]; then
- local address=$(curl -sf ${url}anchor_ipv4/address)
- local prefix=$(netmask_to_prefix $(curl -sf ${url}anchor_ipv4/netmask))
+ local address=$(curl -Lsf ${url}anchor_ipv4/address)
+ local prefix=$(netmask_to_prefix $(curl -Lsf ${url}anchor_ipv4/netmask))
echo "Address=${address}/${prefix}"
log "Added Anchor IPv4 address ${address}/${prefix} on ${interface}."
fi
if [[ " ${attrs} " =~ " ipv6/ " ]]; then
- local address=$(curl -sf ${url}ipv6/address)
- local prefix=$(curl -sf ${url}ipv6/cidr)
+ local address=$(curl -Lsf ${url}ipv6/address)
+ local prefix=$(curl -Lsf ${url}ipv6/cidr)
echo "Address=${address}/${prefix}"
if [ "${type}" != "private" ]; then
- echo "Gateway=$(curl -sf ${url}ipv6/gateway)"
+ echo "Gateway=$(curl -Lsf ${url}ipv6/gateway)"
fi
log "Added IPv6 address ${address}/${prefix} on ${interface}."
fi
@@ -128,7 +130,7 @@ process_interface() {
traverse_interfaces() {
local url=$1
- set -- $(curl -Ssf ${url})
+ set -- $(curl -LSsf ${url})
if [[ " $* " =~ " mac " ]]; then
process_interface ${url} "$*"
else
@@ -143,7 +145,7 @@ traverse_interfaces() {
setup_from_metadata_service() {
local sshkeys
- if sshkeys=$(curl -Ssf ${meta_base}public-keys) && test -n "${sshkeys}"; then
+ if sshkeys=$(curl -LSsf ${meta_base}public-keys) && test -n "${sshkeys}"; then
[ -d /root/.ssh ] || mkdir -m 0700 /root/.ssh
[ -e /root/.ssh/authorized_keys ] || touch /root/.ssh/authorized_keys
if ! grep -q "${sshkeys}" /root/.ssh/authorized_keys; then
@@ -152,9 +154,9 @@ setup_from_metadata_service() {
fi
fi
local hostname
- if ! test -e /etc/hostname && hostname=$(curl -Ssf ${meta_base}hostname); then
+ if ! test -e /etc/hostname && hostname=$(curl -LSsf ${meta_base}hostname); then
echo "${hostname}" > /etc/hostname
- hostname "${hostname}"
+ hostnamectl set-hostname "${hostname}"
log "Hostname set to ${hostname} from metadata service."
fi
traverse_interfaces ${meta_base}interfaces/
@@ -174,7 +176,7 @@ digitalocean_synchronize() {
local retry
for retry in {1..20}; do
log "Attempting to connect to metadata service ..."
- if curl -Ssf -m 1 ${meta_base} >/dev/null; then
+ if curl -LSsf -m 1 ${meta_base} >/dev/null; then
setup_from_metadata_service
break
else
--
2.29.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment