Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !/bin/bash
- # A menu driven shell script for rpi
- # ----------------------------------
- # 27 April 2020
- # Mark David Harrington
- # ----------------------------------
- #escape codes
- RED='\033[0;41;30m'
- STD='\033[0;0;39m'
- IRed='\033[0;91m' # Red
- IGreen='\033[0;92m' # Green
- IYellow='\033[0;93m' # Yellow
- IBlue='\033[0;94m' # Blue
- IPurple='\033[0;95m' # Purple
- ICyan='\033[0;96m' # Cyan
- IWhite='\033[0;97m' # White
- # ----------------------------------
- # User defined functions
- # ----------------------------------
- #global variable
- CURRENTDATEONLY=`date +"%A, %b %d, %Y %H:%M:%S"`
- pinsfileA=MyPyInfo/piInfoA.txt
- pinsfileB=MyPyInfo/piInfoB.txt
- cpuInfo=MyPyInfo/cpuInfo.txt
- mboard=MyPyInfo/motherboard.txt
- #make directory
- mkdir MyPiInfo ## where we will store information from menu derived results
- ## pause function
- pause(){
- read -p "Press [Enter] when complete to continue..." p_EnterKey
- }
- # list all pins bcm and connector and wiring pi and gpio
- ShowBCMPins(){
- echo "Listing pins for Raspberry PI"
- sleep 0.5 # # sleep for 0.5 seconds
- gpio readall | tee "$pinsfileA" # display pin out and write to file
- echo ""
- echo "" ## two lines spaceing
- echo -e "${ICyan}All info is saved for you in ${pinsfileA}${STD}"
- pause
- }
- # Show quick reference to pins
- ShowQuickReference(){
- # display alternative pin diagram
- echo "Alternative Listing pins for Raspberry PI"
- sleep 0.5 # # sleep for 0.5 seconds
- pinout | tee "$pinsfileB" # display pin out and write to file
- echo ""
- echo "" ## two lines spaceing
- echo -e "${ICyan}All info is saved for you in ${pinsfileB}${STD}"
- pause
- }
- # display all cpuinfo about rpi
- DisplayCpuInfo (){
- # display all cpuinfo about rpi
- echo " Displaying all cpuinfo on your raspebbbry pi "
- sleep 0.5 # # sleep for 0.5 seconds
- cat /proc/cpuinfo | tee "$cpuInfo" # write this to file
- echo ""
- echo "" ## two lines spaceing
- echo -e "${ICyan}All info is saved for you in ${cpuInfo}${STD}"
- pause
- }
- # display all modle number of rpi
- DisplayBoardInfo()
- {
- # display all modle number of rpi
- echo "Displaying all motherboard info "
- sleep 0.5 # # sleep for 0.5 seconds
- cat /proc/device-tree/model | tee "$mboard" # write this to file
- echo ""
- echo "" ## two lines spaceing
- echo -e "${ICyan}All info is saved for you in ${mboard}${STD}"
- pause
- }
- # quit function
- QuitMenu()
- {
- echo ""
- echo ""
- echo -e " ${ICyan}**********************************************${STD}"
- echo -e " ${ICyan}* Thank you for using this menu *${STD}"
- echo -e " ${ICyan}* Mark David Harrington *${STD}"
- echo -e " ${ICyan}**********************************************${STD}"
- sleep 1
- clear
- exit 0
- }
- # function to display menus
- show_menus() {
- clear
- echo -e " ${IRed}**********************************************${STD}"
- echo -e " ${IRed}* Date : ${CURRENTDATEONLY} *${STD}"
- echo -e " ${IRed}* RPI INFO - M E N U *${STD}"
- echo -e " ${IRed}* Written by MD Harrington *${STD}"
- echo -e " ${IRed}* *${STD}"
- echo -e " ${IRed}**********************************************${STD}"
- echo -e " ${IGreen}1. Display pin numbers in terminal listing all${STD}"
- echo -e " ${IPurple}2. Quck display of listing pins${STD}"
- echo -e " ${IRed}3. Display current cpu information${STD}"
- echo -e " ${ICyan}4. Display Model info${STD}"
- echo -e " ${IWhite}5. Exit ${STD}"
- }
- # read input from the keyboard and take a action
- # invoke the ShowBCMPins() when the user select 1 from the menu option.
- # invoke the ShowQuickReference() when the user select 2 from the menu option.
- # invoke the ShowQuickReference() when the user select 3 form the menu option.
- # invoke the ShowQuickReference() when the user select 3 form the menu option.
- read_options(){
- local choice
- read -p "Enter choice [ 1 - 5] " choice
- case $choice in
- 1) ShowBCMPins ;;
- 2) ShowQuickReference ;;
- 3) DisplayCpuInfo ;;
- 4) DisplayBoardInfo;;
- 5) QuitMenu ;;
- *) echo -e "${RED}Error...${STD}" && sleep 2
- esac
- }
- # ----------------------------------------------
- # Trap CTRL+C, CTRL+Z and quit signals
- # ----------------------------------------------
- trap '' SIGINT SIGQUIT SIGTSTP
- # -----------------------------------
- # Main logic - infinite loop
- # ------------------------------------
- while true
- do
- show_menus
- read_options
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement