Advertisement
Mark2020H

Bash script providing pins information on RPI

Apr 28th, 2020
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.74 KB | None | 0 0
  1. !/bin/bash
  2. # A menu driven shell script for rpi
  3. # ----------------------------------
  4. # 27 April 2020
  5. # Mark David Harrington
  6. # ----------------------------------
  7.  
  8. #escape codes
  9.  
  10. RED='\033[0;41;30m'
  11. STD='\033[0;0;39m'
  12. IRed='\033[0;91m'         # Red
  13. IGreen='\033[0;92m'       # Green
  14. IYellow='\033[0;93m'      # Yellow
  15. IBlue='\033[0;94m'        # Blue
  16. IPurple='\033[0;95m'      # Purple
  17. ICyan='\033[0;96m'        # Cyan
  18. IWhite='\033[0;97m'       # White
  19.  
  20.  
  21. # ----------------------------------
  22. #  User defined functions
  23. # ----------------------------------
  24.  
  25.  
  26. #global variable
  27. CURRENTDATEONLY=`date +"%A, %b %d, %Y %H:%M:%S"`
  28.  
  29. pinsfileA=MyPyInfo/piInfoA.txt
  30. pinsfileB=MyPyInfo/piInfoB.txt
  31. cpuInfo=MyPyInfo/cpuInfo.txt
  32. mboard=MyPyInfo/motherboard.txt
  33.  
  34.  
  35. #make directory
  36.  
  37. mkdir MyPiInfo ##  where we will store information from menu derived results
  38.  
  39. ## pause function
  40.  
  41. pause(){
  42.    
  43.   read -p "Press [Enter] when complete to continue..." p_EnterKey
  44. }
  45.  
  46. # list all pins bcm and connector and  wiring pi and gpio
  47.  
  48. ShowBCMPins(){
  49.    
  50.     echo "Listing pins for Raspberry PI"
  51.      sleep 0.5 #  # sleep for 0.5 seconds
  52.         gpio readall | tee "$pinsfileA" # display pin out and write to file
  53.          
  54.          echo ""
  55.              echo "" ## two lines spaceing
  56.              
  57.                echo -e "${ICyan}All info is saved for you in ${pinsfileA}${STD}"
  58.            
  59.           pause
  60.            
  61. }
  62.  
  63. #  Show quick reference to pins
  64.  
  65. ShowQuickReference(){
  66.    
  67.     # display alternative  pin diagram
  68.     echo "Alternative Listing pins for Raspberry PI"  
  69.        sleep 0.5 #  # sleep for 0.5 seconds
  70.         pinout  | tee "$pinsfileB"   # display pin out and write to file
  71.          
  72.           echo ""
  73.              echo "" ## two lines spaceing
  74.              
  75.                echo -e "${ICyan}All info is saved for you in ${pinsfileB}${STD}"
  76.          
  77.           pause
  78.      
  79. }
  80.  
  81. # display all cpuinfo  about rpi
  82.  
  83. DisplayCpuInfo (){
  84.    
  85.     # display all cpuinfo  about rpi
  86.     echo " Displaying all cpuinfo  on your raspebbbry pi "
  87.       sleep 0.5 #  # sleep for 0.5 seconds
  88.         cat /proc/cpuinfo | tee "$cpuInfo"  # write this to file
  89.           echo ""
  90.              echo "" ## two lines spaceing
  91.              
  92.                echo -e "${ICyan}All info is saved for you in ${cpuInfo}${STD}"
  93.                  pause
  94.  
  95. }
  96.  
  97. # display all modle number of rpi
  98.  
  99. DisplayBoardInfo()
  100. {
  101.    
  102.     # display all modle number of rpi
  103.     echo "Displaying all motherboard info  "
  104.       sleep 0.5 #  # sleep for 0.5 seconds
  105.         cat /proc/device-tree/model | tee "$mboard" # write this to file
  106.              echo ""
  107.              echo "" ## two lines spaceing
  108.              
  109.                echo -e "${ICyan}All info is saved for you in ${mboard}${STD}"
  110.                
  111.                 pause
  112.              
  113.    
  114.    
  115. }
  116.  
  117. # quit function
  118.  
  119. QuitMenu()
  120. {
  121.     echo ""
  122.     echo ""
  123.     echo -e "   ${ICyan}**********************************************${STD}"
  124.     echo -e "   ${ICyan}*      Thank you for using this menu         *${STD}"
  125.     echo -e "   ${ICyan}*         Mark David Harrington              *${STD}"
  126.     echo -e "   ${ICyan}**********************************************${STD}"
  127.    
  128.         sleep 1
  129.           clear
  130.             exit 0
  131. }
  132.  
  133.  
  134. # function to display menus
  135. show_menus() {
  136.    
  137.     clear
  138.     echo -e "   ${IRed}**********************************************${STD}"   
  139.     echo -e "   ${IRed}*  Date : ${CURRENTDATEONLY}     *${STD}"
  140.     echo -e "   ${IRed}*              RPI INFO - M E N U            *${STD}"
  141.     echo -e "   ${IRed}*          Written by MD Harrington          *${STD}"
  142.     echo -e "   ${IRed}*                                            *${STD}"
  143.     echo -e "   ${IRed}**********************************************${STD}"
  144.     echo -e "   ${IGreen}1. Display pin numbers in terminal listing all${STD}"
  145.     echo -e "   ${IPurple}2. Quck display of listing pins${STD}"
  146.     echo -e "   ${IRed}3. Display current cpu information${STD}"
  147.     echo -e "   ${ICyan}4. Display Model info${STD}"
  148.     echo -e "   ${IWhite}5. Exit ${STD}"
  149. }
  150.  
  151.  
  152.  
  153.  
  154. # read input from the keyboard and take a action
  155. # invoke the ShowBCMPins() when the user select 1 from the menu option.
  156. # invoke the ShowQuickReference() when the user select 2 from the menu option.
  157. # invoke the ShowQuickReference() when the user select 3 form the menu option.
  158. # invoke the ShowQuickReference() when the user select 3 form the menu option.
  159.  
  160.  
  161. read_options(){
  162.    
  163.     local choice
  164.     read -p "Enter choice [ 1 - 5] " choice
  165.     case $choice in
  166.         1) ShowBCMPins ;;
  167.         2) ShowQuickReference ;;
  168.         3) DisplayCpuInfo ;;
  169.         4) DisplayBoardInfo;;
  170.         5) QuitMenu ;;
  171.         *) echo -e "${RED}Error...${STD}" && sleep 2
  172.     esac
  173. }
  174.  
  175. # ----------------------------------------------
  176. #  Trap CTRL+C, CTRL+Z and quit signals
  177. # ----------------------------------------------
  178. trap '' SIGINT SIGQUIT SIGTSTP
  179.  
  180. # -----------------------------------
  181. # Main logic - infinite loop
  182. # ------------------------------------
  183. while true
  184. do
  185.  
  186.     show_menus
  187.     read_options
  188. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement