#!/bin/sh
set -e
SSH_LOGIN=${SSH_LOGIN:-release}
SSH_ADDRESS=${SSH_ADDRESS:-$SSH_LOGIN@files.radicle.dev}
SSH_KEY="$(rad path)/keys/radicle"
main() {
version="$(build/version)"
nid="$(rad self --did | cut -d: -f3-)"
rad_url="$(rad . | sed s/rad:/rad:\\/\\//)"
rad_remote="$rad_url/$nid"
echo "Uploading Radicle $version..."
if [ -z "$version" ]; then
echo "fatal: empty version number" >&2 ; exit 1
fi
destination="/var/www/files.radicle.dev/releases/$version"
# Create remote folder.
ssh -i "$SSH_KEY" "$SSH_ADDRESS" mkdir -p "$destination"
# Copy files over.
scp -i "$SSH_KEY" "build/artifacts/radicle-$version"* "$SSH_ADDRESS:$destination"
scp -i "$SSH_KEY" build/artifacts/radicle.json "$SSH_ADDRESS:$destination"
scp -i "$SSH_KEY" "build/heartwood-$version.tar.gz" "$SSH_ADDRESS:$destination"
while IFS= read -r target
do
archive=$destination/radicle-$version-$target.tar.xz
symlink=$destination/radicle-$target.tar.xz
echo "Creating symlinks for $target.."
if ssh -n -i "$SSH_KEY" "$SSH_ADDRESS" ln -snf "$archive" "$symlink"; then
echo "✓ Created symlink: $symlink"
else
echo "✗ Failed to create symlink: $symlink"
fi
if ssh -n -i "$SSH_KEY" "$SSH_ADDRESS" ln -snf "$archive.sig" "$symlink.sig"; then
echo "✓ Created symlink: $symlink.sig"
else
echo "✗ Failed to create symlink: $symlink.sig"
fi
if ssh -n -i "$SSH_KEY" "$SSH_ADDRESS" ln -snf "$archive.sha256" "$symlink.sha256"; then
echo "✓ Created symlink: $symlink.sha256"
else
echo "✗ Failed to create symlink: $symlink.sha256"
fi
done < build/TARGETS
# Pushes tags without assuming the remote the user is using. It does this by
# using the pushurl directly, i.e.
# `rad://z3gqcJUoA1n9HaHKufZs5FCSGazv5/<nid>`, where `<nid>` is the local Node
# ID.
echo "Pushing tags to ${rad_remote}.."
git push "${rad_remote}" "releases/${version}"
echo "Done."
}
main "$@"