2020-05-23 14:46:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-05-23 03:36:30 +00:00
|
|
|
|
|
|
|
# Script used with Drone CI to upload build artifacts (because specifying all this in
|
|
|
|
# .drone.jsonnet is too painful).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
|
|
|
if [ -z "$SSH_KEY" ]; then
|
|
|
|
echo -e "\n\n\n\e[31;1mUnable to upload artifact: SSH_KEY not set\e[0m"
|
|
|
|
# Just warn but don't fail, so that this doesn't trigger a build failure for untrusted builds
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-05-23 14:46:45 +00:00
|
|
|
echo "$SSH_KEY" >ssh_key
|
2020-05-23 03:36:30 +00:00
|
|
|
|
|
|
|
set -o xtrace # Don't start tracing until *after* we write the ssh key
|
|
|
|
|
2020-05-23 14:46:45 +00:00
|
|
|
chmod 600 ssh_key
|
2020-05-23 03:36:30 +00:00
|
|
|
|
2021-01-04 21:17:29 +00:00
|
|
|
os="${UPLOAD_OS:-$DRONE_STAGE_OS-$DRONE_STAGE_ARCH}"
|
2020-06-22 14:30:38 +00:00
|
|
|
if [ -n "$WINDOWS_BUILD_NAME" ]; then
|
|
|
|
os="windows-$WINDOWS_BUILD_NAME"
|
|
|
|
fi
|
|
|
|
|
2020-05-23 03:36:30 +00:00
|
|
|
if [ -n "$DRONE_TAG" ]; then
|
|
|
|
# For a tag build use something like `lokinet-linux-amd64-v1.2.3`
|
2020-06-22 14:30:38 +00:00
|
|
|
base="lokinet-$os-$DRONE_TAG"
|
2020-05-23 03:36:30 +00:00
|
|
|
else
|
|
|
|
# Otherwise build a length name from the datetime and commit hash, such as:
|
|
|
|
# lokinet-linux-amd64-20200522T212342Z-04d7dcc54
|
2020-06-22 14:30:38 +00:00
|
|
|
base="lokinet-$os-$(date --date=@$DRONE_BUILD_CREATED +%Y%m%dT%H%M%SZ)-${DRONE_COMMIT:0:9}"
|
2020-05-23 03:36:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -v "$base"
|
2020-06-22 14:30:38 +00:00
|
|
|
if [ -e daemon/lokinet.exe ]; then
|
2021-03-04 19:05:44 +00:00
|
|
|
cp -av lokinet-*.exe "$base"
|
2020-06-22 14:30:38 +00:00
|
|
|
# zipit up yo
|
|
|
|
archive="$base.zip"
|
|
|
|
zip -r "$archive" "$base"
|
2021-03-02 18:18:22 +00:00
|
|
|
elif [ -e build/outputs/apk/debug/lokinet-debug.apk ] ; then
|
|
|
|
# android af ngl
|
|
|
|
cp -av build/outputs/apk/debug/lokinet-debug.apk "$base"
|
|
|
|
archive="$base.tar.xz"
|
|
|
|
tar cJvf "$archive" "$base"
|
2020-06-22 14:30:38 +00:00
|
|
|
else
|
2020-08-12 15:15:50 +00:00
|
|
|
cp -av daemon/lokinet daemon/lokinet-vpn ../lokinet-bootstrap "$base"
|
2020-06-22 14:30:38 +00:00
|
|
|
# tar dat shiz up yo
|
|
|
|
archive="$base.tar.xz"
|
|
|
|
tar cJvf "$archive" "$base"
|
|
|
|
fi
|
2020-05-23 03:36:30 +00:00
|
|
|
|
2021-01-19 12:39:53 +00:00
|
|
|
upload_to="oxen.rocks/${DRONE_REPO// /_}/${DRONE_BRANCH// /_}"
|
2020-05-23 03:36:30 +00:00
|
|
|
|
|
|
|
# sftp doesn't have any equivalent to mkdir -p, so we have to split the above up into a chain of
|
|
|
|
# -mkdir a/, -mkdir a/b/, -mkdir a/b/c/, ... commands. The leading `-` allows the command to fail
|
|
|
|
# without error.
|
|
|
|
upload_dirs=(${upload_to//\// })
|
|
|
|
mkdirs=
|
|
|
|
dir_tmp=""
|
|
|
|
for p in "${upload_dirs[@]}"; do
|
|
|
|
dir_tmp="$dir_tmp$p/"
|
|
|
|
mkdirs="$mkdirs
|
|
|
|
-mkdir $dir_tmp"
|
|
|
|
done
|
|
|
|
|
2021-01-19 12:39:53 +00:00
|
|
|
sftp -i ssh_key -b - -o StrictHostKeyChecking=off drone@oxen.rocks <<SFTP
|
2020-05-23 03:36:30 +00:00
|
|
|
$mkdirs
|
2020-06-22 14:30:38 +00:00
|
|
|
put $archive $upload_to
|
2020-05-23 03:36:30 +00:00
|
|
|
SFTP
|
|
|
|
|
|
|
|
set +o xtrace
|
|
|
|
|
2020-06-22 14:30:38 +00:00
|
|
|
echo -e "\n\n\n\n\e[32;1mUploaded to https://${upload_to}/${archive}\e[0m\n\n\n"
|
2020-05-23 03:36:30 +00:00
|
|
|
|