#!/bin/bash

VER='v1.67.0'

script_dir="$(realpath $(dirname $0))"
WORK_DIR="${script_dir}"
cd "${WORK_DIR}/${VER}"

for i in *.zip; do
	NAME="${i%.*}"
	DIR_NAME="${NAME}/"
	TAR_NAME="${NAME}.tar"
	GZIP_NAME="${NAME}.tar.gz"
	BZIP2_NAME="${NAME}.tar.bz2"
	XZ_NAME="${NAME}.tar.xz"

	echo "====================== (Current: ${NAME}) ========================="
	echo "----- (1/6) 'unzip'... -----"
	sudo -u www-data unzip "$i"
	echo "----- (2/6) 'tar -cvf'... -----"
	sudo -u www-data tar -cvf "${TAR_NAME}" "${DIR_NAME}"
	echo "----- (3/6) 'pigz -11 -k -v'... -----"
	sudo -u www-data pigz -11 -k -v "${TAR_NAME}"
	echo "----- (4/6) 'bzip2 -11 -k -v'... -----"
	sudo -u www-data bzip2 -11 -k -v "${TAR_NAME}"
	echo "----- (5/6) 'xz -11 -T0 -k -v'... -----"
	sudo -u www-data xz -11 -T0 -k -v "${TAR_NAME}"
	echo "----- (6/6) 'rm -rf ${DIR_NAME}'... -----"
	sudo -u www-data rm -rfv "${DIR_NAME}"
	echo ''
done
