diff options
-rw-r--r-- | .SRCINFO | 9 | ||||
-rw-r--r-- | PKGBUILD | 10 | ||||
-rw-r--r-- | digitalocean-synchronize.sh | 37 |
3 files changed, 32 insertions, 24 deletions
@@ -1,18 +1,17 @@ pkgbase = digitalocean-synchronize pkgdesc = DigitalOcean Synchronization (passwords, keys, networks) - pkgver = 2.6 - pkgrel = 3 + pkgver = 2.7 + pkgrel = 2 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 = 4b657d5fb413180bb1d5e513e8e466d8388ff935ef27e048c70fd34220a164d2 sha256sums = 25e28f7b3351662b8e2da71aee38a1131df2568177e676e49f47a75d33894d64 sha256sums = d85cde96e602a4ff296d18a7769c683a66feffe5db35a03cdeab651922681f85 pkgname = digitalocean-synchronize - @@ -2,8 +2,8 @@ # Contributor: Kyle Manna <kyle at kylemanna dot com> pkgname=digitalocean-synchronize -pkgver=2.6 -pkgrel=3 +pkgver=2.7 +pkgrel=2 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=('4b657d5fb413180bb1d5e513e8e466d8388ff935ef27e048c70fd34220a164d2' '25e28f7b3351662b8e2da71aee38a1131df2568177e676e49f47a75d33894d64' 'd85cde96e602a4ff296d18a7769c683a66feffe5db35a03cdeab651922681f85') diff --git a/digitalocean-synchronize.sh b/digitalocean-synchronize.sh index 5de4bca8744f..7fd813d623a2 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 @@ -33,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 @@ -74,8 +81,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=$(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 @@ -95,26 +102,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=$(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 -sf ${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 -sf ${url}anchor_ipv4/address) - local prefix=$(netmask_to_prefix $(curl -sf ${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 -sf ${url}ipv6/address) - local prefix=$(curl -sf ${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 -sf ${url}ipv6/gateway)" + echo "Gateway=$(http_get ${url}ipv6/gateway)" fi log "Added IPv6 address ${address}/${prefix} on ${interface}." fi @@ -128,7 +135,7 @@ process_interface() { traverse_interfaces() { local url=$1 - set -- $(curl -Ssf ${url}) + set -- $(http_get -S ${url}) if [[ " $* " =~ " mac " ]]; then process_interface ${url} "$*" else @@ -143,7 +150,7 @@ traverse_interfaces() { setup_from_metadata_service() { local sshkeys - if sshkeys=$(curl -Ssf ${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 @@ -152,9 +159,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=$(http_get -S ${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 +181,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 http_get -S -m 1 ${meta_base} >/dev/null; then setup_from_metadata_service break else |