This commit is contained in:
@ -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"
|
||||
|
35
sos/sos
35
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 <server> <label:tag> <file>
|
||||
sos upload <server> <file> <label:tag> [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 <server> <label:tag> <file>"
|
||||
if [ "$#" -lt 3 ]; then
|
||||
echo "Usage: sos upload <server> <file> <label:tag> [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"
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
Reference in New Issue
Block a user