Skip to content

Commit

Permalink
Zluqet CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Person0z committed Feb 20, 2025
1 parent e924a47 commit 6b45d26
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ docker pull ghcr.io/zluqe/zluqet:latest
```bash
docker run -d -p 5000:5000 -v zluqet:/app/instance ghcr.io/zluqe/zluqet:latest
```

# How to install Zluqet CLI (WIP)
```bash
chmod +x install.sh
```
```bash
./install.sh
```
```bash
./install.sh
```

Usage:
```bash
zluqet --text "<text>" OR zluqet --file <file_location>
```
98 changes: 98 additions & 0 deletions client/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

set -e

INSTALL_PATH="/usr/local/bin/zluqet"

# Define the content of the zluqet script
read -r -d '' ZLUQET_SCRIPT <<'EOF'
#!/bin/bash
# Usage: zluqet --text "<text>" OR zluqet --file <file_location>
# Function to print usage information
usage() {
echo "Usage: $0 --text \"<text>\" OR $0 --file <file_location>"
exit 1
}
# Check if at least two arguments are provided
if [ "$#" -lt 2 ]; then
usage
fi
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
--text)
mode="text"
shift
text="$1"
;;
--file)
mode="file"
shift
file="$1"
;;
*)
echo "Unknown parameter: $1"
usage
;;
esac
shift
done
# If --file was used, read its content
if [ "$mode" == "file" ]; then
if [ ! -f "$file" ]; then
echo "File not found: $file"
exit 1
fi
text=$(cat "$file")
fi
# Define the domain for zluqet
domain="https://paste.zluqe.org"
# Use curl to POST the text
response=$(curl -s -w "\n%{http_code}" -X POST -d "$text" "$domain/api/documents")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
# Try extracting the "key" from the JSON response using jq if available
if command -v jq &> /dev/null; then
key=$(echo "$body" | jq -r '.key')
else
# Fallback extraction using sed
key=$(echo "$body" | sed -n 's/.*"key":[[:space:]]*"\([^"]*\)".*/\1/p')
fi
if [ -n "$key" ]; then
echo "Uploaded successfully. Link: $domain/$key"
else
echo "Error: No paste key returned in the response."
exit 1
fi
else
echo "Failed to upload text: HTTP $http_code"
echo "$body"
exit 1
fi
EOF

# Create a temporary file
tmpfile=$(mktemp)
echo "$ZLUQET_SCRIPT" > "$tmpfile"
chmod +x "$tmpfile"

echo "Installing zluqet to $INSTALL_PATH..."
# Copy the script to /usr/local/bin
if [ "$EUID" -ne 0 ]; then
sudo cp "$tmpfile" "$INSTALL_PATH"
else
cp "$tmpfile" "$INSTALL_PATH"
fi

rm "$tmpfile"

echo "Installation complete! You can now run 'zluqet' from the terminal."

0 comments on commit 6b45d26

Please sign in to comment.