#!/usr/bin/env bash

APP=SAMPLE
rm -f ./rollback-args ./AM-rollback
URL=WEBPAGE-CONTAINING-URLS
SITE=MAIN-DOMAIN-OR-SITE
printf "%s\n" $(curl -Ls $URL | grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | grep -i appimage) >> "./rollback-args" &&
echo -e "-----------------------------------------------------------------------\nYou have chosen to roll back $APP.\nRollback will be done from $SITE\n-----------------------------------------------------------------------"
printf "Select a URL from this menu (read carefully) or press CTRL+C to abort:\n-----------------------------------------------------------------------\n"; sleep 1;
select d in $(cat "./rollback-args"); do test -n "$d" && break; echo ">>> Invalid Selection"; done
cp ./AM-updater ./AM-rollback
sed -i 's/version0/#version0/g' ./AM-rollback
sed -i '/show-progress/c\wget -q --show-progress '$d'' ./AM-rollback
./AM-rollback
rm -f ./version
echo $d >> ./version
rm -f ./rollback-args ./AM-rollback
echo -e "\nROLLBACK SUCCESSFUL!"
exit