+if [ ! -d "$HOME/bin" ]
+then
+ printf "\$HOME/bin does not exist.
+It is required for this script to run.\n"
+
+ exit 1
+fi
+
+cd "$HOME/bin/" || exit 1
+
+if [ "$backups_option" -eq 1 ] && {
+ [ "$minimal" = "-minimal" ] || [ "$extract" -eq 1 ] || [ "$revert_option" -eq 1 ]
+}
+then
+ printf "backups must be the only option\n"
+
+ exit 1
+fi
+
+if [ "$desktop" -eq 1 ] && {
+ [ "$minimal" = "-minimal" ] || [ "$extract" -eq 1 ]
+}
+then
+ printf "desktop must be the only option\n"
+
+ exit 1
+fi
+
+if [ "$backups_option" -eq 1 ]
+then
+ if ! [ "$backups" -gt 0 ] 2> /dev/null
+ then
+ printf "%s is not an integer\n" "$backups"
+
+ exit 1
+ else
+ tmp_file=$(mktemp "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
+ cp "$0" "$tmp_file"
+ sed --in-place "s/^backups=.*/backups=$backups/" "$tmp_file"
+ chmod +x "$tmp_file"
+ mv "$tmp_file" "$0"
+
+ exit 0
+ fi
+fi
+
+if [ "$desktop" -eq 1 ]
+then
+ if [ -f "$HOME/Desktop/geeqie.desktop" ]
+ then
+ printf "Desktop file already exists\n"
+
+ exit 0
+ fi
+
+ file_count=$(find "$HOME/bin/" -name "Geeqie*latest*\.AppImage" -print | wc -l)
+ if [ "$file_count" -eq 0 ]
+ then
+ printf "No AppImages have been downloaded\n"
+
+ exit 1
+ fi
+
+ tmp_dir=$(mktemp --directory "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
+ cd "$tmp_dir" || exit 1
+
+ app=$(find "$HOME/bin/" -name "Geeqie*latest*\.AppImage" -print | sort --reverse | head -1)
+ $app --appimage-extract "usr/local/share/applications/geeqie.desktop"
+ $app --appimage-extract "usr/local/share/pixmaps/geeqie.png"
+ xdg-desktop-icon install --novendor "squashfs-root/usr/local/share/applications/geeqie.desktop"
+ xdg-icon-resource install --novendor --size 48 "squashfs-root/usr/local/share/pixmaps/geeqie.png"
+ xdg-desktop-menu install --novendor "squashfs-root/usr/local/share/applications/geeqie.desktop"
+ rm --recursive --force "$tmp_dir"
+
+ exit 0
+fi
+
+if [ "$revert_option" -eq 1 ]
+then
+ if ! [ "$revert" -gt 0 ] 2> /dev/null
+ then
+ printf "%s is not an integer\n" "$revert"
+
+ exit 1
+ else
+ if ! [ -f "$HOME/bin/Geeqie$minimal-latest-$architecture.AppImage.$revert" ]
+ then
+ printf "Backup $HOME/bin/Geeqie%s-latest-$architecture.AppImage.%s does not exist\n" "$minimal" "$revert"
+
+ exit 1
+ fi
+
+ if [ "$extract" -eq 1 ]
+ then
+ rm --recursive --force "Geeqie$minimal-latest-$architecture-AppImage"
+ mkdir "Geeqie$minimal-latest-$architecture-AppImage"
+ cd "Geeqie$minimal-latest-$architecture-AppImage" || exit 1
+
+ printf "Extracting AppImage\n"
+ ../"Geeqie$minimal-latest-$architecture.AppImage.$revert" --appimage-extract | cut --characters 1-50 | tr '\n' '\r'
+ printf "\nExtraction complete\n"
+
+ cd ..
+ ln --symbolic --force "./Geeqie$minimal-latest-$architecture-AppImage/squashfs-root/AppRun" geeqie
+ else
+ ln --symbolic --force "$HOME/bin/Geeqie$minimal-latest-$architecture.AppImage.$revert" geeqie
+ fi
+
+ exit 0
+ fi
+fi