diff --git a/dropshell-tool/build.sh b/dropshell-tool/build.sh index bc8b6cf..ebfcc99 100755 --- a/dropshell-tool/build.sh +++ b/dropshell-tool/build.sh @@ -4,29 +4,16 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" TEMP_DIR=$(mktemp -d) -SOS="${TEMP_DIR}/sos" -curl -L -o "${SOS}" https://getbin.xyz/sos -chmod +x "${SOS}" +function getbin() { + local BIN_NAME="$1" + + curl -L -o "${TEMP_DIR}/${BIN_NAME}" "https://getbin.xyz/${BIN_NAME}" + chmod +x "${TEMP_DIR}/${BIN_NAME}" +} +getbin "dropshell-build" +"${TEMP_DIR}/dropshell-build" "${SCRIPT_DIR}" - - - - -# make canonical path -DROPSHELL_BUILD_DIR=$(realpath "${DROPSHELL_BUILD_DIR}") - -# make sure the build script exists -if [ ! -f "${DROPSHELL_BUILD_DIR}/dropshell-build" ]; then - echo "Error: dropshell-build not found" - exit 1 -fi -if [ ! -f "${DROPSHELL_BUILD_DIR}/install_dropshell_build_requirements" ]; then - echo "Error: install_dropshell_build_requirements not found" - exit 1 -fi - -# run the build script -"${DROPSHELL_BUILD_DIR}/dropshell-build" -m -r "${SCRIPT_DIR}" +rm -rf "${TEMP_DIR}" diff --git a/dropshell-tool/publish.sh b/dropshell-tool/publish.sh index 682bd8b..2612185 100755 --- a/dropshell-tool/publish.sh +++ b/dropshell-tool/publish.sh @@ -3,6 +3,7 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +TEMP_DIR=$(mktemp -d) die() { @@ -10,14 +11,19 @@ die() { exit 1 } -function publish_install() { +function publish_tool() { + local TOOLPATH="$1" + local ARCH="$2" + local TOOL; + TOOL=$(basename "$TOOLPATH") - "${SCRIPT_DIR}/../sos/sos" upload "getbin.xyz" "dropshell-tool-install" "dropshell-tool-install" + echo "Publishing $TOOL to getbin.xyz" + + "${TEMP_DIR}/sos" upload "getbin.xyz" "$TOOL" "$TOOLPATH" } function publish_executables() { OUTPUT_DIR="${SCRIPT_DIR}/output" - ARCH=$(uname -m) # Find all dropshell-tool.ARCH files in output/ TOOLS=() @@ -33,7 +39,7 @@ function publish_executables() { fi for TOOL in "${TOOLS[@]}"; do - echo "Publishing $TOOL" + publish_tool "$TOOL" "${TOOL//dropshell-tool./}" # extract the architecture from the tool name ARCH="${TOOL//dropshell-tool./}" @@ -44,7 +50,17 @@ function publish_executables() { } -publish_install +function getbin() { + local BIN_NAME="$1" + + curl -L -o "${TEMP_DIR}/${BIN_NAME}" "https://getbin.xyz/${BIN_NAME}" + chmod +x "${TEMP_DIR}/${BIN_NAME}" +} + + + +getbin "sos" publish_executables +rm -rf "${TEMP_DIR}" echo "Done" \ No newline at end of file diff --git a/sos/publish.sh b/sos/publish.sh index 4c8aa00..5968cd7 100755 --- a/sos/publish.sh +++ b/sos/publish.sh @@ -5,4 +5,4 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # run sos to upload sos -"${SCRIPT_DIR}/sos" upload "getbin.xyz" "sos:latest" "${SCRIPT_DIR}/sos" +"${SCRIPT_DIR}/sos" upload "getbin.xyz" "${SCRIPT_DIR}/sos" "sos:latest" diff --git a/sos/sos b/sos/sos index f7ef403..b96fe1c 100755 --- a/sos/sos +++ b/sos/sos @@ -15,10 +15,10 @@ function show_help() { sos is a script to upload files to a simple object storage server. Usage: - sos upload + sos upload [label:tag ...] Example: - sos upload tools.dropshell.app file:latest ./file.txt + sos upload tools.dropshell.app ./file.txt file:latest This will upload the file to the server, and return the download URL. @@ -42,15 +42,25 @@ function datetime() { function upload() { - if [ "$#" -ne 3 ]; then - echo "Usage: sos upload " + if [ "$#" -lt 3 ]; then + echo "Usage: sos upload [label:tag ...]" exit 1 fi server=$1 - label=$2 - file=$3 + file=$2 + first_label=$3 + LABELTAGS=("$first_label") + [[ "$first_label" =~ : ]] || die "Label $first_label does not contain a tag!" + shift 3 + for label in "$@"; do + [[ "$label" =~ : ]] || die "Label $label does not contain a tag!" + LABELTAGS+=("$label") + done + + # check if file contains : + [[ ! "$file" =~ : ]] || die "File contains : - this is not allowed!" [ -f "$file" ] || die "File not found: $file" @@ -60,15 +70,6 @@ function upload() { DATETIME=$(datetime) - # if the label doesn't have a tag, add :lastest - [[ "$label" =~ : ]] || label="$label:latest" - label_base=$(echo "$label" | cut -d':' -f1) - - LABELTAGS=( - "$label" - "$label_base:$DATETIME" - "$label_base:latest" - ) # deduplicate the labeltags mapfile -t LABELTAGS < <(printf "%s\n" "${LABELTAGS[@]}" | sort -u) LABELTAGS_JSON=$(printf '"%s",' "${LABELTAGS[@]}") @@ -104,7 +105,7 @@ EOF echo " " echo " " - JSON1=$(eval "curl -s \"https://$server/hash/$label\"") + JSON1=$(eval "curl -s \"https://$server/hash/$first_label\"") HASH=$(echo "$JSON1" | jq -r '.hash') JSON2=$(eval "curl -s \"https://$server/meta/$HASH\"") || die "Failed to get meta for $HASH" @@ -115,7 +116,7 @@ EOF echo " " - echo "Download URL: https://$server/$label > $FILENAME" + echo "Download URL: https://$server/$first_label > $FILENAME" echo "Alternative: https://$server/$HASH > $FILENAME" } diff --git a/sos/test.sh b/sos/test.sh index cfe7f29..b597b96 100755 --- a/sos/test.sh +++ b/sos/test.sh @@ -4,4 +4,5 @@ set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -"${SCRIPT_DIR}/sos" upload "getbin.xyz" "sos:test" "${SCRIPT_DIR}/sos" +"${SCRIPT_DIR}/sos" upload "getbin.xyz" "${SCRIPT_DIR}/sos" "sos:test" "sos:dodgy" +