This commit is contained in:
parent
d8598933ec
commit
7d1910d6bd
12
Dockerfile
12
Dockerfile
@ -2,16 +2,22 @@ FROM debian:latest
|
|||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
build-essential cmake git wget tar curl ninja-build mold nodejs npm perl jq ccache nlohmann-json3-dev \
|
build-essential cmake git wget tar curl ninja-build mold nodejs npm perl jq ccache nlohmann-json3-dev \
|
||||||
|
ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN echo "deb http://deb.debian.org/debian testing main" | tee /etc/apt/sources.list.d/testing-temp.list
|
RUN echo "deb http://deb.debian.org/debian testing main" | tee /etc/apt/sources.list.d/testing-temp.list
|
||||||
|
|
||||||
RUN apt-get update && apt-get -t testing install -y upx-ucl && \
|
RUN apt-get update && apt-get install -f && apt-get -t testing install -y upx-ucl && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
rm /etc/apt/sources.list.d/testing-temp.list && \
|
rm /etc/apt/sources.list.d/testing-temp.list && \
|
||||||
apt-get update
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
|
||||||
|
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN curl -fsSL https://get.docker.com | sh
|
|
||||||
|
|
||||||
COPY --chmod=0755 ./src/* /usr/local/bin/
|
COPY --chmod=0755 ./src/* /usr/local/bin/
|
||||||
|
|
||||||
|
@ -144,24 +144,24 @@ function install_packages() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_headers() {
|
# function install_libassert() {
|
||||||
# put libassert headers on the host.
|
# # put libassert headers on the host.
|
||||||
echo "Checking for libassert headers"
|
# echo "Checking for libassert headers"
|
||||||
if [ ! -f "/usr/local/lib/libassert.a" ]; then
|
# if [ ! -f "/usr/local/lib/libassert.a" ]; then
|
||||||
echo "libassert not found, installing..."
|
# echo "libassert not found, installing..."
|
||||||
git clone https://github.com/jeremy-rifkin/libassert.git
|
# git clone https://github.com/jeremy-rifkin/libassert.git
|
||||||
#git checkout v2.1.5
|
# #git checkout v2.1.5
|
||||||
mkdir libassert/build
|
# mkdir libassert/build
|
||||||
cd "libassert/build" || exit 1
|
# cd "libassert/build" || exit 1
|
||||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
# cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||||
make -j
|
# make -j
|
||||||
${SUDOCMD:-} make install
|
# ${SUDOCMD:-} make install
|
||||||
cd ../..
|
# cd ../..
|
||||||
rm -rf libassert
|
# rm -rf libassert
|
||||||
else
|
# else
|
||||||
echo "libassert headers already installed"
|
# echo "libassert headers already installed"
|
||||||
fi
|
# fi
|
||||||
}
|
# }
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------------------
|
||||||
@ -334,8 +334,6 @@ function main() {
|
|||||||
|
|
||||||
install_packages
|
install_packages
|
||||||
|
|
||||||
install_headers
|
|
||||||
|
|
||||||
install_musl
|
install_musl
|
||||||
|
|
||||||
output_version
|
output_version
|
||||||
|
151
temp/sos
Executable file
151
temp/sos
Executable file
@ -0,0 +1,151 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
|
||||||
|
# get dropshell
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
curl -L -s -o "${TEMP_DIR}/dropshell" "https://getbin.xyz/dropshell.${ARCH}" || die "Failed to download dropshell"
|
||||||
|
chmod +x "${TEMP_DIR}/dropshell"
|
||||||
|
trap 'rm -rf "${TEMP_DIR}"' EXIT
|
||||||
|
DROPSHELL="${TEMP_DIR}/dropshell"
|
||||||
|
|
||||||
|
|
||||||
|
function show_help() {
|
||||||
|
cat << EOF
|
||||||
|
|
||||||
|
sos is a script to upload files to a simple object storage server.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
sos upload <server> <file> <label:tag> [label:tag ...]
|
||||||
|
|
||||||
|
Example:
|
||||||
|
sos upload tools.dropshell.app ./file.txt file:latest
|
||||||
|
|
||||||
|
This will upload the file to the server, and return the download URL.
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
SOS_WRITE_TOKEN: The write token to use for the upload. If not set,
|
||||||
|
the script will look in $HOME/.config/sos/write_token.txt.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function die() {
|
||||||
|
echo "FATAL:"
|
||||||
|
echo "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function datetime() {
|
||||||
|
date -u +"%Y.%m%d.%H%M"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function upload() {
|
||||||
|
if [ "$#" -lt 3 ]; then
|
||||||
|
echo "Usage: sos upload <server> <file> <label:tag> [label:tag ...]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
server=$1
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
# upload the file
|
||||||
|
TARGET_URL="https://$server/upload"
|
||||||
|
echo "Uploading $file to $TARGET_URL"
|
||||||
|
|
||||||
|
DATETIME=$(datetime)
|
||||||
|
|
||||||
|
# deduplicate the labeltags
|
||||||
|
mapfile -t LABELTAGS < <(printf "%s\n" "${LABELTAGS[@]}" | sort -u)
|
||||||
|
LABELTAGS_JSON=$(printf '"%s",' "${LABELTAGS[@]}")
|
||||||
|
LABELTAGS_JSON="[${LABELTAGS_JSON%,}]"
|
||||||
|
|
||||||
|
METADATA_JSON=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"labeltags": $LABELTAGS_JSON,
|
||||||
|
"description": "Uploaded by sos",
|
||||||
|
"version": "$DATETIME"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
|
||||||
|
WRITE_TOKEN="$SOS_WRITE_TOKEN"
|
||||||
|
else
|
||||||
|
TOKENPATH="$HOME/.config/sos/write_token.txt"
|
||||||
|
if [ ! -f "$TOKENPATH" ]; then
|
||||||
|
die "Token file not found in environment variable SOS_WRITE_TOKEN or $TOKENPATH. Please create it and put your write token in it."
|
||||||
|
fi
|
||||||
|
WRITE_TOKEN=$(cat "$TOKENPATH")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# trip whitespace from the file path
|
||||||
|
LOCALHASH=$("${DROPSHELL}" hash "${file}" | tr -d '[:space:]')
|
||||||
|
echo "Local hash: $LOCALHASH"
|
||||||
|
|
||||||
|
EXISTSJSON=$(eval "curl -s \"https://$server/exists/$LOCALHASH\"") || die "Failed to check if file exists"
|
||||||
|
DOESEXIT=$(echo "$EXISTSJSON" | jq -r '.exists')
|
||||||
|
|
||||||
|
HASH=""
|
||||||
|
|
||||||
|
if [ "$DOESEXIT" == "true" ]; then
|
||||||
|
echo "File already exists, skipping upload"
|
||||||
|
|
||||||
|
curl -X PUT -H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
|
-F "metadata=${METADATA_JSON}" \
|
||||||
|
"$TARGET_URL" \
|
||||||
|
|| die "Failed to upload $file to $TARGET_URL"
|
||||||
|
else
|
||||||
|
curl -X PUT -H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||||
|
-F "metadata=${METADATA_JSON}" \
|
||||||
|
-F "file=@${file}" \
|
||||||
|
"$TARGET_URL" \
|
||||||
|
|| die "Failed to upload $file to $TARGET_URL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " "
|
||||||
|
echo " "
|
||||||
|
|
||||||
|
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"
|
||||||
|
FILENAME=$(echo "$JSON2" | jq -r '.metadata.filename')
|
||||||
|
|
||||||
|
echo "Metadata:"
|
||||||
|
echo "$JSON2" | jq
|
||||||
|
|
||||||
|
echo " "
|
||||||
|
|
||||||
|
echo "Download URL: https://$server/$first_label > $FILENAME"
|
||||||
|
echo "Alternative: https://$server/$HASH > $FILENAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
# if no arguments, show help
|
||||||
|
[ "$#" -gt 0 ] || show_help
|
||||||
|
|
||||||
|
CMD="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
if [ "$CMD" == "upload" ]; then
|
||||||
|
upload "$@"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
die "Unknown command: $CMD"
|
Loading…
x
Reference in New Issue
Block a user