<commit_before>#!/bin/bash
#
# Name:	 	backup-zip.sh
# Description:	Take given folder and create an encrypted tar archive
#
# Author:	<EMAIL>
# Version:	0.5

#set -x


PASSPHRASE="<PASSWORD>"


TAR="/bin/tar"
GPG="/usr/bin/gpg"
SED="/bin/sed"

startTimer() {
    START_TIME=$(date)
    S_TIME=$(date +%s)
}

endTimer() {
    END_TIME=$(date)
    E_TIME=$(date +%s)
    DURATION=$(echo $((E_TIME - S_TIME)))

    #calculate overall completion time
    if [[ ${DURATION} -le 60 ]] ; then
        echo "Ended: "${END_TIME}" - Duration: ${DURATION} Seconds"
    else
        echo "Ended: "${END_TIME}" - Duration: $(awk 'BEGIN{ printf "%.2f\n", '${DURATION}'/60}') Minutes"
    fi
}

startTimer

# make sure there is no trailing / 
VM_DIR=$(echo "$1" | ${SED} 's#/*$##')

echo "${VM_DIR}"

${TAR} c -v -S -C "${VM_DIR}" . | ${GPG} -c --passphrase "${PASSPHRASE}" --cipher-algo aes256 --compress-algo zlib --no-use-agent --batch --no-tty --yes -o "${VM_DIR}".gpg

if [[ $? == 0 ]]; then
    # Return 0 -> so everything was ok
    echo -e "\e[32mSuccess\e[0m"
else
    echo -e "\e[31mFailed\e[0m"
fi

echo -e "Resulting File: \e[33m$(ls -sh "${VM_DIR}".gpg)\e[0m"

endTimer
#EOF<commit_msg>add checks for passphrase file (make sure it's there, readable, protected and has 1 line<commit_after>#!/bin/bash
#
# Name:	 	backup-zip.sh
# Description:	Take given folder and create an encrypted tar archive
#
# Author:	<EMAIL>.de
# Version:	0.6

## Debuging
set -x

## only filename.. file is expected to be located in same directory as backup-[un]zip.sh script
PASSPHRASE_FILENAME="backup-passphrase.txt"


## setup basics
TAR="/bin/tar"
GPG="/usr/bin/gpg"
SED="/bin/sed"

startTimer() {
    START_TIME=$(date)
    S_TIME=$(date +%s)
}

endTimer() {
    END_TIME=$(date)
    E_TIME=$(date +%s)
    DURATION=$(echo $((E_TIME - S_TIME)))

    #calculate overall completion time
    if [[ ${DURATION} -le 60 ]] ; then
        echo "Ended: "${END_TIME}" - Duration: ${DURATION} Seconds"
    else
        echo "Ended: "${END_TIME}" - Duration: $(awk 'BEGIN{ printf "%.2f\n", '${DURATION}'/60}') Minutes"
    fi
}

startTimer

## setup full patch for passphrase file and check it
SCRIPTPATH=$(dirname $0)
PASSPHRASE_FILE_FULL_PATH=${SCRIPTPATH}/${PASSPHRASE_FILENAME}

## check that file exists
if [[ ! -f ${PASSPHRASE_FILE_FULL_PATH} ]]; then
    echo -e "\e[31mPassphrase file does not exist! Exiting.\e[0m"
    exit 1;
else 
    echo -e "\e[32mPassphrase file found.\e[0m"
    ## check ownership
    if [[ ! -O ${PASSPHRASE_FILE_FULL_PATH} ]]; then
        echo -e "\e[31mPassphrase file is not owned by me (should be root?!). Exiting.\e[0m"
        exit 1;	
    else
	echo -e "\e[32mPassphrase file is owned by me (should be root?!).\e[0m"
        ## check strict permissions (600)
	if [ $(stat -c %a ${PASSPHRASE_FILE_FULL_PATH}) != 600 ]; then
	    echo -e "\e[31mPassphrase file has wrong file permissions. Please set to 600. Exiting.\e[0m"
	    exit 1;
	else
	    echo -e "\e[32mPassphrase file has the right file permissions (600).\e[0m"
            ## check that file has exactly one line
	    if [ $(cat ${PASSPHRASE_FILE_FULL_PATH} | wc -l) != 1 ]; then
	        echo -e "\e[31mPassphrase file does not contain exactly one single line. Exiting.\e[0m"
	    else
		echo -e "\e[32mPassphrase file has exactly one line (as required).\e[0m"
  	    fi # // lines
	fi # // permissions
    fi # // ownership
fi # // exists


echo -e "\e[32mPassphrase file looks ok.\e[0m"
exit 0;

# make sure there is no trailing / 
VM_DIR=$(echo "$1" | ${SED} 's#/*$##')

echo "${VM_DIR}"

${TAR} c -v -S -C "${VM_DIR}" . | ${GPG} -c --passphrase-file "${PASSPHRASE_FILE_FULL_PATH}" --cipher-algo aes256 --compress-algo zlib --no-use-agent --batch --no-tty --yes -o "${VM_DIR}".gpg

if [[ $? == 0 ]]; then
    # Return 0 -> so everything was ok
    echo -e "\e[32mSuccess\e[0m"
else
    echo -e "\e[31mFailed\e[0m"
fi

echo -e "Resulting File: \e[33m$(ls -sh "${VM_DIR}".gpg)\e[0m"

endTimer
#EOF
{'fraction_non_alphanumeric': 0.1767523953605648, 'fraction_numerical': 0.0226928895612708, 'mean_word_length': 3.0770811921891057, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '291270', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1519, 'n_words': 429}