Last active
September 27, 2017 15:58
-
-
Save georgy7/de2a0bf9e130ac4c36f2a0a3f7d5c523 to your computer and use it in GitHub Desktop.
It's like a resource builder. Or the simplest tar alternative ever. If you do not want to bloat your demo executable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Сверхупрощенная (в плане разбора) замена TAR.GZ. | |
# Первая строка - кол-во файлов (N). | |
# Следующие N строк - названия и размеры файлов через TAB. | |
# Дальше файлы идут подряд. | |
FILES_TO_CONCATENATE=( | |
"file1.bmp" | |
"file2.txt" | |
"file3.raw" | |
"file with spaces in name.txt" | |
) | |
LEGEND_FILE=legend.tsv | |
CONCATENATED_BUILD=concatenated.bin | |
BUILD=concatenated.gz | |
if [ -f $LEGEND_FILE ] ; then | |
rm $LEGEND_FILE | |
fi | |
echo ${#FILES_TO_CONCATENATE[@]} > $CONCATENATED_BUILD | |
catCommand="cat $LEGEND_FILE " | |
for filename in "${FILES_TO_CONCATENATE[@]}" | |
do | |
size=$(wc -c < "$filename") | |
escapesFn=$(printf %q "$filename") | |
echo -n $filename >> $LEGEND_FILE | |
echo -n -e '\t' >> $LEGEND_FILE | |
echo $size >> $LEGEND_FILE | |
catCommand+="$escapesFn" | |
catCommand+=' ' | |
done | |
echo | |
echo $catCommand | |
echo | |
eval $catCommand >> $CONCATENATED_BUILD | |
gzip -c --best $CONCATENATED_BUILD > $BUILD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment