#!/bin/dash
## Supported shells: dash, bash, zsh, ksh
GetOSType () {
#$1 = returns the type of the current operating system:
if [ -n "$1" ]; then
case "$(uname -s)" in
*"Linux"* )
eval $1="Linux"
;;
*"Darwin"* | *"BSD"* )
eval $1="BSD-based"
;;
* )
eval $1="Other"
;;
esac
else
{
printf '%s\n' 'ERROR: GetOSType: Expected 1 parameter!'
printf '%s\n' 'Press Enter to exit...';
RestoreSettings; read temp; exit_code="1"
}>&2
fi
}
GetCurrentShell () {
#$1 = returns the <current shell name>
#$1 = returns the <current shell full path>
if [ -n "$BASH_VERSION" ]; then current_shell_name="bash";
elif [ -n "$ZSH_VERSION" ]; then current_shell_name="zsh";
elif [ -n "$KSH_VERSION" ]; then current_shell_name="ksh";
elif [ "$PS1" = '$ ' ]; then current_shell_name="dash";
else current_shell_name="dash"; #default shell
fi
current_shell_full_path="$(which "$current_shell_name")"
eval $1=\"\$current_shell_name\"
eval $2=\"\$current_shell_full_path\"
}
GetTerminalEmulatorPlusLaunchFlagLinux () {
#Returns <terminal_emulator> and <terminal_emulator_plus_launch_flag> in Linux:
terminal_emulator_raw="$(ps -o comm= -p "$(($(ps -o ppid= -p "$(($(ps -o sid= -p "$$")))")))")"
if [ ! "${terminal_emulator_raw#*"tmux"*}" = "$terminal_emulator_raw" ]; then
msg="$(tmux display-message -p "#{client_pid}")"
terminal_emulator_raw="$(ps -o comm= -p "$(($(ps -o ppid= -p "$(($(ps -o sid= -p "$msg")))")))")"
fi
terminal_emulator="${terminal_emulator_raw%"-"}"
if [ "$terminal_emulator" = "gnome-console" ] || [ "$terminal_emulator" = "gnome-terminal" ]; then
terminal_emulator_plus_launch_flag="\"$terminal_emulator\" --"
elif [ "$terminal_emulator" = "lxterminal" ] || [ "$terminal_emulator" = "qterminal" ]; then
#For LXDE and LXQt for example: the shell can be called directly (no terminal emulator needed):
terminal_emulator_plus_launch_flag=""
else
terminal_emulator_plus_launch_flag="\"$terminal_emulator\" -e"
fi
}
CheckCreateMainDirs () {
#Check for the existence of temporary directories (used for extracting [office document / archive / pdf/htm] files) and creates them if needed:
output_dir=""
error="false"
{
[ -n "$TEMPORARY_EXTRACT_PATH" ] && cd "$TEMPORARY_EXTRACT_PATH" && {
output_dir="$PWD"
if [ ! -e 'TEMP_EXTR_FOLDER' ]; then
mkdir 'TEMP_EXTR_FOLDER' || error="true"
fi
cd 'TEMP_EXTR_FOLDER' || {
error="true"
}
} || error="true"
} 2>/dev/null
if [ "$error" = "true" ]; then
printf '%s\n' "Error: Could not access temporary folder \"TEMP_EXTR_FOLDER\" in the extract location: \"$TEMPORARY_EXTRACT_PATH\"!"
printf '%s\n' "Press Enter to exit..."; RestoreSettings; read temp; exit 1
fi>&2
}
PrintDesktopFile1 () {
#Prints a .desktop file for handling parameters added for compare with Open With in Linux:
cat<<EOF
[Desktop Entry]
Name=File Comparer
Comment=Compares [ folders/files / office/pdf documents / archives ]
TryExec=$terminal_emulator
Exec=$terminal_emulator_plus_launch_flag "$current_shell_full_path" "$current_script_path" %U
Terminal=$1
Type=Application
Icon=utilities-terminal
Categories=Utility;
MimeType=inode/directory;application/zip;application/x-rar-compressed;application/x-7z-compressed;text/plain;application/x-tar;application/x-gtar;application/x-gzip;application/x-bzip2;application/x-xz;application/x-compressed-tar;application/x-bzip-compressed-tar;application/x-tar-bz2;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.presentation;application/pdf
EOF
}
PrintDesktopFile2 () {
#Prints a .desktop file for handling parameters added for compare with Open With in Linux - in incognito mode (i.e. a temporary session where parameters added for compare are stored only for the current temporary session):
cat<<EOF
[Desktop Entry]
Name=File Comparer (Incognito)
Comment=Compares [ folders/files / office/pdf documents / archives ] in Incognito Mode
TryExec=$terminal_emulator
Exec=$terminal_emulator_plus_launch_flag "$current_shell_full_path" "$current_script_path" --incognito %U
Terminal=$1
Type=Application
Icon=utilities-terminal
Categories=Utility;
MimeType=inode/directory;application/zip;application/x-rar-compressed;application/x-7z-compressed;text/plain;application/x-tar;application/x-gtar;application/x-gzip;application/x-bzip2;application/x-xz;application/x-compressed-tar;application/x-bzip-compressed-tar;application/x-tar-bz2;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.presentation;application/pdf
EOF
}
ExtractFirstAndLastPathComponent () {
#$1 = input path
#$2 = returns the first path component
#$3 = returns the last path component
eval current_path="\"\$$1\""
first_path_component=""
last_path_component=""
if [ -n "$current_path" ]; then
#Remove trailing '/' characters:
while [ ! "${current_path%"/"}" = "$current_path" ]; do
current_path="${current_path%"/"}"
done
if [ -z "$current_path" ]; then
eval current_path=\"\$$1\"
fi
last_path_component="${current_path##*"/"}"
first_path_component="${current_path%"$last_path_component"}"
fi
eval $2="\"\$first_path_component\""
eval $3="\"\$last_path_component\""
}
CheckFilesFoldersToCompare () {
#Checks if the <files and folders> to compare exist and are accessible:
if [ -z "$files_folders_to_compare" ]; then
printf '%s\n' "Please add files/folders to the comparison queue first!"
exit_code=1
else
error="false"
IFS='
'
count="0"
for file in $(cat "$stored_file_paths_file_path" 2>/dev/null); do
count=$(($count + 1))
if [ ! -e "$file" ] || [ ! -r "$file" ]; then
printf '%s\n' "ERROR: Param [$count] does not exist or is not readable!">&2
error="true"
fi
done
unset IFS
if [ "$error" = "true" ]; then
printf '\n%s\n\n' "Please: Try to readd files and compare them afterwards...">&2
exit_code=1
fi
fi
}
ExtractFileIfArchive () {
#Output:
#
#output1 = contains the escaped archive file path (and is printed to <standard output>)
#fileEFIA_extracted = contains :
# - the extracted temporary output path after extracting the archive in case of an [office document/archive] or [pdf/htm] file
# - the current path in case of regular file type (file/folder) (for extracting plain text)
eval fileEFIA=\"\$$1\"
if [ -z "$first_time" ]; then cat '/dev/null'>"$stored_file_paths_file_path"; first_time="defined"; fi
case "$fileEFIA" in
*'.zip' | *'.odt' | *'.ods' | *'.odp' | *'.docx' | *.'xlsx' | *'.pptx' | *'.ppsx' | \
*'.7z' | *'.rar' | *'.pdf' | *'.htm' | *'.html' | \
*'.tar.'* | *'.bz2' | *'.xz' | *'.gz' | *'.tgz' | *'.tar' | \
'/dev/null' )
error="false"
case "$fileEFIA" in
*'.pdf' )
CheckUtilitiesAndBuildMessage --warning pdftotext pdftohtml
if [ "$warning" = "true" ]; then ShowMessageDialog message; fi
;;
esac
if [ "$error" = "false" ]; then
ExtractArchive fileEFIA fileEFIA_extracted
output1="$(printf '%s' "$fileEFIA_extracted"|sed "s/'/$Q\"\$Q\"$Q/g")"
printf "'%s' " "$output1"
fi
;;
* )
output1="$(printf '%s' "$fileEFIA"|sed "s/'/$Q\"\$Q\"$Q/g")"
printf "'%s' " "$output1"
fileEFIA_extracted="$fileEFIA"
;;
esac
printf '%s\n' "$fileEFIA_extracted">>"$stored_file_paths_file_path"
}
ExtractArchive () {
#$1 = the input file/folder path of the [ office document / archive / pdf/htm file ] / [ regular file/folder ] to be "extracted"
#$2 = an ouput variable containing:
# - the extracted temporary output path after extracting the archive in case of an [office document/archive] or [pdf/htm] file
# - the current path in case of regular file type (file/folder) (for extracting plain text)
eval current_archive_path="\"\$$1\""
if [ "$current_archive_path" = '/dev/null' ]; then
{
cd "$output_dir" || error="true"
if [ "$found_dir" = "true" ]; then
mkdir "null"
cd "null" || error="true"
full_current_archive_extract_to_path="$output_dir/null"
else
full_current_archive_extract_to_path="/dev/null"
fi
##cat /dev/null>"$full_current_archive_extract_to_path""/""temp.links.txt" || error="true"
} 2>/dev/null
if [ "$error" = "true" ]; then
printf '%s\n' "ERROR: Could not create/access <output> directory structure!"
printf '%s\n' "Press Enter to exit..."
RestoreSettings; read temp; kill $$
fi>&2
else
full_current_archive_path="$current_archive_path"
ExtractFirstAndLastPathComponent current_archive_path fpc_current_archive_path lpc_current_archive_path
cd "$fpc_current_archive_path"
fpc_current_archive_path="$PWD"
ExtractFirstAndLastPathComponent fpc_current_archive_path fpc_fpc_current_archive_path lpc_fpc_current_archive_path
current_archive_name_ext="${lpc_current_archive_path}"
if [ ! -d "$current_archive_path" ]; then
current_archive_name_ext_plus="$current_archive_name_ext""_extract"
else
current_archive_name_ext_plus="$current_archive_name_ext"
fi
full_current_archive_extract_to_path="$output_dir/"'TEMP_EXTR_FOLDER'"/$lpc_fpc_current_archive_path/$current_archive_name_ext_plus"
if [ ! -e "$full_current_archive_extract_to_path" ]; then
{
error="false"
cd "$output_dir/"'TEMP_EXTR_FOLDER' || error="true"
mkdir "$lpc_fpc_current_archive_path"; cd "$lpc_fpc_current_archive_path" || error="true"
mkdir "$current_archive_name_ext_plus"; cd "$current_archive_name_ext_plus" || error="true"
} 2>/dev/null
if [ "$error" = "true" ]; then
printf '%s\n' "ERROR: Could not create/access <output> directory structure!"
printf '%s\n' "Press Enter to exit..."
RestoreSettings; read temp; kill $$
fi>&2
case "$current_archive_path" in
*'.zip' | *'.odt' | *'.ods' | *'.odp' | *'.docx' | *.'xlsx' | *'.pptx' | *'.ppsx' )
unzip "$full_current_archive_path" -d "$full_current_archive_extract_to_path"
;;
*'.7z' )
7z x "$full_current_archive_path" -o"$full_current_archive_extract_to_path/"
;;
*'.rar' )
unrar x "$full_current_archive_path" "$full_current_archive_extract_to_path/"
;;
*'.pdf' )
pdftotext "$full_current_archive_path" "$full_current_archive_extract_to_path""/""temp.text.txt"
pdftohtml "$full_current_archive_path" "$full_current_archive_extract_to_path""/""temp.html"
{ cat "$full_current_archive_extract_to_path""/"*; }|ExtractURIsFromText --pipe>>"$full_current_archive_extract_to_path""/""temp.links.txt"
;;
*'.htm' | *'.html' )
cp "$full_current_archive_path" "$full_current_archive_extract_to_path""/""temp.html"
{ cat "$full_current_archive_extract_to_path""/"*; }|ExtractURIsFromText --pipe>>"$full_current_archive_extract_to_path""/""temp.links.txt"
;;
*'.tar.bz2' )
tar -xvjf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
;;
*'.tar.xz' )
tar -xvJf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
;;
*'.tar.gz' | *'.tgz' )
tar -xvzf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
;;
*'.tar' )
tar -xvf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
;;
*'.bz2' | *'.xz' | *'.gz' )
cp "$full_current_archive_path" "$full_current_archive_extract_to_path"
case "$current_archive_path" in
*'.bz2' ) bzip2 "$full_current_archive_extract_to_path/""$current_archive_name_ext" -d "$full_current_archive_extract_to_path"; ;;
*'.xz' ) xz "$full_current_archive_extract_to_path/""$current_archive_name_ext" -d "$full_current_archive_extract_to_path"; ;;
*'.gz' ) gzip -d "$full_current_archive_extract_to_path/""$current_archive_name_ext"; ;;
esac
case "${current_archive_name_ext%"."*}" in
*'.tar' )
tar -xvf "$full_current_archive_extract_to_path/${current_archive_name_ext%"."*}" -C "$full_current_archive_extract_to_path"
#rm "$full_current_archive_extract_to_path/${current_archive_name_ext%"."*}"
rm "$output_dir""/"'TEMP_EXTR_FOLDER'"/""${current_archive_name_ext%"."*}" #WARNING: EDIT WITH CAUTION!!!
;;
esac
;;
esac >/dev/null 2>/dev/null
else
cd "$full_current_archive_extract_to_path"
fi
fi
eval $2=\"\$full_current_archive_extract_to_path\"
}
PrintJustInTitle () {
#Changes the terminal emulator window title to: $1 (survives output redirection):
printf "\033]0;$1\007">"$print_to_screen"
}
ShowMessageDialog () {
#Displays a warning dialog message (using the 'zenity' GUI) containing the text in the <message> variable:
eval message="\"\$$1\""
zenity --warning --text="$message" --no-wrap
}
CheckUtilitiesAndBuildMessage () {
#Check if any of the necessary utilities is missing:
message=""
msg_type="warning"; msg_prefix="WARNING"
warning="false"
if [ "$1" = '--warning' ]; then
shift
elif [ "$1" = '--warning-message' ]; then
eval message="\"\$$2\""
shift; shift
else
msg_type="error"; msg_prefix="ERROR"
error="false"
fi
warning_all="false"; error_all="false"
error_or_warning_count="0"
for utility; do
which $utility >/dev/null 2>/dev/null || {
error_or_warning_count=$(($error_or_warning_count + 1))
if [ -z "$message" ]; then
message="$msg_prefix: the '$utility'"
else
message="$message"", '$utility'"
fi
eval $msg_type="\"true\""
eval $msg_type\_all="\"true\""
}
done
if [ "$warning_all" = "true" ] || [ "$error_all" = "true" ]; then
if [ "$error_or_warning_count" = "1" ]; then
message="$message"" utility is not installed!"
elif [ "$error_or_warning_count" -gt "1" ]; then
message="$message"" utilities are not installed!"
fi
fi
if [ "$error" = "true" ]; then RestoreSettings; fi
}
RestoreSettings () {
#Restores the initial IFS and directory (to their original value - that they had before running the script):
IFS="$initial_IFS"
cd "$initial_dir"
}
ExtractURIsFromText () {
START_REC_SEQ='_@_@_@_1_2_3_'
END_REC_SEQ='_3_2_1_@_@_@_'
NON_EOL_CHARS='[^[:blank:]^>^<]*'
scheme_match='([a-zA-Z]+[0-9\-]*\:\/\/){1}'
domain_match='((([a-zA-Z]+[0-9\-]*)+(\.[a-zA-Z]+[0-9\-]*)+)+)'
keep_lines_not_containing_an_URI='sed -E '"'"'/^'"$START_REC_SEQ""$scheme_match""$domain_match""$NON_EOL_CHARS""$END_REC_SEQ"'$/d'"'"
delete_lines_not_containing_an_URI='sed -E '"'"'/^'"$START_REC_SEQ""$scheme_match""$domain_match""$NON_EOL_CHARS""$END_REC_SEQ"'$/!d'"'"
sed_command1='sed -E '"'"'s/^('"$scheme_match""$domain_match""$NON_EOL_CHARS"')$/'"$START_REC_SEQ"'\1'"$END_REC_SEQ"'/g'"'"
sed_command2='sed -E '"'"'s/('"$scheme_match""$domain_match""$NON_EOL_CHARS"')(.*)/'"${NL}"'\1'"${NL}"'\7/g'"'"
stored_results1=""; stored_results2=""
if [ "$1" = "--pipe" ]; then
stored_results1="$(while IFS= read -r line; do printf '%s\n' "$line"; done;)"
else
stored_results1="$(find "${@}" -type f -exec cat '{}' \;)"
fi
current_list_0="0"; cc="0"; var=""; found_links="true"
stored_results_all="$stored_results1"
while [ "$found_links" = "true" ]; do
stored_results2="$(printf '%s' "$stored_results1"|eval "$sed_command1")"
if [ ! "$stored_results2" = "$stored_results1" ]; then
var="$(printf '%s' "$stored_results2"|eval $delete_lines_not_containing_an_URI)"
if [ -n "$var" ]; then
found_links="true"
stored_results1="$(printf '%s' "$stored_results2"|eval $keep_lines_not_containing_an_URI)"
else
found_links="false"
fi
else
stored_results1="$(printf '%s' "$stored_results2"|eval "$sed_command2")"
if [ ! "$stored_results1" = "$stored_results2" ]; then
found_links="true"
else
found_links="false"
fi
fi
stored_results_all="$(printf '%s' "$stored_results_all"|eval "$sed_command2")"
done
stored_results_all="$(printf '%s' "$stored_results_all"|eval "$sed_command1")"
current_list="$(printf '%s' "$stored_results_all"|eval $delete_lines_not_containing_an_URI)"
printf "%s\n" "$current_list"|sed -E 's/'"$START_REC_SEQ"'(.*)'"$END_REC_SEQ"'/\1/g'
}
GenerateSequence () {
#Prints the sequence of numbers $1 .. $2 <-> if $1 value < $2 value:
sequence_start=$(($1))
sequence_end=$(($2))
if [ "$sequence_start" -le "$sequence_end" ]; then
seq $sequence_start $sequence_end
fi
}
Commands that might be useful:
soffice - for Office Documents - for example: convert an Office Document to a HTML Document:
soffice --headless --convert-to html <office_document_FULL_PATH> --outdir <OUTPUT_DIR_PATH>>
pdftohtml - for converting PDF Documents to HTML Documents (-i = skip image files):
pdftohtml -i <pdf_document>
- filter results - print lines containing string (highlight):
...|grep "string"
- filter results - print lines not containing string:
...|grep -v "string"
- filter results - print lines containing: string1 OR string2 OR ... stringN:
...|awk '/string1|string2|...|stringN/'
- filter results - print lines not containing: string1 OR string2 OR ... stringN:
...|awk '!/string1|string2|...|stringN/'
- filter results - print columns <1> and <2> from output:
...|awk '{print $1, $2}'
- filter results (-F = Fixed string) - print lines in '/file/path/2' that are in '/file/path/1':
grep -F -f '/file/path/1' '/file/path/2'
- filter results (-F = Fixed string) - print lines in '/file/path/2' that are not in '/file/path/1':
grep -F -vf '/file/path/1' '/file/path/2'
- group results by uniqueness - print lines that are unique:
...|sort|uniq -u
- group results by uniqueness - print lines that are duplicate:
...|sort|uniq -d
- group results by uniqueness - print lines, grouping common lines (print count in front of each line):
...|sort|uniq -c
- sort results by column <N> (replace <N> with a number (1..)):
...|sort -k <N>
- sort results by column <N> (replace <N> with a number (1..)) - as numeric sort (-n) in reversed order (-r):
...|sort -k <N> -n -r
print_to_screen='/dev/tty'
{
set +f #Enable globbing (POSIX compliant)
setopt no_nomatch 2>/dev/null #Enable globbing (zsh)
CLEANUP_EXTRACTED_FILES_ON_NEW_SESSION="true" #Set this variable to "false" in order to keep the temporary EXTRACTED [ARCHIVES]/[PDF]/[HTML] FILES in the output_folder - after a compare session
Q="'"
initial_IFS="$IFS"
GetOSType OS_TYPE
cd "${0%/}" 2>/dev/null
current_script_path="$(pwd -P)/${0##/}"
GetCurrentShell current_shell_name current_shell_full_path
APPS_DESKTOP_FILES_FOLDER="$HOME/.local/share/applications" #(for Linux) this is the default location for .desktop files (should not be changed)
if [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ]; then
if [ -e '/dev/shm' ]; then
TEMPORARY_EXTRACT_PATH='/dev/shm'
elif [ -e "$HOME" ]; then
TEMPORARY_EXTRACT_PATH="$HOME"
else
printf '%s\n' "Please provide TEMPORARY EXTRACT PATH: ">&2
read TEMPORARY_EXTRACT_PATH
fi
elif [ "$OS_TYPE" = "BSD-based" ] && [ -e "$HOME" ]; then
TEMPORARY_EXTRACT_PATH="$HOME"
else
printf '%s\n' "Please provide TEMPORARY EXTRACT PATH: "
read TEMPORARY_EXTRACT_PATH
fi
TEMPORARY_EXTRACT_FOLDER='TEMP_EXTR_FOLDER' # HARDCODED STRING (SHOULD NOT BE CHANGED)
CheckCreateMainDirs
desktop_file_name_ext1="FileComparerScript.desktop" #can be changed
desktop_file_path1="$APPS_DESKTOP_FILES_FOLDER""/""$desktop_file_name_ext1"
desktop_file_name_ext2="FileComparerScriptIncognito.desktop" #can be changed
desktop_file_path2="$APPS_DESKTOP_FILES_FOLDER""/""$desktop_file_name_ext2"
stored_file_paths_file_parent_dir_path="$APPS_DESKTOP_FILES_FOLDER" #can be changed
if [ ! -e "$stored_file_paths_file_parent_dir_path" ]; then
stored_file_paths_file_parent_dir_path="$HOME" #can be changed
fi
stored_file_paths_file_path="$stored_file_paths_file_parent_dir_path""/"'FileComparerScriptSettings.txt'
incognito_stored_file_paths_file_path="$stored_file_paths_file_parent_dir_path""/"'FileComparerScriptSettingsIncognito.txt'
temp_compared_status_file="$stored_file_paths_file_parent_dir_path""/"'temp_compared_status_file.txt'
temp_to_be_reset_status_file="$stored_file_paths_file_parent_dir_path""/""temp_to_be_reset.txt"
#Store New Line for use with sed:
if [ "$OS_TYPE" = "Linux" ]; then
NL=$(printf '%s' "\n")
elif [ "$OS_TYPE" = "BSD-based" ]; then
#NL=$(printf "\n")
NL="\
"
fi
#Set default File Comparer:
if [ "$OS_TYPE" = "Linux" ]; then
compare_app="meld" #Linux
elif [ "$OS_TYPE" = "BSD-based" ]; then
compare_app="ksdiff" #(=call Kaleidoscope from the commandline) #macOS
which $compare_app >/dev/null 2>/dev/null || {
compare_app="opendiff" #(=call FileMerge from the commandline) #macOS
}
fi
exit_code=0
if [ "$1" = "--install" ]; then
IFS='
'
if [ "$OS_TYPE" = "Linux" ]; then
error="false"
CheckUtilitiesAndBuildMessage grep update-desktop-database cat ps
if [ "$error" = "true" ]; then message="INSTALL: ""$message"; ShowMessageDialog message; exit 1; fi
cat '/dev/null'>"$desktop_file_path1"
cat '/dev/null'>"$desktop_file_path2"
GetTerminalEmulatorPlusLaunchFlagLinux
#terminal_visible=false/true <=> not show / show: the initial launcher app (terminal) window
#for LXDE and LXQt Desktop Environments: use "true"; otherwise: use "false"
if [ -z "$terminal_emulator_plus_launch_flag" ]; then
terminal_visible="true"
else
terminal_visible="false"
fi
PrintDesktopFile1 $terminal_visible>"$desktop_file_path1"
PrintDesktopFile2 $terminal_visible>"$desktop_file_path2"
# Update the database (cache file) of desktop entries (for the Open With Menu):
update-desktop-database "$APPS_DESKTOP_FILES_FOLDER" || { error="true"; }
# Update the Favorite (Dock) Icons List:
#BUG:# favorite_icons_list=$(dconf read /org/gnome/shell/favorite-apps 2>/dev/null) || { error="true"; }
favorite_icons_list=$(gsettings get org.gnome.shell favorite-apps 2>/dev/null) || { error="true"; }
printf '%s' "$favorite_icons_list"|grep -F "$desktop_file_name_ext1">/dev/null || {
#BUG:# dconf write /org/gnome/shell/favorite-apps "${favorite_icons_list%"]"}"", ""'$desktop_file_name_ext1'""]"
gsettings set org.gnome.shell favorite-apps "${favorite_icons_list%"]"}"", ""'$desktop_file_name_ext1'""]"
} 2>/dev/null || { error="true"; }
if [ "$error" = "true" ]; then
printf '\n%s\n\n' "ERROR: Install encountered errors.">&2
else
printf '\n%s\n' "Installed as '$desktop_file_name_ext1' in the Desktop Favorite Apps Ribbon (Dock)."
printf '\n%s\n' "Installed as '$desktop_file_name_ext1', '$desktop_file_name_ext2' in the '$APPS_DESKTOP_FILES_FOLDER' folder."
printf "\n"
fi
else
printf '\n%s\n\n' "ERROR: Currently, install is implemented only for the Linux operating systems!">&2
fi
fi
if [ -z "$1" ]; then
printf '%s\n' "true">"$temp_to_be_reset_status_file"
fi
if [ ! "$1" = "--install" ]; then
CheckUtilitiesAndBuildMessage mkdir cat kill unzip tar cp
if [ "$error" = "true" ]; then ShowMessageDialog message; exit 1; fi
initial_dir="$PWD"
if [ ! -e "$temp_to_be_reset_status_file" ]; then
cat '/dev/null'>"$temp_to_be_reset_status_file"
fi
cd "$initial_dir"
if [ ! -e "$stored_file_paths_file_path" ]; then
cat '/dev/null'>"$stored_file_paths_file_path"
fi
PrintJustInTitle "File Comparer"
if [ ! "${#@}" = "0" ]; then
if [ "$1" = "--incognito" ]; then
shift;
stored_file_paths_file_path="$incognito_stored_file_paths_file_path"
fi
#######
if [ -z "$(cat "$temp_compared_status_file" 2>/dev/null)" ]; then
printf '%s\n' "compared">"$temp_compared_status_file" 2>/dev/null
else
cat '/dev/null'>"$temp_compared_status_file" 2>/dev/null
fi
if [ "$(cat "$temp_to_be_reset_status_file" 2>/dev/null)" = "true" ]; then
cat '/dev/null'>"$stored_file_paths_file_path"
cat '/dev/null'>"$incognito_stored_file_paths_file_path"
printf '%s\n' "false">"$temp_to_be_reset_status_file"
if [ -n "$TEMPORARY_EXTRACT_PATH" ] && [ -n "$output_dir" ]; then
if [ "$CLEANUP_EXTRACTED_FILES_ON_NEW_SESSION" = "true" ]; then
rm -R -f "$output_dir""/"'TEMP_EXTR_FOLDER'"/"* #WARNING: EDIT WITH CAUTION!!!
fi
fi
fi
#######
for file; do
if [ "$file" = "" ]; then
file="/dev/null"
fi
printf '%s\n' "Loading file: '$file'..."
files_folders_to_compare=$( \
IFS='
';
for current_file in $(cat "$stored_file_paths_file_path" 2>/dev/null); do
ExtractFileIfArchive current_file;
done;
ExtractFileIfArchive file;
);
done
else
if [ -e "$incognito_stored_file_paths_file_path" ] && [ -n "$(cat "$incognito_stored_file_paths_file_path" 2>/dev/null)" ]; then
stored_file_paths_file_path="$incognito_stored_file_paths_file_path"
fi
error="false"
IFS='
';
count="0"
found_dir="false"
for current_file in $(cat "$stored_file_paths_file_path" 2>/dev/null); do
count=$(($count + 1))
printf '%s\n' "Param [$count]: "$current_file""
if [ -d "$current_file" ]; then found_dir="true"; fi
done
if [ "$count" = "1" ]; then
current_file='/dev/null'
printf '%s\n' "Param [$(($count + 1))]: "$current_file""
fi
count2="0"
for current_file in $(cat "$stored_file_paths_file_path" 2>/dev/null); do
count2=$(($count2 + 1))
if [ ! -e "$current_file" ]; then
printf '%s\n' "ERROR: Param [$count2] is not accessible! (POSSIBLE FIX: Try readding files)">&2
error="true";
fi
done
if [ "$error" = "true" ]; then
RestoreSettings; read temp; exit 1
else
files_folders_to_compare=$( \
IFS='
';
for current_file in $(cat "$stored_file_paths_file_path" 2>/dev/null); do
ExtractFileIfArchive current_file;
done;
if [ "$count" = "1" ]; then current_file='/dev/null'; ExtractFileIfArchive current_file; fi;
);
fi
IFS='
'
CheckFilesFoldersToCompare
if [ "$exit_code" = "0" ]; then
printf '%s\n' "compared">"$temp_compared_status_file"
IFS='
'
eval "$compare_app" $files_folders_to_compare||{
printf '%s\n' "ERROR: $compare_app (see above)"
printf '%s\n' "Press Enter to exit...";
RestoreSettings; read temp; exit_code="1"
}>&2
else
RestoreSettings; read temp; exit_code="1"
fi
if [ -e "$incognito_stored_file_paths_file_path" ] && [ -n "$(cat "$incognito_stored_file_paths_file_path" 2>/dev/null)" ]; then
cat '/dev/null'>"$incognito_stored_file_paths_file_path"
fi
fi
fi
IFS="$initial_IFS"
exit $exit_code
}>"$print_to_screen"