all repos — dotfiles @ a41150052c09b9f0d94d013c1b086d8d4e8f4039

linux dotfiles

bin/scripts/xup (view raw)

 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
#!/bin/bash

# quick and dirty file sharing script using rsync
# .share folder has to be on the remote machine's
# user's home directory

remote_hostname="glix"
remote_url="https://x.prithu.xyz"

slugen () {
    # generate a slug of alphabets
    dd if=/dev/urandom status=none bs=1024 count=1 | \
        strings | tr -d '[:space:][:punct:][:digit:][lIq]' | cut -c -${1:-3}
}


if [ "$1" ]
then
    if [ -z "$2" ]
    then
        slug=$(slugen)
        if echo "$1" | grep '\.' 2>&1 > /dev/null
        then
            ext=$(echo "$1" | grep '\.' | cut -d '.' -f2 | sed 's/^/\./')
        else
            ext=""
        fi
        rsync --ignore-existing "$1" "$remote_hostname:.share/$slug$ext" || exit 1
        echo "$remote_url/$slug$ext"
    else
        rsync --ignore-existing "$1" "$remote_hostname:.share/$2" || exit 1
        echo "$remote_url/$2"
    fi
fi