aboutsummaryrefslogtreecommitdiffstats
path: root/tar_fix.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tar_fix.sh')
-rw-r--r--tar_fix.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/tar_fix.sh b/tar_fix.sh
new file mode 100644
index 0000000..7450d57
--- /dev/null
+++ b/tar_fix.sh
@@ -0,0 +1,54 @@
+#!/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"