atm959

install-prereqs.sh

Mar 11th, 2017
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.99 KB | None | 0 0
  1. clear
  2. cf=""
  3.  
  4. #Check if the number of arguments equals 1. If so, then parse the argument.
  5. if [ $# -eq 1 ]; then
  6.    
  7.     #Check if the argument equals "--uninstall". If so, start the uninstall process.
  8.     if [ $1 == "--uninstall" ]; then
  9.    
  10.         #Ask if the user wants to continue.
  11.         echo -n "Are you sure you want to continue the uninstall process, $USER? (Y/N): "; read cf
  12.        
  13.         #If the user entered "Y" or "y", then continue.
  14.         if [ $cf == "Y" ] || [ $cf == "y" ]; then
  15.             yes | pip uninstall pytmx
  16.             yes | pip uninstall setuptools
  17.             yes | sudo apt remove --force-yes python-pip
  18.             yes | sudo apt remove --force-yes python-pygame
  19.             exit 0
  20.         fi
  21.        
  22.         #If the user entered "N" or "n", then abort.
  23.         if [ $cf == "N" ] || [ $cf == "n" ]; then
  24.             echo "Uninstall process terminated."
  25.             exit 0
  26.         fi
  27.        
  28.         #If the user entered an invalid answer, then abort.
  29.         echo "Invalid answer; uninstall process aborted."
  30.         exit 0
  31.     fi
  32.    
  33.     #If the user entered an invalid argument, then exit.
  34.     echo "Invalid argument."
  35.     exit 0
  36. fi
  37.  
  38. #Ask the question and respond to the answer.
  39. function ask_question(){
  40.    
  41.     #Ask if the user is ready to continue.
  42.     echo -n "Are you sure you want to continue, $USER? (Y/N): "; read cf
  43.    
  44.     #If the answer is "N" or "n", then exit.
  45.     if [ $cf == "N" ] || [ $cf == "n" ]; then
  46.         abort
  47.     fi
  48.    
  49.     #if the answer is "Y" or "y", then proceed.
  50.     if [ $cf == "Y" ] || [ $cf == "y" ]; then
  51.         install_prereqs
  52.     fi
  53.    
  54.     #If the answer is not "N", "n", "Y", or "y", then ask the question again.
  55.     if [ $cf != "N" ] && [ $cf != "n" ] && [ $cf != "Y" ] && [ $cf != "y" ]; then
  56.         invalid_answer
  57.     fi
  58. }
  59.  
  60. #Abort the process.
  61. function abort(){
  62.     echo "Process terminated."
  63.     exit 0
  64. }
  65.  
  66. #Install the prerequisites.
  67. function install_prereqs(){
  68.     yes | sudo apt install python-pygame
  69.     yes | sudo apt install python-pip
  70.     pip install setuptools
  71.     pip install pytmx
  72.     exit 0
  73. }
  74.  
  75. #Reask the question.
  76. function invalid_answer(){
  77.     echo "Invalid answer."
  78.     ask_question
  79. }
  80.  
  81. #Ask the question.
  82. ask_question
Advertisement
Add Comment
Please, Sign In to add comment