Skip to content

Instantly share code, notes, and snippets.

@valentineus
Last active August 23, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valentineus/6d15b98526fdf237b083220dd775fafa to your computer and use it in GitHub Desktop.
Save valentineus/6d15b98526fdf237b083220dd775fafa to your computer and use it in GitHub Desktop.
#!/bin/sh
# Author: Valentin Popov
# Email: info@valentineus.link
# Date: 2017-08-23
# Usage: /bin/sh create_archive.sh /path/to/input /path/to/output
# Description: Packaging applications in the archive.
# Updating the Environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export PATH="$PATH:/usr/local/scripts"
# Define the input directory
if [ "$1" ]; then
INPUT="$(readlink --canonicalize-missing "$1")";
else
echo "No input parameter!";
exit 1;
fi
# Define the output directory
if [ "$2" ]; then
OUTPUT="$(readlink --canonicalize-missing "$2")";
else
echo "No output parameter!";
exit 1;
fi
# List of directories for archiving
for INDEX in "app" "priv-app"
do
# Check for the existence of the source directory
if ! [ -d "$INPUT/$INDEX" ]; then
echo "The /$INDEX directory is missing!";
exit 1;
fi
# Creation of global files
mkdir --parents "$OUTPUT";
touch "$OUTPUT/$INDEX.sha256";
# Archiving the directory
find "$INPUT/$INDEX" -mindepth 1 -maxdepth 1 -type d -print | while read DIRECTOY; do
ARCHIVE="$(basename "$DIRECTOY").7z";
echo "$(date "+%H:%M:%S") In the process of creating /$INDEX/$ARCHIVE...";
7z a -r -ssw -mx=9 "$OUTPUT/$INDEX/$ARCHIVE" "$DIRECTOY" > /dev/null 2>&1;
sha256sum "$OUTPUT/$INDEX/$ARCHIVE" >> "$OUTPUT/$INDEX.sha256";
echo "$(date "+%H:%M:%S") The archive /$INDEX/$ARCHIVE is created.";
done
echo "==================";
echo "Total size of the directory: $(du --max-depth=1 -h "$OUTPUT/$INDEX" | awk '{print $1}')";
echo "Total number of files: $(find "$OUTPUT/$INDEX" -mindepth 1 -maxdepth 1 -type f -print | wc -l)";
echo "==================";
done
# End of work
echo "$(date "+%H:%M:%S") The script has been successfully completed.";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment