pastebin/add_paste.sh

31 lines
568 B
Bash

#!/bin/bash
paste=$(</dev/stdin)
filename=$1
folder=/home/hebron/pastebin
url=https://git.homelab.no/thomasjsn/pastebin/src/branch/master
if [ ! -d "$folder" ]; then
git clone git@repo.homelab.no:thomasjsn/pastebin.git "$folder"
fi
cd $folder
git pull
if [ -z "$filename" ]; then
filename=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
fi
if [ -f "$folder/$filename" ]; then
echo "Paste already exists!"
exit 1
fi
echo "$paste" > $folder/$filename
git add .
git commit -m "New paste: $filename"
git push
echo "$url/$filename"