Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What?

This is a collection of scripts I hacked together as a replacement for Dropbox. Dropbox serves three use-cases for me:

  • Syncing files across different machines

    That's what unison is for. unisyn is a script that, together with wait-for-one (I couldn't find a better name, sorry :) and inw waits for changes on either side and triggers a unison run.

  • Sharing files to the public

    Simply an nginx set up to point to ~/u/pub (where ~/u is my synchronized directory).

  • Publishing files from my phone

    I send the files via e-mail to a special mail address that my mail server hands over to umail, which in turn puts it to ~/u/pub and replies with the link so I can easily copy&paste it somewhere.

The scripts in detail

inw

A wrapper for inotify-tools. See https://github.com/yath/inw for the project.

wait-for-one

Accepts a list of commands on the command-line, waits for one to complete, kills the others and returns with the return code of the command finished.

Example:

$ perl wait-for-one "sleep 2 && false" "cat"
'sleep 2 && false' exited with return code 1
$ echo $?
1
$

That's it. It's used by unisync to call inw locally and remote and wait for one side to report changes.

unisyn

The actual syncing script. Does nothing much except calling wait-for-one as described above and call unison afterwards. Exits if a file ~/u/.nosync exists, when wait-for-one returns with an error or if another instance is already running.

unisyn is meant to be started by cron; I call it every three minutes. It won't do anything if started already, and while running it just waits for changes in ~/u.

umail

Handler for incoming mail. I have created an alias,

u: |/home/yath/umail.wrap

in my /etc/aliases. umail.wrap just calls sudo for my user to the actual umail script:

#!/bin/sh
exec sudo -u yath /home/yath/umail

(The corresponding sudoers entry is Debian-exim ALL=(yath) NOPASSWD: /home/yath/umail.)

For Debian's exim you need to set SYSTEM_ALIASES_PIPE_TRANSPORT to address_pipe in your local macro definitions.

umail reads a MIME encoded mail from stdin, validates it, saves the attachment to ~/u/pub and replies to the sender with a list of the URLs and/or error/warning messages.

The script is even a bit more crappy than the others; I doubt it will live long.

umail.auth.pl

Lives in the same directory as umail and contains a subroutine check_validity that gets an Email::MIME object passed and is supposed to return a true value when validation was successful or a false value otherwise.

A note on e-mail

It turned out that e-mail might not be the best protocol for that. While I knew that because of Base64 my data gets blown up by one third I didn't simply think about K-9 Mail copying this inflated message to the Sent folder as well; so I'm actually transmitting 2.66 megabytes for a 1 MB image.

Maybe someone (or I) comes up with a better solution.

nginx config

Just for the sake of completeness, here's the relevant nginx config snippet:

server {
    listen   [::]:80;
    server_name u.yath.de;

    location / {
        root /home/yath/u/pub;
    }

}

server {
    listen   [::]:443;
    server_name u.yath.de;

    ssl on;
    ssl_certificate something.crt;
    ssl_certificate_key something.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+aRSA+RC4:EDH+aRSA:EECDH:RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;
    ssl_session_cache shared:SSL:10m;

    location / {
        root /home/yath/u/pub;
    }

}

Author

Sebastian Schmidt <yath@yath.de>

Except for inw, which has its own license as described on its project page, everything in this repository is in the Public Domain.

About

unison synchronization foo

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages