Merge branch 'master' of http://onion.tor.my/PedoDeveloper/autoshare
This commit is contained in:
commit
4748def178
1 changed files with 18 additions and 13 deletions
|
|
@ -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 ))
|
||||
|
|
@ -46,21 +49,26 @@ 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"
|
||||
}
|
||||
|
||||
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,8 +81,7 @@ create_archive() {
|
|||
local input_file="$1"
|
||||
local password="$2"
|
||||
local volumes="$3"
|
||||
local size="$4"
|
||||
local archive_name="$5"
|
||||
local archive_name="$4"
|
||||
|
||||
7z a -mhe=on "-p${password}" "$volumes" "$archive_name" "${input_file}"
|
||||
}
|
||||
|
|
@ -84,25 +91,23 @@ 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"
|
||||
|
||||
mkdir -p "$archive_dir" || { log "ERROR" "Unable to create archive directory"; exit 1; }
|
||||
archive_dir="$(dirname "$0")/../archives"
|
||||
mkdir -p "$archive_dir"
|
||||
|
||||
archive_name="$(generate_name "$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" \
|
||||
"$volumes" \
|
||||
"$size" \
|
||||
"$archive_name"
|
||||
|
||||
log "NOTICE" "Archive created"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue