From 9b15435ef6de98326703110c8820004d240d87d4 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Sat, 9 Nov 2024 05:43:45 +0000 Subject: [PATCH 1/2] Fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9766384..5024753 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Autoshare -An upcoming project. This will be a single program that fully automates the content sharing process (packing content into archives, creating previews, uploading archives and previews, and creating a post template ready to be copied and pasted. +An upcoming project. This will be a single program that fully automates the content sharing process (packing content into archives, creating previews, uploading archives and previews, and creating a post template ready to be copied and pasted). It will be written in a mixture of Bash and Python. Tails and Whonix will be supported, with the goal of making the program work natively in Tails without the need to install additional software. From 537e01864761960878088780b62513fa4ac30489 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Sat, 9 Nov 2024 06:42:05 +0000 Subject: [PATCH 2/2] Added basic archiving script --- modules/archive.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 modules/archive.sh diff --git a/modules/archive.sh b/modules/archive.sh new file mode 100755 index 0000000..593b2ee --- /dev/null +++ b/modules/archive.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +archive_dir="$(dirname "$0")/../archives" + +input_file="${1}" +archive_pwd="${2}" +size="$3" + +check_dependencies() { + if ! mkdir -p "$archive_dir"; then + echo "ERROR: Unable to create archive directory" + exit 1 + fi + + if ! command -v 7z 2>&1 >/dev/null; then + echo "ERROR: 7z must be installed" + exit 1 + fi +} + +check_input() { + if [[ ! -e "${input_file}" ]]; then + echo "ERROR: Input file '${input_file}' does not exist" + exit 2 + fi + + echo "Archiving file/directory '${input_file}'" >&2 +} + +set_volumes() { + volumes= + + if [[ "$size" =~ ^[1-9][0-9]*$ ]]; then + volumes="-v${size}m" + elif [[ -n "$size" ]]; then + echo "Invalid size $size, must be a number" + exit 2 + fi + + echo "Volumes set to '$volumes'" >&2 +} + +generate_name() { + archive="$archive_dir/$(base64 /dev/urandom | tr -dc [:alnum:] | head -c 20).7z" + + echo "Generated archive name $archive" >&2 +} + +create_archive() { + echo "Packing ${input_file} into archive $archive with password ${archive_pwd}" + [[ -n "$volumes" ]] && echo "and volumes of size $size MB" + + 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" >&2 +} + +check_dependencies +check_input +set_volumes +generate_name +create_archive