summaryrefslogtreecommitdiff
path: root/kolwynia/home/bdunahu/files/.local/bin/upload
blob: a2db9b5aa3986e25c346009d7832dab5679a8878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh


err() { echo "Usage:
        upload [OPTIONS]
Options:
        -t: time from now to expire in hours (default: 48)
        file: a path to a file. If this is not given, receives input from stdin." && exit 1 ;}

hours=48

while getopts ":t:" opt; do
    case $opt in
        t)
            hours=$OPTARG
            if [[ $OPTARG =~ ^-?[0-9]+$ ]]; then
                hours=$OPTARG
            else
                err
            fi
            ;;
        *)
            err
            ;;
    esac
done

shift $((OPTIND -1))

if [ -n "$1" ] && [ -f "$1" ]; then
    source="$1"
    ext="${1##*.}"
else
    source=$(mktemp)
    ext="txt"
    cat > "$source"
    chmod a+r "$source"
fi

dest="$(cat /dev/random | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1)-$(date -d "+$hours hours" +%s).$ext"

scp "$source" "root@operationnull.com:/var/www/operationnull/paste/$dest" &&
    echo "https://operationnull.com/paste/$dest"