diff --git a/README.md b/README.md
index 649bf71..5293ae9 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,22 @@
## Tinybackup
-
-
This is a simple bash shell script that creates and restores an encrypted backup using GPG.
-#### Install
+### Install
+
+* `make`
+
+#### How to use it
+
+* backup: `tinybackup b `
+* recover: `tinybackup r `
+
+
-* `sudo make install`
+#### Dependencies
+* (ubuntu/debian): `apt get gzip pv gnupg2`
+* (archlinux): `pacman -S gzip pv gnupg2`
#### Use without installation
diff --git a/diagram.png b/diagram.png
deleted file mode 100644
index 5188c9d..0000000
Binary files a/diagram.png and /dev/null differ
diff --git a/spec/flow-diagram.graphml b/spec/flow-diagram.graphml
new file mode 100644
index 0000000..f1a26c1
--- /dev/null
+++ b/spec/flow-diagram.graphml
@@ -0,0 +1,636 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Backup
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Uncompress
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Decrypt
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Join
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Restore
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Archive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Compress
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Encrypt
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Split
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Folder
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ tinybackup
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spec/flow-diagram.png b/spec/flow-diagram.png
new file mode 100644
index 0000000..0d18fb7
Binary files /dev/null and b/spec/flow-diagram.png differ
diff --git a/tinybackup b/tinybackup
index 4fe0afa..370bbfb 100755
--- a/tinybackup
+++ b/tinybackup
@@ -1,57 +1,80 @@
#!/usr/bin/bash --
# ------------------------------------------------------
-# Simple GPG Backup
+#
+# tinybackup
+# ~~~~~~~~~~
+# the simplest GPG Folder Backup
#
# Author: David Valin
# License: Apache License
+#
# ------------------------------------------------------
-backup () {
- echo -e "\nBACKUP"
- echo -e "__________________________________\n"
- read -p "Location to backup: " backup_folder
- read -p "Backup name: " BACKUP_NAME
- read -p "PGP key id: " KEYID
- echo "Starting backup, be patient...."
- NOW=$(date +"%d%m%Y")
- backup_name="$BACKUP_NAME.$NOW.tgz"
- tar -czvf $backup_name $backup_folder
- enc_output="$backup_name.enc"
- secret $backup_name $enc_output
- echo "Done!"
- echo " - ${enc_output}"
-}
-
-restore () {
- echo -e "\nBACKUP RESTORE"
- echo -e "__________________________________\n"
- read -p "Backup file (encrypted): " backup_file
- read -p "Destination location: " backup_destination
- read -p "PGP key id: " KEYID
- echo "Starting restore, be patient...."
- NOW=$(date +"%d%m%Y")
- restored_file=original.tgz
- final_location=$backup_destination/$restored_file
- reveal $backup_file $restored_file
- tar -xzvf $restored_file $final_location
- echo "Done!"
- echo " - ${final_location}"
-}
-
-secret () {
- gpg --encrypt --armor --output ${enc_output} --recipient $KEYID "${1}"
-}
-
-reveal () {
- gpg --decrypt --output ${2} "${1}"
-}
-
-read -p "backup (b) or restore (r) ? " what_to_do
-
-if [ "$what_to_do" = "b" ]
- then
- backup "$@"; exit
- else
- restore "$@"; exit
+cmd=$1
+
+if [[ "$cmd" == "b" ]]; then
+
+ echo -e "\nBACKUP A FOLDER"
+ echo -e "__________________________________\n"
+
+ backup_folder=$2
+ backup_destination_folder=$3
+ backup_name=$4
+ gpg_pub_key_id=$5
+ NOW=$(date +"%Y%m%d.%H%M")
+ backup_name="$backup_name.$NOW.tgz"
+ enc_output="$backup_name.gpg"
+
+ echo " [x] Backup mode set"
+ echo " [x] Folder to backup: $backup_folder"
+ echo " [x] GPG public key: $gpg_pub_key_id"
+ echo " [x] Backup destination folder: $backup_destination_folder"
+ echo " [x] Backup name: $backup_name"
+ echo ""
+
+ read -p " Press 'y' to continue or any other key to exit: " response
+
+ if [[ "$response" == "y" || "$response" == "Y" ]]; then
+ echo ""
+ echo " [x] Backup started at $NOW..."
+ echo ""
+ mkdir -p $backup_destination_folder
+ # using memory only, archive -> compress -> encrypt -> split
+ tar --absolute-names -cf - "$backup_folder" | gzip | pv | gpg --encrypt --armor --recipient "$gpg_pub_key_id" | split -b 100M - "$backup_destination_folder/$enc_output."
+ else
+ echo "Exiting..."
+ exit 1
+ fi
+ exit 1
fi
+
+if [[ "$cmd" == "r" ]]; then
+
+ echo -e "\nRECOVER FOLDER BACKUP"
+ echo -e "__________________________________\n"
+
+ backup_name=$2
+ recover_root_folder=$3
+ gpg_private_key_id=$4
+ NOW=$(date +"%Y%m%d.%H%M")
+
+ echo " [x] Recover mode set"
+ echo " [x] Recovering $backup_name..."
+ echo " [x] Recover root folder: $recover_root_folder"
+ echo " [x] GPG key: $gpg_private_key_id"
+ echo ""
+ echo " Input files:"
+
+ mkdir -p $recover_root_folder
+
+ # using memory only: read -> decrypt -> uncompress in target
+ for file in "$backup_name."*; do
+ echo " $file"
+ done
+ echo ""
+ echo " [x] Recover started at $NOW..."
+ cat "$backup_name."* | gpg --decrypt --recipient "$gpg_private_key_id" --output - | gunzip | tar -xf - -C "$recover_root_folder"
+ exit 1
+fi
+