flipje

backupmanager-shell-menu-onder-constructie

Aug 9th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.52 KB | None | 0 0
  1. #!/bin/bash
  2. # +-----------------------------------------------------------------------------------------+
  3. # |                                                                                         |
  4. # |                                                                                         |
  5. # |                                                                                         |
  6. # |                                                                                         |
  7. # | Mei 2012 flip hess [email protected]                                                  |
  8. # +-----------------------------------------------------------------------------------------+
  9.  
  10. # Global variables:
  11.  
  12. PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
  13. SCRIPT_PATH="${0}"
  14. ARGS="${#}"
  15.  
  16. # Text color variables
  17.  
  18. txtund=$(tput sgr 0 1)    # Underline
  19. txtbld=$(tput bold)       # Bold
  20. txtred=$(tput setaf 1)    # Red
  21. txtgrn=$(tput setaf 2)    # Green
  22. txtylw=$(tput setaf 3)    # Yellow
  23. txtgrn=$(tput setaf 4)    # Blue
  24. txtpur=$(tput setaf 5)    # Purple
  25. txtcyn=$(tput setaf 6)    # Cyan
  26. txtwht=$(tput setaf 7)    # White
  27. txtrst=$(tput sgr0)       # Text reset
  28.  
  29. # screen size vars
  30. LINES=$(tput lines)
  31. COLUMNS=$(tput cols)
  32.  
  33. # Functions:
  34.  
  35.   # exit function
  36.   function die()
  37.   {
  38.     echo -e "Error in${SCRIPT_PATH}:\n${1}"
  39.     exit 1
  40.   }
  41.  
  42.   # Shows usage function.
  43.   function fShowUsage()
  44.   {
  45.     echo "Usage: ${SCRIPT_PATH}"
  46.     exit 1
  47.   }
  48.  
  49.   # check for.......
  50.   function fCheck()
  51.   {
  52.     # user must be root:
  53.     #[ $(whoami) = root ] || die "User must be root!"
  54.  
  55.     # check for arguments:
  56.     [ "${ARGS}" = 0 ] || fShowUsage
  57.  
  58.     # check terminal size
  59.     [ "${COLUMNS}" -gt 90 ] || die "Terminal size is to small! Please change your terminal to at least 90 Columns"
  60.  
  61.     return 0
  62.   }
  63.  
  64.   # function new customer
  65.   fNewCust()
  66.   {
  67.  
  68.    fReturn
  69.  
  70.   }
  71.  
  72.   # delete customers
  73.   fDelCust()
  74.   {
  75.  
  76.    fReturn
  77.   }
  78.  
  79.   # run backup for customer
  80.   fBackupRun()
  81.   {
  82.  
  83.    fReturn
  84.  
  85.    return 0
  86.   }
  87.  
  88.   # show bandwith use for customer
  89.   fBandwidth()
  90.   {
  91.    { [ -x /usr/local/bin/andy/python.py ] && /usr/local/bin/andy/python.py; } || die "Failed to run /usr/local/bin/andy/python.py"
  92.  
  93.  
  94.  
  95.    fReturn
  96.  
  97.    return 0
  98.   }
  99.  
  100.   # show data size for customer
  101.   fUsed()
  102.   {
  103.  
  104.    fReturn
  105.  
  106.    return 0
  107.   }
  108.  
  109.   fOverview()
  110.   {
  111.    fReturn
  112.  
  113.    return 0
  114.   }
  115.  
  116.   # return functie
  117.   function fReturn()
  118.   {
  119.    SET=0
  120.    while [ ${SET} = 0 ] ;
  121.    do
  122.      # clear screen
  123.      clear
  124.      # get output
  125.      echo -e "\
  126.   ${txtylw}######################################################################################${txtrst}\n\
  127.   ${txtylw}# +--------------------------------------------------------------------------------+ #${txtrst}\n\
  128.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  129.   ${txtylw}# |   All Done!                                                                   ${txtylw} | #${txtrst}\n\
  130.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  131.   ${txtylw}# |   Press any key to return to the menu,                                        ${txtylw} | #${txtrst}\n\
  132.   ${txtylw}# |   Type exit to exit backup manager.                                           ${txtylw} | #${txtrst}\n\
  133.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  134.   ${txtylw}# +--------------------------------------------------------------------------------+ #${txtrst}\n\
  135.   ${txtylw}######################################################################################${txtrst}"
  136.      read -p "${txtwht}${txtbld}   --> " ANSWER
  137.  
  138.      # get answer
  139.      if [ "${ANSWER}" = e ] ; then
  140.         { echo -e "${txtred}${txtbld}Exiting in 1 seconds${txtrst}" ; sleep 0.5 ; clear ; exit 1; }
  141.      elif [ ${ANSWER} = E ] ; then
  142.         { echo -e "${txtred}${txtbld}Exiting in 1 seconds${txtrst}" ; sleep 0.5 ; clear ; exit 1; }
  143.      elif [ ${ANSWER} = exit ] ; then
  144.         { echo -e "${txtred}${txtbld}Exiting in 1 seconds${txtrst}" ; sleep 0.5 ; clear ; exit 1; }
  145.      elif [ ${ANSWER} = EXIT ] ; then
  146.         { echo -e "${txtred}${txtbld}Exiting in 1 seconds${txtrst}" ; sleep 0.5 ; clear ; exit 1; }
  147.      elif [ ${ANSWER} = Exit ] ; then
  148.         { echo -e "${txtred}${txtbld}Exiting in 1 seconds${txtrst}" ; sleep 0.5 ; clear ;exit 1; }
  149.      else
  150.        SET=1
  151.      fi
  152.   done
  153.  
  154.   # go back to menu
  155.   [ "${SET}" = 1 ] && fStart
  156.  
  157.   }
  158.  
  159.   # function get startpage
  160.   function fStart()
  161.   {
  162.    # clear screen
  163.    clear
  164.    # print menu
  165.    echo -e "\
  166.   ${txtylw}######################################################################################${txtrst}\n\
  167.   ${txtylw}# +--------------------------------------------------------------------------------+ #${txtrst}\n\
  168.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  169.   ${txtylw}# |           ${txtpur} #####     ##     ####   #    #  #    #  #####                      ${txtylw} | #${txtrst}\n\
  170.   ${txtylw}# |           ${txtpur} #    #   #  #   #    #  #   #   #    #  #    #                     ${txtylw} | #${txtrst}\n\
  171.   ${txtylw}# |           ${txtpur} #####   #    #  #       ####    #    #  #    #                     ${txtylw} | #${txtrst}\n\
  172.   ${txtylw}# |           ${txtpur} #    #  ######  #       #  #    #    #  #####                      ${txtylw} | #${txtrst}\n\
  173.   ${txtylw}# |           ${txtpur} #    #  #    #  #    #  #   #   #    #  #                          ${txtylw} | #${txtrst}\n\
  174.   ${txtylw}# |           ${txtpur} #####   #    #   ####   #    #   ####   #                          ${txtylw} | #${txtrst}\n\
  175.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  176.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  177.   ${txtylw}# |           ${txtred} #    #    ##    #    #    ##     ####   ######  #####              ${txtylw} | #${txtrst}\n\
  178.   ${txtylw}# |           ${txtred} ##  ##   #  #   ##   #   #  #   #    #  #       #    #             ${txtylw} | #${txtrst}\n\
  179.   ${txtylw}# |           ${txtred} # ## #  #    #  # #  #  #    #  #       #####   #    #             ${txtylw} | #${txtrst}\n\
  180.   ${txtylw}# |           ${txtred} #    #  ######  #  # #  ######  #  ###  #       #####              ${txtylw} | #${txtrst}\n\
  181.   ${txtylw}# |           ${txtred} #    #  #    #  #   ##  #    #  #    #  #       #   #              ${txtylw} | #${txtrst}\n\
  182.   ${txtylw}# |           ${txtred} #    #  #    #  #    #  #    #   ####   ######  #    #             ${txtylw} | #${txtrst}\n\
  183.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  184.   ${txtylw}# |     Mhasmo backup manger - Flip Hess Mei 2012 - [email protected]       ${txtylw} | #${txtrst}\n\
  185.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  186.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  187.   ${txtylw}# |${txtgrn}     1.  Een nieuwe backupklant toevoegen.                                     ${txtylw} | #${txtrst}\n\
  188.   ${txtylw}# |${txtgrn}     2.  Een backupklant verwijderen.                                          ${txtylw} | #${txtrst}\n\
  189.   ${txtylw}# |${txtgrn}     3.  Een backup draaien voor een klant.                                    ${txtylw} | #${txtrst}\n\
  190.   ${txtylw}# |${txtgrn}     4.  Bandbreedte log opvragen voor een klant.                              ${txtylw} | #${txtrst}\n\
  191.   ${txtylw}# |${txtgrn}     5.  Dataverbruik log opvragen voor een klant.                             ${txtylw} | #${txtrst}\n\
  192.   ${txtylw}# |${txtgrn}     6.  Overzicht alle klanten weergeven.                                     ${txtylw} | #${txtrst}\n\
  193.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  194.   ${txtylw}# |${txtgrn}     9.  Backup manager afsluiten.                                             ${txtylw} | #${txtrst}\n\
  195.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  196.   ${txtylw}# |                                                                               ${txtylw} | #${txtrst}\n\
  197.   ${txtylw}# |   Maak uw keuze door het desbetreffende nummer in te toetsen.                 ${txtylw} | #${txtrst}\n\
  198.   ${txtylw}# +--------------------------------------------------------------------------------+ #${txtrst}\n\
  199.   ${txtylw}######################################################################################${txtrst}"
  200.    read -p "${txtwht}Wat wordt uw keuze? -->  " INPUT
  201.  
  202.     #get options and set vars
  203.     case "${INPUT}" in
  204.  
  205.       1)
  206.         fNewCust
  207.         ;;
  208.       2)
  209.         fDelCust
  210.         ;;
  211.       3)
  212.         fBackupRun
  213.         ;;
  214.       4)
  215.         fBandwidth
  216.         ;;
  217.       5)
  218.         fUsed
  219.         ;;
  220.       6)
  221.         fOverview
  222.         ;;
  223.       9)
  224.         exit 0
  225.         ;;
  226.       *)
  227.         echo "${txtred}${txtbld}Input value not valid!${txtrst}" ; sleep 1
  228.         fStart
  229.         ;;
  230.       esac
  231.  
  232.    return 0
  233.   }
  234.  
  235.   # The main function.
  236.   function fMain()
  237.   {
  238.    fStart
  239.  
  240.    return 0
  241.   }
  242.  
  243.  # check environment:
  244.   fCheck
  245.  
  246.  # Start the program:
  247.   fMain "${@}"
  248.  
  249.  # Exit with previous return code:
  250.   exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment