From 9599a764907ce8da1a970d77a7375bcacef2d58b Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 13:51:44 +0000 Subject: [PATCH 01/40] Created .gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee34761 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +archives/ +previews/ From 262e6916a9ff809a6b7597f67126daaff7813748 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 16:02:22 +0000 Subject: [PATCH 02/40] Much faster method of finding videos --- modules/create_video_previews | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/create_video_previews b/modules/create_video_previews index 0ba0148..60c07fa 100755 --- a/modules/create_video_previews +++ b/modules/create_video_previews @@ -8,8 +8,8 @@ check_dependencies() { if ! mkdir -p "$preview_dir"; then echo "ERROR: Unable to create preview directory" exit 1 - elif ! command -v ffmpeg 2>&1 >/dev/null; then - echo "ERROR: FFmpeg must be installed" + elif ! command -v ffmpeg xargs 2>&1 >/dev/null; then + echo "ERROR: FFmpeg and xargs must be installed" exit 1 fi } @@ -23,7 +23,7 @@ check_input() { # Search for videos recursively using the MIME type find_videos() { - video_list=$(find "${search_dir}" -type f -exec file -i {} \; | grep -oP '.*(?=: video/)') + video_list=$(find ${search_dir} -type f -print0 | xargs -0 file -i | grep -oP '.*(?=:\s+video/)') echo "${video_list}" >&2 } From c6a2961ba38b2a524c9a9e112176399de4bdbf95 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH 03/40] Test commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3a89c54..9d20af2 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,5 @@ Anyone is welcome to collaborate with me. ## Collaborators Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](http://topicgitcoi2s3ohrhkdfxl2ii6ocoysi7d5fstcgatuoqp26b2zldad.onion/PedoDeveloper/autoshare/issues/7) and you will be added as a collaborator + +test commit From e7f2320b827e39e2b1c13f1956ade50e4d982031 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Tue, 12 Nov 2024 12:40:07 +0000 Subject: [PATCH 04/40] Removed use of bc --- modules/archive.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index b6be4aa..3df2d7f 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -44,18 +44,16 @@ calc_smart_volumes() { total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 0 # If total file size is smaller than volume size, don't pack it into volumes - [[ $total_size -lt $size ]] && return 1 + (( total_size < size )) && return 1 - num_volumes=$(echo "($total_size + $size - 1) / $size" | bc) - size=$(echo "($total_size + $num_volumes - 1) / $num_volumes" | bc) + num_volumes=$(( (total_size + size - 1) / size )) + size=$(( (total_size + num_volumes - 1) / num_volumes )) echo "Calculated smart volume size '$size'" >&2 } set_volumes() { - if [[ -n "$size" ]]; then - calc_smart_volumes && volumes="-v${size}m" - fi + [[ -n "$size" ]] && calc_smart_volumes && volumes="-v${size}m" echo "Volumes set to '$volumes'" >&2 } From 66c2231a1522a3ad3625d1cd4ece201965808db6 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Tue, 12 Nov 2024 12:41:08 +0000 Subject: [PATCH 05/40] Added basic video preview script --- modules/video_previews.sh | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 modules/video_previews.sh diff --git a/modules/video_previews.sh b/modules/video_previews.sh new file mode 100755 index 0000000..a250361 --- /dev/null +++ b/modules/video_previews.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +preview_dir="$(dirname "$0")/../previews" + +search_dir="${1}" + +check_dependencies() { + if ! mkdir -p "$preview_dir"; then + echo "ERROR: Unable to create preview directory" + exit 1 + elif ! command -v ffmpeg 2>&1 >/dev/null; then + echo "ERROR: FFmpeg must be installed" + exit 1 + fi +} + +check_input() { + if [[ ! -e "${search_dir}" ]]; then + echo "ERROR: Input file '${search_dir}' does not exist" + exit 2 + fi +} + +# Search for videos recursively using the MIME type +find_videos() { + video_list=$(find "${search_dir}" -type f -exec file -i {} \; | grep -oP '.*(?=: video/)') + + echo "${video_list}" >&2 +} + +create_previews() { + while IFS= read -r video; do + echo "Making preview for ${video}" + make_preview + done <<< "${video_list}" +} + +get_size() { + IFS=',' + read -r width height <<< $(ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0 "${video}") + + if [[ $width -gt $height ]]; then + rows=4 cols=5 + scale_format="200:-1" + else + rows=5 cols=4 + scale_format="-1:200" + fi +} + +get_num_frames() { + local num_snapshots=$(( rows * cols )) + + num_frames=$(ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -of csv=p=0 "${video}") + echo "Num frames: $num_frames" >&2 + + frames_per_snapshot=$(( num_frames / num_snapshots )) +} + +make_preview() { + get_size + get_num_frames + + filename="$(basename "${video}")" + + ffmpeg -nostdin -loglevel panic -i "${video}" -frames 1 -q:v 90 -vf "select=not(mod(n\,$frames_per_snapshot)),scale=$scale_format,tile=${rows}x${cols}" "$preview_dir/${filename}.webp" +} + +check_dependencies +check_input +find_videos +create_previews From e4bce4beef17f7c65389dc12b8a0874d2980f84e Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 14:14:25 +0000 Subject: [PATCH 06/40] logging functions and color variables --- modules/colors.sh | 6 ++++++ modules/functions.sh | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 modules/colors.sh create mode 100644 modules/functions.sh diff --git a/modules/colors.sh b/modules/colors.sh new file mode 100644 index 0000000..45a0adb --- /dev/null +++ b/modules/colors.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Color variables for logging. + +RESET="\033[0m" +GREEN="\033[1;32m" +RED="\033[1;31m" diff --git a/modules/functions.sh b/modules/functions.sh new file mode 100644 index 0000000..8ce2fc9 --- /dev/null +++ b/modules/functions.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Common utility functions shared across multiple files. +source colors.sh + +check_dependencies() { + return 0 +} + +log_info() { + local caller="${0##*/}" + echo -e "$caller: INFO: $*" >&2 +} + +log_notice() { + local caller="${0##*/}" + echo -e "$caller: ${GREEN}NOTICE: $*${RESET}" >&2 +} + +log_err() { + local caller="${0##*/}" + echo -e "$caller: ${RED}ERROR: $*${RESET}" >&2 +} From a43d991a3b1f7d1d9460736bdeecfda39ec99fb1 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 14:17:59 +0000 Subject: [PATCH 07/40] moved calls out of global space to main function, preparing for usage with strict mode --- modules/archive.sh | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 3df2d7f..a1d52f7 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -1,12 +1,10 @@ #!/bin/bash # This script packs a file or directory into a 7z archive with the given password. # It can (optionally) split the archives into volumes of a fixed size in megabytes. +source colors.sh +source functions.sh -archive_dir="$(dirname "$0")/../archives" - -input_file="${1}" -archive_pwd="${2}" -size="$3" +trap 'cleanup' EXIT cleanup() { [[ -n "$archive" ]] && rm -f "$archive*" @@ -72,10 +70,25 @@ create_archive() { 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" >&2 } -trap cleanup 1 2 3 6 +main() { + archive_dir="$(dirname "$0")/../archives" + input_file="${1}" + archive_pwd="${2}" + size="$3" -check_dependencies -check_input -set_volumes -generate_name -create_archive + check_dependencies + check_input + set_volumes + generate_name + create_archive +} + + +# Missing arguments must be caught here when using `set -e`, otherwise +# the script will exit prematurely without logging the error. +if (( $# == 3 )); then + main "$@" +else + log_err "Missing arguments" + exit 2 +fi From 085b8ea8bbfa5356df24caa2c43e2c41f19d869d Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 14:40:12 +0000 Subject: [PATCH 08/40] added yellow --- modules/colors.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/colors.sh b/modules/colors.sh index 45a0adb..2e660ab 100644 --- a/modules/colors.sh +++ b/modules/colors.sh @@ -3,4 +3,5 @@ RESET="\033[0m" GREEN="\033[1;32m" +YELLOW="\033[1;33m" RED="\033[1;31m" From 3c1060a84fe93113d9526a037b9fe3d597c41d23 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 14:43:48 +0000 Subject: [PATCH 09/40] function for checking dependencies added, log functions condensed into a single function --- modules/functions.sh | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/modules/functions.sh b/modules/functions.sh index 8ce2fc9..8931232 100644 --- a/modules/functions.sh +++ b/modules/functions.sh @@ -3,20 +3,36 @@ source colors.sh check_dependencies() { - return 0 + # Usage: check_dependencies 7z unrar curl ... + local dependencies=() + + for dependency in "$@"; do + if ! command -v "$dependency" >/dev/null; then + dependencies+=("$dependency") + fi + done + + if (( "${#dependencies[@]}" > 0 )); then + log_err "Missing dependencies" "${dependencies[@]}" + return 1 + fi } -log_info() { +log() { + # Usage: log "NOTICE|ERROR|WARN" this is a log message ... local caller="${0##*/}" - echo -e "$caller: INFO: $*" >&2 -} + local level="$1"; shift + local color -log_notice() { - local caller="${0##*/}" - echo -e "$caller: ${GREEN}NOTICE: $*${RESET}" >&2 -} + case "$level" in + NOTICE) color="$GREEN" ;; + WARN) color="$YELLOW" ;; + ERROR) color="$RED" ;; -log_err() { - local caller="${0##*/}" - echo -e "$caller: ${RED}ERROR: $*${RESET}" >&2 + # No color for these levels. + INFO) color="" ;; + *) color="" ;; + esac + + echo -e "$caller: ${color}[$level]: $*${RESET}" >&2 } From f363327a34caa6d4badba09fd99cd609b4ce3b68 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 15:14:02 +0000 Subject: [PATCH 10/40] removed check_dependencies in favor of functions.sh version, modified cleanup to use new log function, fixed trap signals --- modules/archive.sh | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) mode change 100755 => 100644 modules/archive.sh diff --git a/modules/archive.sh b/modules/archive.sh old mode 100755 new mode 100644 index a1d52f7..2c0bf23 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -4,21 +4,12 @@ source colors.sh source functions.sh -trap 'cleanup' EXIT +trap 'cleanup' ERR INT cleanup() { - [[ -n "$archive" ]] && rm -f "$archive*" - - echo "Cleaned up all $archive files" >&2 -} - -check_dependencies() { - if ! mkdir -p "$archive_dir"; then - echo "ERROR: Unable to create archive directory" - exit 1 - elif ! command -v 7z 2>&1 >/dev/null; then - echo "ERROR: 7z must be installed" - exit 1 + if [[ -n "$archive" ]]; then + rm -f "${archive}"* + log "INFO" "Cleaning up $(basename $archive) remains before exit" fi } @@ -76,7 +67,13 @@ main() { archive_pwd="${2}" size="$3" - check_dependencies + check_dependencies "7z" + + if ! mkdir -p "$archive_dir"; then + log "ERROR" "Unable to create archive directory" + exit 1 + fi + check_input set_volumes generate_name @@ -89,6 +86,6 @@ main() { if (( $# == 3 )); then main "$@" else - log_err "Missing arguments" + log "ERROR" "Missing arguments" exit 2 fi From 834ba85b304477b8dfa45f77b5574efef9bdbc23 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 15:22:28 +0000 Subject: [PATCH 11/40] replaced all logging statements with log function, resolved misconception with and argument handling --- modules/archive.sh | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 2c0bf23..b0c6493 100644 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -15,17 +15,17 @@ cleanup() { check_input() { if [[ ! -e "${input_file}" ]]; then - echo "ERROR: Input file '${input_file}' does not exist" + log "ERROR" "Input file '${input_file}' does not exist" exit 2 elif [[ -z "${archive_pwd}" ]]; then - echo "ERROR: No password given" + log "ERROR" "No password given" exit 2 elif [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then - echo "Invalid size $size, must be empty or a positive number" + log "ERROR" "Invalid size $size, must be empty or a positive number" exit 2 fi - echo "Archiving file/directory '${input_file}' with password '${archive_pwd}' and size '$size'" >&2 + log "INFO" "Archiving file/directory '${input_file}' with password '${archive_pwd}' and size '$size'" >&2 } # Calculates a "smart" volume size so that each volume (including the final part) will be approximately the same size @@ -38,25 +38,25 @@ calc_smart_volumes() { num_volumes=$(( (total_size + size - 1) / size )) size=$(( (total_size + num_volumes - 1) / num_volumes )) - echo "Calculated smart volume size '$size'" >&2 + log "INFO" "Calculated smart volume size '$size'" >&2 } set_volumes() { [[ -n "$size" ]] && calc_smart_volumes && volumes="-v${size}m" - echo "Volumes set to '$volumes'" >&2 + log "INFO" "Volumes set to '$volumes'" >&2 } # Generates a random archive name of 20 alphanumeric characters generate_name() { archive="$archive_dir/$(tr -dc [:alnum:] < /dev/urandom | head -c 20).7z" - echo "Generated archive name '$archive'" >&2 + log "INFO" "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" + log "INFO" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" + [[ -n "$volumes" ]] && log "INFO" "Volumes size is set to $size MB" 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" >&2 } @@ -80,12 +80,4 @@ main() { create_archive } - -# Missing arguments must be caught here when using `set -e`, otherwise -# the script will exit prematurely without logging the error. -if (( $# == 3 )); then - main "$@" -else - log "ERROR" "Missing arguments" - exit 2 -fi +main "$@" From ebbc407b9350e9f9b175527b57388885e24a41f9 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 15:55:33 +0000 Subject: [PATCH 12/40] removed unnecessary source, fixed logging messages, refactored functions to work in a more traditional functional style rather than relying on global values --- modules/archive.sh | 83 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 25 deletions(-) mode change 100644 => 100755 modules/archive.sh diff --git a/modules/archive.sh b/modules/archive.sh old mode 100644 new mode 100755 index b0c6493..207188e --- a/modules/archive.sh +++ b/modules/archive.sh @@ -1,7 +1,6 @@ #!/bin/bash # This script packs a file or directory into a 7z archive with the given password. # It can (optionally) split the archives into volumes of a fixed size in megabytes. -source colors.sh source functions.sh trap 'cleanup' ERR INT @@ -14,70 +13,104 @@ cleanup() { } check_input() { - if [[ ! -e "${input_file}" ]]; then - log "ERROR" "Input file '${input_file}' does not exist" - exit 2 - elif [[ -z "${archive_pwd}" ]]; then - log "ERROR" "No password given" - exit 2 - elif [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then + local input_file="$1" + local archive_pwd="$2" + local size="$3" + + [[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist" && exit 2 ;} + [[ -n "${archive_pwd}" ]] || { log "ERROR" "No password given" && exit 2 ;} + + if [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then log "ERROR" "Invalid size $size, must be empty or a positive number" exit 2 fi - log "INFO" "Archiving file/directory '${input_file}' with password '${archive_pwd}' and size '$size'" >&2 + log "INFO" "Archiving '${input_file}' with password '${archive_pwd}' and size '$size'" } -# Calculates a "smart" volume size so that each volume (including the final part) will be approximately the same size calc_smart_volumes() { - total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 0 + # Calculates a "smart" volume size so that each volume (including the final part) + # will be approximately the same size + local input_file="$1" + local size="$2" + + total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 1 # If total file size is smaller than volume size, don't pack it into volumes (( total_size < size )) && return 1 num_volumes=$(( (total_size + size - 1) / size )) - size=$(( (total_size + num_volumes - 1) / num_volumes )) + smart_size=$(( (total_size + num_volumes - 1) / num_volumes )) - log "INFO" "Calculated smart volume size '$size'" >&2 + log "INFO" "Calculated smart volume size '$size'" + + echo "$smart_size" } set_volumes() { - [[ -n "$size" ]] && calc_smart_volumes && volumes="-v${size}m" + local input_file="$1" + local size="$2" + local volumes="" - log "INFO" "Volumes set to '$volumes'" >&2 + if [[ -n "$size" ]]; then + smart_size="$(calc_smart_volumes $input_file || echo -n)" + volumes="-v${smart_size}m" + fi + + log "INFO" "Volumes set to '$volumes'" + + echo "$volumes" } # Generates a random archive name of 20 alphanumeric characters generate_name() { archive="$archive_dir/$(tr -dc [:alnum:] < /dev/urandom | head -c 20).7z" - log "INFO" "Generated archive name '$archive'" >&2 + log "INFO" "Generated archive name '$archive'" + + echo "$archive" } create_archive() { - log "INFO" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" + local input_file="$1" + local archive_pwd="$2" + local volumes="$3" + local size="$4" + local archive="$5" + [[ -n "$volumes" ]] && log "INFO" "Volumes size is set to $size MB" - 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" >&2 + 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" } main() { + local input_file="${1:-}" + local archive_pwd="${2:-}" + local size="${3:-}" + local volumes archive archive_dir archive_dir="$(dirname "$0")/../archives" - input_file="${1}" - archive_pwd="${2}" - size="$3" check_dependencies "7z" + check_input "$input_file" "$archive_pwd" "$size" if ! mkdir -p "$archive_dir"; then log "ERROR" "Unable to create archive directory" exit 1 fi - check_input - set_volumes - generate_name - create_archive + volumes="$(set_volumes $size)" + archive="$(generate_name)" + + log "NOTICE" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" + + create_archive \ + "$input_file" \ + "$archive_pwd" \ + "$volumes" \ + "$size" \ + "$archive" + + log "NOTICE" "Archive created" } main "$@" From 8ebb5071a4b6f1ce6612db591ccfe0795ff1fb98 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 16:03:02 +0000 Subject: [PATCH 13/40] added strict mode, fixed unbound variables caused by it --- modules/archive.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 207188e..f5ee030 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -3,6 +3,8 @@ # It can (optionally) split the archives into volumes of a fixed size in megabytes. source functions.sh +set -euo pipefail + trap 'cleanup' ERR INT cleanup() { @@ -49,11 +51,11 @@ calc_smart_volumes() { set_volumes() { local input_file="$1" - local size="$2" + local size="${2:-}" local volumes="" if [[ -n "$size" ]]; then - smart_size="$(calc_smart_volumes $input_file || echo -n)" + smart_size="$(calc_smart_volumes $input_file $size || echo -n)" volumes="-v${smart_size}m" fi @@ -98,10 +100,10 @@ main() { exit 1 fi - volumes="$(set_volumes $size)" + volumes="$(set_volumes $input_file $size)" archive="$(generate_name)" - log "NOTICE" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" + log "INFO" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" create_archive \ "$input_file" \ From 96e65508d141c55c34d2a6824c3fe28650c94257 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 16:04:51 +0000 Subject: [PATCH 14/40] shellcheck --- modules/archive.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index f5ee030..a1043b4 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -10,7 +10,7 @@ trap 'cleanup' ERR INT cleanup() { if [[ -n "$archive" ]]; then rm -f "${archive}"* - log "INFO" "Cleaning up $(basename $archive) remains before exit" + log "INFO" "Cleaning up $(basename "$archive") remains before exit" fi } @@ -55,7 +55,7 @@ set_volumes() { local volumes="" if [[ -n "$size" ]]; then - smart_size="$(calc_smart_volumes $input_file $size || echo -n)" + smart_size="$(calc_smart_volumes "$input_file" "$size" || echo -n)" volumes="-v${smart_size}m" fi @@ -66,7 +66,7 @@ set_volumes() { # Generates a random archive name of 20 alphanumeric characters generate_name() { - archive="$archive_dir/$(tr -dc [:alnum:] < /dev/urandom | head -c 20).7z" + archive="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" log "INFO" "Generated archive name '$archive'" @@ -100,7 +100,7 @@ main() { exit 1 fi - volumes="$(set_volumes $input_file $size)" + volumes="$(set_volumes "$input_file" "$size")" archive="$(generate_name)" log "INFO" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" From 006ecbe7d400cf9786efcee1d71ad585e51531d4 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 17:02:39 +0000 Subject: [PATCH 15/40] fixed non-local variables, changed variable names, other minor fixes --- modules/archive.sh | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index a1043b4..b43094b 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -5,29 +5,28 @@ source functions.sh set -euo pipefail -trap 'cleanup' ERR INT cleanup() { - if [[ -n "$archive" ]]; then - rm -f "${archive}"* - log "INFO" "Cleaning up $(basename "$archive") remains before exit" + local archive_name="$1" + + if [[ -n "$archive_name" ]]; then + rm -f "${archive_name}"* + log "INFO" "Cleaning up $(basename "$archive_name") remains before exit" fi } check_input() { local input_file="$1" - local archive_pwd="$2" + local password="$2" local size="$3" [[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist" && exit 2 ;} - [[ -n "${archive_pwd}" ]] || { log "ERROR" "No password given" && exit 2 ;} + [[ -n "${password}" ]] || { log "ERROR" "No password given" && exit 2 ;} if [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then log "ERROR" "Invalid size $size, must be empty or a positive number" exit 2 fi - - log "INFO" "Archiving '${input_file}' with password '${archive_pwd}' and size '$size'" } calc_smart_volumes() { @@ -35,6 +34,7 @@ calc_smart_volumes() { # will be approximately the same size local input_file="$1" local size="$2" + local total_size num_volumes smart_size total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 1 @@ -53,6 +53,7 @@ set_volumes() { local input_file="$1" local size="${2:-}" local volumes="" + local smart_size if [[ -n "$size" ]]; then smart_size="$(calc_smart_volumes "$input_file" "$size" || echo -n)" @@ -66,34 +67,34 @@ set_volumes() { # Generates a random archive name of 20 alphanumeric characters generate_name() { - archive="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" + local archive_name="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" - log "INFO" "Generated archive name '$archive'" + log "INFO" "Generated archive name '$archive_name'" - echo "$archive" + echo "$archive_name" } create_archive() { local input_file="$1" - local archive_pwd="$2" + local password="$2" local volumes="$3" local size="$4" - local archive="$5" + local archive_name="$5" [[ -n "$volumes" ]] && log "INFO" "Volumes size is set to $size MB" - 7z a -mhe=on "-p${archive_pwd}" "$volumes" "$archive" "${input_file}" + 7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}" } main() { local input_file="${1:-}" - local archive_pwd="${2:-}" + local password="${2:-}" local size="${3:-}" - local volumes archive archive_dir + local volumes archive_name archive_dir archive_dir="$(dirname "$0")/../archives" check_dependencies "7z" - check_input "$input_file" "$archive_pwd" "$size" + check_input "$input_file" "$password" "$size" if ! mkdir -p "$archive_dir"; then log "ERROR" "Unable to create archive directory" @@ -101,16 +102,17 @@ main() { fi volumes="$(set_volumes "$input_file" "$size")" - archive="$(generate_name)" + archive_name="$(generate_name)" - log "INFO" "Packing '${input_file}' into archive '$archive' with password '${archive_pwd}'" + trap 'cleanup "$archive_name"' ERR INT + log "INFO" "Packing '${input_file}' into archive '$archive_name' with password '${password}'" create_archive \ "$input_file" \ - "$archive_pwd" \ + "$password" \ "$volumes" \ "$size" \ - "$archive" + "$archive_name" log "NOTICE" "Archive created" } From 2ec3e333e5cb732d86e40f0211393b468682d4ad Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 17:09:39 +0000 Subject: [PATCH 16/40] minor change + shellcheck --- modules/archive.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index b43094b..67ac48c 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -65,9 +65,10 @@ set_volumes() { echo "$volumes" } -# Generates a random archive name of 20 alphanumeric characters generate_name() { - local archive_name="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" + # Generates a random archive name of 20 alphanumeric characters + local archive_name + archive_name="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" log "INFO" "Generated archive name '$archive_name'" @@ -107,6 +108,7 @@ main() { trap 'cleanup "$archive_name"' ERR INT log "INFO" "Packing '${input_file}' into archive '$archive_name' with password '${password}'" + create_archive \ "$input_file" \ "$password" \ From 904aa642e19e84473842684775411f05fea5cf42 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 17:17:25 +0000 Subject: [PATCH 17/40] remove useless if-statement --- modules/archive.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 67ac48c..780dcc3 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -8,11 +8,8 @@ set -euo pipefail cleanup() { local archive_name="$1" - - if [[ -n "$archive_name" ]]; then - rm -f "${archive_name}"* - log "INFO" "Cleaning up $(basename "$archive_name") remains before exit" - fi + rm -f "${archive_name}"* + log "INFO" "Cleaning up $(basename "$archive_name") remains before exit" } check_input() { From 4bbeec223071b764031d4febf8f098843ee8d81f Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Tue, 12 Nov 2024 17:19:46 +0000 Subject: [PATCH 18/40] use bash builtin instead of basename --- modules/archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/archive.sh b/modules/archive.sh index 780dcc3..7ddf1a6 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -9,7 +9,7 @@ set -euo pipefail cleanup() { local archive_name="$1" rm -f "${archive_name}"* - log "INFO" "Cleaning up $(basename "$archive_name") remains before exit" + log "INFO" "Cleaning up "${archive_name##*/}" remains before exit" } check_input() { From 20f311b7d6dff163bd9e433447a2e503f8aaa877 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 02:12:49 +0000 Subject: [PATCH 19/40] fixed function call to log --- modules/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/functions.sh b/modules/functions.sh index 8931232..80b5d8f 100644 --- a/modules/functions.sh +++ b/modules/functions.sh @@ -13,7 +13,7 @@ check_dependencies() { done if (( "${#dependencies[@]}" > 0 )); then - log_err "Missing dependencies" "${dependencies[@]}" + log "ERROR" "Missing dependencies" "${dependencies[@]}" return 1 fi } From 713fbbb29a865fef6806eb53cf3298ca856eeaed Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 02:14:30 +0000 Subject: [PATCH 20/40] minor comment changes --- modules/functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/functions.sh b/modules/functions.sh index 80b5d8f..6aed634 100644 --- a/modules/functions.sh +++ b/modules/functions.sh @@ -3,7 +3,7 @@ source colors.sh check_dependencies() { - # Usage: check_dependencies 7z unrar curl ... + # Usage: check_dependencies "7z" "unrar" "curl" ... local dependencies=() for dependency in "$@"; do @@ -19,7 +19,7 @@ check_dependencies() { } log() { - # Usage: log "NOTICE|ERROR|WARN" this is a log message ... + # Usage: log "NOTICE|WARN|ERROR" "this is a log message" ... local caller="${0##*/}" local level="$1"; shift local color From 2f7188569021baac2831abe93662bb7ca0c8433f Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 02:19:51 +0000 Subject: [PATCH 21/40] changed name from set_volumes to get_volumes to more accurately describe what the function does --- modules/archive.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 7ddf1a6..756f752 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -46,7 +46,7 @@ calc_smart_volumes() { echo "$smart_size" } -set_volumes() { +get_volumes() { local input_file="$1" local size="${2:-}" local volumes="" @@ -99,7 +99,7 @@ main() { exit 1 fi - volumes="$(set_volumes "$input_file" "$size")" + volumes="$(get_volumes "$input_file" "$size")" archive_name="$(generate_name)" trap 'cleanup "$archive_name"' ERR INT From 5eaa4863f7b9f60e1043bd538d5bb7d697b17535 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 02:33:39 +0000 Subject: [PATCH 22/40] improved logging --- modules/archive.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 756f752..1f21d6a 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -21,7 +21,7 @@ check_input() { [[ -n "${password}" ]] || { log "ERROR" "No password given" && exit 2 ;} if [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then - log "ERROR" "Invalid size $size, must be empty or a positive number" + log "ERROR" "Invalid size '$size', must be empty or a positive number" exit 2 fi } @@ -41,7 +41,7 @@ calc_smart_volumes() { num_volumes=$(( (total_size + size - 1) / size )) smart_size=$(( (total_size + num_volumes - 1) / num_volumes )) - log "INFO" "Calculated smart volume size '$size'" + log "INFO" "Calculated smart volume size '$smart_size'" echo "$smart_size" } @@ -53,11 +53,12 @@ get_volumes() { local smart_size if [[ -n "$size" ]]; then + log "INFO" "Volumes size is set to ${size}MB" smart_size="$(calc_smart_volumes "$input_file" "$size" || echo -n)" volumes="-v${smart_size}m" fi - log "INFO" "Volumes set to '$volumes'" + [[ -n "$volumes" ]] && log "INFO" "Volumes set to '$volumes'" || log "INFO" "Volumes argument unset" echo "$volumes" } @@ -79,8 +80,6 @@ create_archive() { local size="$4" local archive_name="$5" - [[ -n "$volumes" ]] && log "INFO" "Volumes size is set to $size MB" - 7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}" } From cebc024117ad861a7598932dd97c1d69c6e9d041 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 02:40:59 +0000 Subject: [PATCH 23/40] shellcheck --- modules/archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/archive.sh b/modules/archive.sh index 1f21d6a..98101e8 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -9,7 +9,7 @@ set -euo pipefail cleanup() { local archive_name="$1" rm -f "${archive_name}"* - log "INFO" "Cleaning up "${archive_name##*/}" remains before exit" + log "INFO" "Cleaning up ${archive_name##*/} remains before exit" } check_input() { From ceb331eb10849b281d20834ef08e51291a9c8839 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 03:10:19 +0000 Subject: [PATCH 24/40] stop leaking dependency variable --- modules/functions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/functions.sh b/modules/functions.sh index 6aed634..880cf01 100644 --- a/modules/functions.sh +++ b/modules/functions.sh @@ -5,6 +5,7 @@ source colors.sh check_dependencies() { # Usage: check_dependencies "7z" "unrar" "curl" ... local dependencies=() + local dependency for dependency in "$@"; do if ! command -v "$dependency" >/dev/null; then From 596426e5a84ff4f74531effbbf17c69aa3a47838 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:48:23 +0000 Subject: [PATCH 25/40] Added message for collaborators --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5024753..e1eb5c5 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,7 @@ An upcoming project. This will be a single program that fully automates the cont 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. Anyone is welcome to collaborate with me. + +## Collaborators + +Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](issues/7) and you will be added as a collaborator From 5d9436d92c179b235c4631fcedd3a821b72c932f Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:50:03 +0000 Subject: [PATCH 26/40] Changed && to ; --- modules/archive.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index 98101e8..d9ea711 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -17,8 +17,8 @@ check_input() { local password="$2" local size="$3" - [[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist" && exit 2 ;} - [[ -n "${password}" ]] || { log "ERROR" "No password given" && exit 2 ;} + [[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist"; exit 2; } + [[ -n "${password}" ]] || { log "ERROR" "No password given"; exit 2; } if [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then log "ERROR" "Invalid size '$size', must be empty or a positive number" From 3ea5fcfa1591505954e50f58a25bbafb8948e192 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:51:36 +0000 Subject: [PATCH 27/40] Made if statements more concise --- modules/archive.sh | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/archive.sh b/modules/archive.sh index d9ea711..7c3196b 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -19,11 +19,7 @@ check_input() { [[ -e "$input_file" ]] || { log "ERROR" "Input file '${input_file}' does not exist"; exit 2; } [[ -n "${password}" ]] || { log "ERROR" "No password given"; exit 2; } - - if [[ ! "$size" =~ ^([1-9][0-9]*)?$ ]]; then - log "ERROR" "Invalid size '$size', must be empty or a positive number" - exit 2 - fi + [[ "$size" =~ ^([1-9][0-9]*)?$ ]] || { log "ERROR" "Invalid size '$size', must be empty or a positive number"; exit 2; } } calc_smart_volumes() { @@ -93,10 +89,7 @@ main() { check_dependencies "7z" check_input "$input_file" "$password" "$size" - if ! mkdir -p "$archive_dir"; then - log "ERROR" "Unable to create archive directory" - exit 1 - fi + mkdir -p "$archive_dir" || { log "ERROR" "Unable to create archive directory"; exit 1; } volumes="$(get_volumes "$input_file" "$size")" archive_name="$(generate_name)" From c84085236d14c880d14853276f78226a5b44b798 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:52:26 +0000 Subject: [PATCH 28/40] Fixed spacing --- modules/archive.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/archive.sh b/modules/archive.sh index 7c3196b..6b03678 100755 --- a/modules/archive.sh +++ b/modules/archive.sh @@ -1,11 +1,11 @@ #!/bin/bash # This script packs a file or directory into a 7z archive with the given password. # It can (optionally) split the archives into volumes of a fixed size in megabytes. + source functions.sh set -euo pipefail - cleanup() { local archive_name="$1" rm -f "${archive_name}"* From ac4da0bab7c1787ec3ecd541871a48cf36d5f730 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:54:58 +0000 Subject: [PATCH 29/40] Merged colors.sh with functions.sh, moved to separate 'includes' directory --- {modules => includes}/functions.sh | 6 +++++- modules/colors.sh | 7 ------- 2 files changed, 5 insertions(+), 8 deletions(-) rename {modules => includes}/functions.sh (91%) delete mode 100644 modules/colors.sh diff --git a/modules/functions.sh b/includes/functions.sh similarity index 91% rename from modules/functions.sh rename to includes/functions.sh index 880cf01..39ee6eb 100644 --- a/modules/functions.sh +++ b/includes/functions.sh @@ -1,6 +1,10 @@ #!/bin/bash # Common utility functions shared across multiple files. -source colors.sh + +RESET="\033[0m" +GREEN="\033[1;32m" +YELLOW="\033[1;33m" +RED="\033[1;31m" check_dependencies() { # Usage: check_dependencies "7z" "unrar" "curl" ... diff --git a/modules/colors.sh b/modules/colors.sh deleted file mode 100644 index 2e660ab..0000000 --- a/modules/colors.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Color variables for logging. - -RESET="\033[0m" -GREEN="\033[1;32m" -YELLOW="\033[1;33m" -RED="\033[1;31m" From 7da917274b20375a214942254d0e086c840f42c0 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:58:07 +0000 Subject: [PATCH 30/40] Small code improvements --- modules/video_previews.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/video_previews.sh b/modules/video_previews.sh index a250361..0ba0148 100755 --- a/modules/video_previews.sh +++ b/modules/video_previews.sh @@ -37,9 +37,9 @@ create_previews() { get_size() { IFS=',' - read -r width height <<< $(ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0 "${video}") + read -r width height <<< $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "${video}") - if [[ $width -gt $height ]]; then + if (( $width >= $height )); then rows=4 cols=5 scale_format="200:-1" else @@ -61,9 +61,10 @@ make_preview() { get_size get_num_frames - filename="$(basename "${video}")" + filename="$preview_dir/$(basename "${video}").webp" + filters="select=not(mod(n\,$frames_per_snapshot)),scale=$scale_format,tile=${rows}x${cols}" - ffmpeg -nostdin -loglevel panic -i "${video}" -frames 1 -q:v 90 -vf "select=not(mod(n\,$frames_per_snapshot)),scale=$scale_format,tile=${rows}x${cols}" "$preview_dir/${filename}.webp" + ffmpeg -nostdin -loglevel panic -i "${video}" -frames 1 -q:v 90 -vf "$filters" "${filename}" } check_dependencies From 93dd385cbe20c2e6f690a06b588aaded44d01ea2 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 11:58:34 +0000 Subject: [PATCH 31/40] Renamed modules --- modules/{archive.sh => create_archive} | 0 modules/{video_previews.sh => create_video_previews} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename modules/{archive.sh => create_archive} (100%) rename modules/{video_previews.sh => create_video_previews} (100%) diff --git a/modules/archive.sh b/modules/create_archive similarity index 100% rename from modules/archive.sh rename to modules/create_archive diff --git a/modules/video_previews.sh b/modules/create_video_previews similarity index 100% rename from modules/video_previews.sh rename to modules/create_video_previews From f897c8c2a547dd1714004bca5c35d3364c5ad092 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 12:02:00 +0000 Subject: [PATCH 32/40] Fixed link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e1eb5c5..3a89c54 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ Anyone is welcome to collaborate with me. ## Collaborators -Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](issues/7) and you will be added as a collaborator +Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](http://topicgitcoi2s3ohrhkdfxl2ii6ocoysi7d5fstcgatuoqp26b2zldad.onion/PedoDeveloper/autoshare/issues/7) and you will be added as a collaborator From ee40a3b43923bf2f1beb13e4ac724576c4e4a55e Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Wed, 13 Nov 2024 12:13:26 +0000 Subject: [PATCH 33/40] Fixed broken source statement --- modules/create_archive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/create_archive b/modules/create_archive index 6b03678..6f39fd0 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -2,7 +2,7 @@ # This script packs a file or directory into a 7z archive with the given password. # It can (optionally) split the archives into volumes of a fixed size in megabytes. -source functions.sh +source "$(dirname "$0")/../includes/functions.sh" set -euo pipefail From 0ec24ecaf29c23c1b8e3b4b9b5a10d09f2607fb5 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:13:24 +0000 Subject: [PATCH 34/40] remove unused function parameter --- modules/create_archive | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/create_archive b/modules/create_archive index 6f39fd0..a3b4672 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -73,7 +73,6 @@ create_archive() { local input_file="$1" local password="$2" local volumes="$3" - local size="$4" local archive_name="$5" 7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}" @@ -102,7 +101,6 @@ main() { "$input_file" \ "$password" \ "$volumes" \ - "$size" \ "$archive_name" log "NOTICE" "Archive created" From 42bf72e127abac2e16cfb6cb3168b8ea76db516b Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:19:24 +0000 Subject: [PATCH 35/40] remove error handling for mkdir, it's unlikely to fail and the script would exit on error due to set -e anyway --- modules/create_archive | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/create_archive b/modules/create_archive index a3b4672..b9d00f2 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -88,7 +88,7 @@ main() { check_dependencies "7z" check_input "$input_file" "$password" "$size" - mkdir -p "$archive_dir" || { log "ERROR" "Unable to create archive directory"; exit 1; } + mkdir -p "$archive_dir" volumes="$(get_volumes "$input_file" "$size")" archive_name="$(generate_name)" From 34529d337265e1645c395ab38d4d8ab1cece276e Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:21:02 +0000 Subject: [PATCH 36/40] move some things around for improved readability --- modules/create_archive | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/create_archive b/modules/create_archive index b9d00f2..bbb7efe 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -83,20 +83,19 @@ main() { local password="${2:-}" local size="${3:-}" local volumes archive_name archive_dir - archive_dir="$(dirname "$0")/../archives" check_dependencies "7z" check_input "$input_file" "$password" "$size" + archive_name="$(generate_name)" + archive_dir="$(dirname "$0")/../archives" mkdir -p "$archive_dir" volumes="$(get_volumes "$input_file" "$size")" - archive_name="$(generate_name)" - - trap 'cleanup "$archive_name"' ERR INT log "INFO" "Packing '${input_file}' into archive '$archive_name' with password '${password}'" + trap 'cleanup "$archive_name"' ERR INT create_archive \ "$input_file" \ "$password" \ From 9b013d99967e5babdc0dab8994ec7235831531d6 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:31:19 +0000 Subject: [PATCH 37/40] fixed unbound variable error and missing function parameter --- modules/create_archive | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/create_archive b/modules/create_archive index bbb7efe..bbe91fd 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -61,6 +61,7 @@ get_volumes() { generate_name() { # Generates a random archive name of 20 alphanumeric characters + local archive_dir="$1" local archive_name archive_name="$archive_dir/$(tr -dc '[:alnum:]' < /dev/urandom | head -c 20).7z" @@ -73,7 +74,7 @@ create_archive() { local input_file="$1" local password="$2" local volumes="$3" - local archive_name="$5" + local archive_name="$4" 7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}" } @@ -87,10 +88,10 @@ main() { check_dependencies "7z" check_input "$input_file" "$password" "$size" - archive_name="$(generate_name)" archive_dir="$(dirname "$0")/../archives" mkdir -p "$archive_dir" + archive_name="$(generate_name "$archive_dir")" volumes="$(get_volumes "$input_file" "$size")" log "INFO" "Packing '${input_file}' into archive '$archive_name' with password '${password}'" From 665e3568425d9eed2015ec796a6f99a4c2b03823 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:43:41 +0000 Subject: [PATCH 38/40] fixed bug where volumes argument would be set to an invalid value --- modules/create_archive | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/create_archive b/modules/create_archive index bbe91fd..cc9dbed 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -46,15 +46,19 @@ get_volumes() { local input_file="$1" local size="${2:-}" local volumes="" - local smart_size + local smart_size="" if [[ -n "$size" ]]; then log "INFO" "Volumes size is set to ${size}MB" - smart_size="$(calc_smart_volumes "$input_file" "$size" || echo -n)" - volumes="-v${smart_size}m" + smart_size="$(calc_smart_volumes "$input_file" "$size" || true)" fi - [[ -n "$volumes" ]] && log "INFO" "Volumes set to '$volumes'" || log "INFO" "Volumes argument unset" + if [[ -n "$smart_size" ]]; then + volumes="-v${smart_size}m" + log "INFO" "Volumes set to '$volumes'" + else + log "INFO" "Volumes argument unset" + fi echo "$volumes" } From 3e76fc49b06ef126bf54c8c0401142cb28a16704 Mon Sep 17 00:00:00 2001 From: sometimesuseful <> Date: Wed, 13 Nov 2024 15:48:36 +0000 Subject: [PATCH 39/40] added logging for when the input file is smaller than volume size --- modules/create_archive | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/create_archive b/modules/create_archive index cc9dbed..1a2c8e0 100755 --- a/modules/create_archive +++ b/modules/create_archive @@ -32,7 +32,10 @@ calc_smart_volumes() { total_size=$(du -s -BM "${input_file}" | grep -oP '^\d+') || return 1 # If total file size is smaller than volume size, don't pack it into volumes - (( total_size < size )) && return 1 + if (( total_size < size)); then + log "WARN" "$input_file is smaller than ${size}MB, skipping volumes" + return 1 + fi num_volumes=$(( (total_size + size - 1) / size )) smart_size=$(( (total_size + num_volumes - 1) / num_volumes )) From 3f600541ab0ad31bf35f5522afca55c92721f710 Mon Sep 17 00:00:00 2001 From: PedoDeveloper Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH 40/40] Undo test commit --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9d20af2..3a89c54 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,3 @@ Anyone is welcome to collaborate with me. ## Collaborators Currently it is not possible to submit pull requests when using the Tor Browser on the Safest setting. Please do not fork this repo attempting to submit a pull request. Instead leave a comment in [this thread](http://topicgitcoi2s3ohrhkdfxl2ii6ocoysi7d5fstcgatuoqp26b2zldad.onion/PedoDeveloper/autoshare/issues/7) and you will be added as a collaborator - -test commit