summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Li2022-01-02 20:59:19 -0800
committerGavin Li2022-01-02 20:59:19 -0800
commit56c8e99af4b73fab77a195e4921a3b91a59b73b6 (patch)
tree5a91f54d3688ee800853d58d6a837294659cad28
parentdab508b61fc8556fb07c0e2ce42461d3b7428e75 (diff)
downloadaur-56c8e99af4b73fab77a195e4921a3b91a59b73b6.tar.gz
digitalocean-synchronize 2.7-2
tracking b5d5154 on upstream
-rw-r--r--PKGBUILD4
-rw-r--r--digitalocean-synchronize.sh33
2 files changed, 21 insertions, 16 deletions
diff --git a/PKGBUILD b/PKGBUILD
index d87ec2f343c7..971b51b057c9 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -3,7 +3,7 @@
pkgname=digitalocean-synchronize
pkgver=2.7
-pkgrel=1
+pkgrel=2
pkgdesc='DigitalOcean Synchronization (passwords, keys, networks)'
url='https://github.com/gh2o/digitalocean-debian-to-arch'
@@ -19,7 +19,7 @@ source=(digitalocean-synchronize.sh
digitalocean-synchronize.service
90-dosync-virtio-no-rename.link)
-sha256sums=('d6fe6486e0313b576e7cf226ae50f341cfd2c49b27855c55015cdf43d1390700'
+sha256sums=('4b657d5fb413180bb1d5e513e8e466d8388ff935ef27e048c70fd34220a164d2'
'25e28f7b3351662b8e2da71aee38a1131df2568177e676e49f47a75d33894d64'
'd85cde96e602a4ff296d18a7769c683a66feffe5db35a03cdeab651922681f85')
diff --git a/digitalocean-synchronize.sh b/digitalocean-synchronize.sh
index 34ca52deac7f..7fd813d623a2 100644
--- a/digitalocean-synchronize.sh
+++ b/digitalocean-synchronize.sh
@@ -35,6 +35,11 @@ log() {
echo "[$(date)]" "$@" >&2
}
+http_get() {
+ # Sometimes the API request fails with 'connection reset by peer'
+ curl --location --silent --fail --retry 3 --retry-all-errors "$@"
+}
+
netmask_to_prefix() {
local pfx=0 cmp msk
for cmp in ${1//./ } 0; do
@@ -76,8 +81,8 @@ update_shadow_if_changed() {
process_interface() {
local url=$1
local attrs=$2
- local mac=$(curl -LSsf ${url}mac)
- local type=$(curl -LSsf ${url}type)
+ local mac=$(http_get -S ${url}mac)
+ local type=$(http_get -S ${url}type)
local interface=
local cand path
for cand in $(ls /sys/class/net); do
@@ -97,26 +102,26 @@ process_interface() {
[Network]
EOF
if [[ " ${attrs} " =~ " ipv4/ " ]]; then
- local address=$(curl -Lsf ${url}ipv4/address)
- local prefix=$(netmask_to_prefix $(curl -Lsf ${url}ipv4/netmask))
+ local address=$(http_get ${url}ipv4/address)
+ local prefix=$(netmask_to_prefix $(http_get ${url}ipv4/netmask))
echo "Address=${address}/${prefix}"
if [ "${type}" != "private" ]; then
- echo "Gateway=$(curl -Lsf ${url}ipv4/gateway)"
+ echo "Gateway=$(http_get ${url}ipv4/gateway)"
fi
log "Added IPv4 address ${address}/${prefix} on ${interface}."
fi
if [[ " ${attrs} " =~ " anchor_ipv4/ " ]]; then
- local address=$(curl -Lsf ${url}anchor_ipv4/address)
- local prefix=$(netmask_to_prefix $(curl -Lsf ${url}anchor_ipv4/netmask))
+ local address=$(http_get ${url}anchor_ipv4/address)
+ local prefix=$(netmask_to_prefix $(http_get ${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 -Lsf ${url}ipv6/address)
- local prefix=$(curl -Lsf ${url}ipv6/cidr)
+ local address=$(http_get ${url}ipv6/address)
+ local prefix=$(http_get ${url}ipv6/cidr)
echo "Address=${address}/${prefix}"
if [ "${type}" != "private" ]; then
- echo "Gateway=$(curl -Lsf ${url}ipv6/gateway)"
+ echo "Gateway=$(http_get ${url}ipv6/gateway)"
fi
log "Added IPv6 address ${address}/${prefix} on ${interface}."
fi
@@ -130,7 +135,7 @@ process_interface() {
traverse_interfaces() {
local url=$1
- set -- $(curl -LSsf ${url})
+ set -- $(http_get -S ${url})
if [[ " $* " =~ " mac " ]]; then
process_interface ${url} "$*"
else
@@ -145,7 +150,7 @@ traverse_interfaces() {
setup_from_metadata_service() {
local sshkeys
- if sshkeys=$(curl -LSsf ${meta_base}public-keys) && test -n "${sshkeys}"; then
+ if sshkeys=$(http_get -S ${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
@@ -154,7 +159,7 @@ setup_from_metadata_service() {
fi
fi
local hostname
- if ! test -e /etc/hostname && hostname=$(curl -LSsf ${meta_base}hostname); then
+ if ! test -e /etc/hostname && hostname=$(http_get -S ${meta_base}hostname); then
echo "${hostname}" > /etc/hostname
hostnamectl set-hostname "${hostname}"
log "Hostname set to ${hostname} from metadata service."
@@ -176,7 +181,7 @@ digitalocean_synchronize() {
local retry
for retry in {1..20}; do
log "Attempting to connect to metadata service ..."
- if curl -LSsf -m 1 ${meta_base} >/dev/null; then
+ if http_get -S -m 1 ${meta_base} >/dev/null; then
setup_from_metadata_service
break
else