55 lines
1.7 KiB
Bash
55 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
usage() {
|
|
echo "Uso: bash $0 --input=<archivo_entrada> --output=<archivo_salida>"
|
|
exit 1
|
|
}
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Get the current directory path...' '\e[m'
|
|
current_dir=$(pwd)
|
|
|
|
# Check arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--input=*)
|
|
input_file="${1#*=}"
|
|
shift
|
|
;;
|
|
--output=*)
|
|
output_file="${1#*=}"
|
|
shift
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$input_file" ] || [ -z "$output_file" ]; then
|
|
usage
|
|
fi
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Unzip the input file to a temporary directory...' '\e[m'
|
|
temp_dir=$(mktemp -d)
|
|
|
|
tar -xzvf "$input_file" -C "$temp_dir" || echo "Info: some tar failed, but the script will continue."
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Rename files ending in .pacnew...' '\e[m'
|
|
find "$temp_dir" -type f -name "*.pacnew" -exec sh -c 'mv -f "$1" "${1%.pacnew}"' _ {} \;
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Copy the contents of 'x86_64' to the root...' '\e[m'
|
|
rsync -a "$temp_dir/x86_64/" "$temp_dir/"
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Delete the x86_64 directory using doas (requires privileges)...' '\e[m'
|
|
doas rm -rf "$temp_dir/x86_64"
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' "Make $output_file..." '\e[m'
|
|
(cd "$temp_dir" && tar -czvf "$current_dir/$output_file" *)
|
|
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Clean the temporary directory using doas (requires privileges)...' '\e[m'
|
|
doas rm -rf "$temp_dir"
|
|
|
|
echo "The file $output_file has been successfully created! <3"
|