#!/bin/bash # set colors for output messages OK="$(tput setaf 2)[OK]$(tput sgr0)" ERROR="$(tput setaf 1)[ERROR]$(tput sgr0)" # Set the name of the log file to include the current date and time SLOG="install-$(date +%d-%H%M%S)_themes.log" # function to extract files with overwrite option extract_files() { local source_dir="$1" # source directory containing files local destination="$2" # destination directory for extraction local extraction_type="$3" # type of extraction: "tar" or "unzip" if [ -d "$source_dir" ]; then echo "extracting files from '$source_dir' to '$destination'..." if [ "$extraction_type" == "tar" ]; then for file in "$source_dir"/*.tar.gz; do if [ -f "$file" ]; then echo "extracting '$file' to '$destination'..." tar -xzf "$file" -C "$destination" --overwrite && echo "$OK extracted '$file' to '$destination'" || echo "$ERROR failed to extract '$file'" fi done elif [ "$extraction_type" == "unzip" ]; then for file in "$source_dir"/*.zip; do if [ -f "$file" ]; then echo "extracting '$file' to '$destination'..." unzip -o -q "$file" -d "$destination" && echo "$OK extracted '$file' to '$destination'" || echo "$ERROR failed to extract '$file'" fi done else echo "${ERROR} invalid extraction type '$extraction_type'" return 1 fi echo "${OK} extraction from '$source_dir' completed" else echo "${ERROR} source directory '$source_dir' does not exist" return 1 fi } # create directories if they don't exist mkdir -p ~/.icons mkdir -p ~/.themes # extract files from 'theme' directory to ~/.themes using tar and log output extract_files "theme" ~/.themes "tar" 2>&1 | tee -a "$SLOG" # extract files from 'icon' directory to ~/.icons using unzip and log output extract_files "icon" ~/.icons "unzip" 2>&1 | tee -a "$SLOG"