1
0

Upload files to "/"

This commit is contained in:
Lee 2024-07-12 09:53:18 +00:00
commit 1a4f52235c
3 changed files with 102 additions and 0 deletions

11
install-docker.sh Normal file

@ -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

30
paste-installer.sh Normal file

@ -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."

61
paste.sh Normal file

@ -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"