fant0men

Game uninstaller script

Apr 6th, 2020
453
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This script will serve as an uninstaller for an id Software games collection.
  3.  
  4. script=$(readlink -f "$0")
  5.  
  6. userid_script=$(whoami)
  7. distro='0'
  8. userid_install='0'
  9. home_dir='0'
  10. bin_dir='0'
  11. install_dir='0'
  12. start_script_f='0'
  13. uninstall_list_f='0'
  14. deb_dir='0'
  15.  
  16. if [[ $userid_script != 'root' ]]; then
  17.     cat <<USER_ID
  18.  
  19. You need root priviliges to run this uninstaller!
  20. Run the script like this: sudo ${script}
  21.  
  22. USER_ID
  23.  
  24.     exit
  25. fi
  26.  
  27. get_distro () {
  28.     cat <<GET_DISTRO
  29.  
  30. Are you running a DEB-based or RPM-based Linux distribution?
  31. If neither, just choose 'Abort' and create the symlinks yourself manually.
  32.  
  33. GET_DISTRO
  34.  
  35.     until [[ $distro == 'deb' || $distro == 'rpm' ]]; do
  36.         clear
  37.  
  38.         cat <<CHOOSE_DISTRO
  39.  
  40. Choose your distribution type:
  41.  
  42. 1) DEB-based (Ubuntu, Mint, Debian etc.)
  43. 2) RPM-based (Fedora, CentOS, Red Hat etc.)
  44. 3) Abort
  45.  
  46. CHOOSE_DISTRO
  47.  
  48.         printf '>'
  49.         read distro_type
  50.  
  51.         case "$distro_type" in
  52.             1)
  53.                 distro='deb'
  54.             ;;
  55.             2)
  56.                 distro='rpm'
  57.             ;;
  58.             3)
  59.                 exit
  60.             ;;
  61.         esac
  62.     done
  63. }
  64.  
  65. get_userid_install () {
  66.     yesno='0'
  67.     regex_home_dir='^[0-9]+$'
  68.  
  69.     mapfile -t home_dir_list < <(find /home -type d -maxdepth 1 -iname "*" | tail -n +2)
  70.  
  71.     until [[ $yesno == 'yes' ]]; do
  72.         clear
  73.  
  74.         n='0'
  75.  
  76.         echo -e "\nChoose your home directory:\n"
  77.  
  78.         for (( i = 0; i < ${#home_dir_list[@]}; i++ )); do
  79.             n=$(( n + 1 ))
  80.  
  81.             echo "${n}) ${home_dir_list[${i}]}"
  82.  
  83.         done
  84.  
  85.         printf '\n>'
  86.         read home_dir_n
  87.  
  88.         if [[ $home_dir_n =~ $regex_home_dir ]]; then
  89.             if [[ $home_dir_n -gt 0 ]]; then
  90.                 home_dir_n=$(( home_dir_n - 1 ))
  91.             fi
  92.  
  93.             if [[ -d ${home_dir_list[${home_dir_n}]} ]]; then
  94.                 home_dir="${home_dir_list[${home_dir_n}]}"
  95.                 userid_install=$(basename "$home_dir")
  96.             else
  97.                 continue
  98.             fi
  99.         fi
  100.  
  101.         if [[ $home_dir != '0' ]]; then
  102.             cat <<YES_NO
  103.  
  104. Games will be uninstalled from:
  105. ${home_dir}
  106.  
  107. Is this correct? (yes/no)
  108.  
  109. YES_NO
  110.  
  111.             printf '>'
  112.             read yesno
  113.         fi
  114.     done
  115.  
  116.     bin_dir="${home_dir}/bin"
  117.     install_dir="${home_dir}/id_games"
  118.     deb_dir="${install_dir}/debs"
  119.     start_script_f="${bin_dir}/id_games.sh"
  120.     uninstall_list_f="${install_dir}/id_games_uninstall_list.txt"
  121. }
  122.  
  123. uninstall_files () {
  124.  
  125.     regex_comment='^#'
  126.  
  127.     if [[ ! -f $uninstall_list_f ]]; then
  128.         echo -e "\nGames are not installed!\n"
  129.         exit
  130.     fi
  131.  
  132.     mapfile -t uninstall_list <"$uninstall_list_f"
  133.  
  134.     if [[ $distro == 'deb' ]]; then
  135.         apt remove wolf4sdl rott prboom-plus darkplaces quake2 quake3 || exit
  136.  
  137.         mapfile -t deb_list < <(find "$deb_dir" -type f -iname "*.deb")
  138.  
  139.         for (( i = 0; i < ${#deb_list[@]}; i++ )); do
  140.             deb="${deb_list[${i}]}"
  141.  
  142.             if [[ -f "$deb" ]]; then
  143.                 apt remove "$deb" || exit
  144.             fi
  145.         done
  146.  
  147.         apt autoremove || exit
  148.     elif [[ $distro == 'rpm' ]]; then
  149.         yum remove wolf4sdl-registered-id wolf4sdl-spear rott-registered prboom-plus darkplaces quake2 quake3 || exit
  150.     fi
  151.  
  152.     echo -e "\nRemoving:\n"
  153.  
  154.     for (( i = 0; i < ${#uninstall_list[@]}; i++ )); do
  155.         if [[ ! ${uninstall_list[${i}]} =~ $regex_comment ]]; then
  156.             echo "${uninstall_list[${i}]}"
  157.             rm -rf "${uninstall_list[${i}]}"
  158.         fi
  159.     done
  160. }
  161.  
  162. get_distro
  163. get_userid_install
  164. uninstall_files
RAW Paste Data