4

Packing, encrypting and uploading deliverables

 2 years ago
source link: https://wsdookadr.github.io/posts/p7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Packing, encrypting and uploading deliverables

Intro

Sometimes when I do client work, I don’t have time to set up Git repositories. When the work is done, I generate the invoice based on the time spent on the project, and I have to ship the deliverables.

Recently I’ve been working on a C# project, and I use a Windows10 laptop where I happen to have a WSL installed.

I could set up a continuous integration (CI) environment to trigger builds for every commit, and have the binaries available in some artifact repository, or I could set up a file server for this and use scp or sftp, but again, that’s not the case.

Transferring the deliverables by e-mail doesn’t always work because sometimes the e-mail provider will block attachments that contain binaries or exceed a certain size.

Because of this I needed a simple solution to just pack the deliverables (with strong enough encryption, data + headers) and just upload them to a file sharing service.

File sharing services

I’ve had a look at existing file sharing services, and specifically I wanted to find something that:

  • allows direct download (no waiting times, no pop-ups, no ads)

  • doesn’t require registration

  • supports upload using curl

  • does not require me to use a browser for the upload

  • is free

There are many such services but these ones were a good fit for this use-case:

servicemin expiry timemax sizedirect download

file.io

100 MB

transfer.sh

14 days

free.keep.sh

500 MB

Upload script

To run this script you’ll need some packages installed:

sudo apt-get install p7zip-full jq makepasswd curl

And the script itself:

pack_encrypted.sh
#!/bin/bash
DIR="$1"
PASS=$(makepasswd --chars 40)
ARCHIVE=d1.7z

if [[ -e "$DIR" && -d "$DIR" ]]; then
    rm -f $ARCHIVE
    find "$DIR" -name "*.dll" -or -name "*.exe" | xargs -I{} rm "{}"
    7z a -r -p$PASS -mx=9 -mhe=on -t7z $ARCHIVE "$DIR"

    echo "Password:" > pass.txt
    echo "$PASS" >> pass.txt
    echo "" >> pass.txt
    echo "Mirrors:" >> pass.txt
    curl -F "file=@$ARCHIVE" https://file.io/?expires=1w | jq -c -r '.link' >> pass.txt
    curl --upload-file ./$ARCHIVE https://transfer.sh/$ARCHIVE >> pass.txt
    echo "" >> pass.txt
    curl --upload-file ./$ARCHIVE https://free.keep.sh >> pass.txt
    echo "" >> pass.txt
else
    echo "Invalid directory as argument"
fi

Usage

Here’s a usage example, creating a directory with a file in it, using the script to create the encrypted archive, and afterwards displaying the urls where it was uploaded together with the password.

user@home:/tmp/sandbox$ mkdir test1
user@home:/tmp/sandbox$ echo "test" > test1/test.txt
user@home:/tmp/sandbox$ ./pack_encrypted.sh test1
[...]
user@home:/tmp/sandbox$ cat pass.txt
Password:
tEGiJqdGwiynoCIIDAat6JrTHVCCPb5RFzitrb3o

Mirrors:
https://file.io/8d1cZVdQ49iY
https://transfer.sh/gb7x9w/d1.7z
https://free.keep.sh/F44BQzpAUMEbnAzB/d1.7z
If you liked this article and would like to discuss more about scripting or automating various tasks feel free to reach out at [email protected]
Multiple instance Activitywatch remote server setup for time tracking

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK