From 1a4f52235caf8d2ec69d0a141cdd3d9b280b1b0f Mon Sep 17 00:00:00 2001 From: Lee Date: Fri, 12 Jul 2024 09:53:18 +0000 Subject: [PATCH] Upload files to "/" --- install-docker.sh | 11 +++++++++ paste-installer.sh | 30 +++++++++++++++++++++++ paste.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 install-docker.sh create mode 100644 paste-installer.sh create mode 100644 paste.sh diff --git a/install-docker.sh b/install-docker.sh new file mode 100644 index 0000000..90b4197 --- /dev/null +++ b/install-docker.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# Usage: curl -sSL https://s.fascinated.cc/s/install-docker | bash +# or use wget: wget -qO- https://s.fascinated.cc/s/install-docker | bash + +# Get ready +apt update +apt upgrade -y +apt install curl -y + +# Install Docker +curl -sSL https://get.docker.com/ | CHANNEL=stable bash \ No newline at end of file diff --git a/paste-installer.sh b/paste-installer.sh new file mode 100644 index 0000000..afb3598 --- /dev/null +++ b/paste-installer.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Define variables +SCRIPT_URL="https://git.fascinated.cc/Fascinated/linux-scripts/raw/branch/master/paste.sh" +SCRIPT_NAME="paste.sh" +PROFILE_FILE="$HOME/.bashrc" # Use .bash_profile for MacOS or if preferred + +# Download the script +echo "Downloading $SCRIPT_NAME from $SCRIPT_URL..." +curl -o $SCRIPT_NAME $SCRIPT_URL + +# Make the script executable +echo "Making $SCRIPT_NAME executable..." +chmod +x $SCRIPT_NAME + +# Move script to the home directory +mv $SCRIPT_NAME $HOME + +# Insert alias into profile file if not already present +ALIAS_COMMAND="alias paste=\"$HOME/$SCRIPT_NAME\"" +if ! grep -q "$ALIAS_COMMAND" "$PROFILE_FILE"; then + echo "Adding alias to $PROFILE_FILE..." + echo "$ALIAS_COMMAND" >> "$PROFILE_FILE" + echo "Alias added. Please restart your terminal or run 'source $PROFILE_FILE' to apply changes." +else + echo "Alias already present in $PROFILE_FILE." +fi + +# Inform the user that the setup is complete +echo "Setup complete. You can now use the 'paste' command." diff --git a/paste.sh b/paste.sh new file mode 100644 index 0000000..57d2034 --- /dev/null +++ b/paste.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Define the domain +domain=https://paste.fascinated.cc + +# Initialize an associative array to hold arguments and their values +declare -A args + +# Default values for optional arguments +args["expires"]="" + +# Function to handle arguments +parse_args() { + while [[ "$#" -gt 0 ]]; do + case $1 in + --expires) args["expires"]=$2; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift + done +} + +# Parse the command-line arguments +parse_args "$@" + +# Read stdin if available +if [ -t 0 ]; then + echo "Nothing to upload. Please provide input data." + exit 1 +fi + +stdin=$(cat) + +# Check if stdin is empty +if [[ -z "$stdin" ]]; then + echo "Nothing to upload. Please provide input data." + exit 1 +fi + +# Construct the upload URL with optional parameters +upload_url="$domain/api/upload" +if [[ -n "${args[expires]}" ]]; then + upload_url="$upload_url?expires=${args[expires]}" +fi + +# Make the POST request and capture the response +response=$(curl -s -H "Accept: application/json" -X POST -d "$stdin" "$upload_url") + +# Check for errors in the response +error_message=$(echo "$response" | jq -r '.error // .message // empty') + +if [[ -n "$error_message" ]]; then + echo "Error: $error_message" + exit 1 +fi + +# Extract the JSON part from the response using jq +key=$(echo "$response" | jq -r '.key') + +# Print the URL +echo "$domain/$key"