├── .gitignore ├── License.md ├── README.md ├── documentation ├── bmtData.md ├── bmtFiles.md ├── bmtLinux.md ├── bmtMisc.md ├── bmtNetwork.md ├── bmtPrint.md ├── bmtPrompt.md ├── bmtTest.md ├── bmtTime.md ├── misc │ └── changelog.md └── screenshot │ ├── colour_print_example.png │ ├── example.png │ ├── output_test_print.png │ └── test.png ├── example └── example.sh ├── lib ├── bmtData ├── bmtFiles ├── bmtLinux ├── bmtMisc ├── bmtNetwork ├── bmtPrint ├── bmtPrompt ├── bmtTest └── bmtTime ├── main └── bashmultitool ├── makefile └── test ├── testObjects ├── NonEmptyDir │ └── text.txt ├── dummyfile.foofoo ├── empty.txt ├── full.txt └── tv.png ├── testTest.sh └── testlog ├── pass.log └── test.log /.gitignore: -------------------------------------------------------------------------------- 1 | stuff/ 2 | -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | Copyright (c) <2018> 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) 2 | 3 | Overview 4 | -------------------------------------------- 5 | * Name: bashMultiTool 6 | * Description: 7 | 8 | A Bash Shell library file for commonly used functions 9 | can be imported into shell scripts to create functional and colorful 10 | scripts and Terminal users interfaces(TUI). 11 | The library allows user to redefine commonly used functions every time you write a shell script, the library may save a part of the development time. 12 | 13 | * Author: Gavin Lyons 14 | * GNU bash: version 5.1.16 15 | 16 | Table of contents 17 | --------------------------- 18 | 19 | * [Installation](#installation) 20 | * [Usage](#usage) 21 | * [Software](#software) 22 | * [Example](#example) 23 | 24 | Installation 25 | ----------------------------------------------- 26 | 27 | **Linux debian based systems built on Ubuntu 22.04 LTS (Jammy Jellyfish)** 28 | 29 | A Personal Package Archives (PPA) has been created on Ubuntu 30 | package building and hosting section of launchpad site 31 | called bashmultitool. 32 | 33 | To install this on your system run commands in terminal 34 | 35 | ```sh 36 | sudo add-apt-repository ppa:typematrix/bashmultitool 37 | sudo apt update 38 | sudo apt install bashmultitool 39 | ``` 40 | 41 | **Arch based System** 42 | 43 | Package available in the Arch Linux user repo AUR 44 | 45 | **For other linux systems** 46 | 47 | Download latest fixed release and run the makefile as per 48 | terminal commands below for version 2.1 latest release at time of writing 49 | Note: If you install with this method you will not be informed of updates 50 | by system. 51 | 52 | ```sh 53 | curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.1.tar.gz | tar xz 54 | cd bashmultitool-2.1 55 | sudo make install 56 | ``` 57 | 58 | Usage 59 | ------------------------------------------- 60 | 61 | Source the library functions from your bash shell scripts like so: 62 | 63 | ```sh 64 | LIBPATH="/usr/lib/bashmultitool/" 65 | for MYFILE in "$LIBPATH"*; 66 | do 67 | source "$MYFILE" 68 | done 69 | ``` 70 | 71 | To access library functions from your shell scripts type: 72 | 73 | ```sh 74 | # [function-name] [keyword] [options] 75 | # eg 76 | 77 | bmtPrintFunc b_red "Hello World" 78 | ``` 79 | 80 | Software 81 | ----------------------------------------- 82 | 83 | Eight separate markdown help files with detailed information, 84 | in documentation folder are available. 85 | For shortcut to each help file click on link in 2nd table below. 86 | A script to print library meta data is also installed. 87 | 88 | | Installed File Path | Description | 89 | | ------ | ------ | 90 | | /usr/bin/bashmultitool | Script to print library meta data | 91 | | /usr/lib/bashmultitool/bashmultitool/* | 8 library files see next table| 92 | | /usr/lib/bashmultitool/doc/README.md | readme | 93 | | /usr/lib/bashmultitool/doc/bmt*.md | 8 Documentation files see next table | 94 | 95 | | Library file | Function | Sections | Content | Doc link | 96 | | ---- | ---- | ---- | ---- | ---- | 97 | | bmtPrint | bmtPrintFunc | 101 | Printing text | [bmtPrint help file](documentation/bmtPrint.md)| 98 | | bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)| 99 | | bmtNetwork | bmtNetworkFunc | 301-302 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md)| 100 | | bmtLinux | bmtLinuxFunc | 401-408 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)| 101 | | bmtFiles | bmtFilesFunc | 501-510 | File related | [bmtFiles help file](documentation/bmtFiles.md)| 102 | | bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)| 103 | | bmtTime | btmTimeFunc | 701-710 | Time related | [bmtTime help file](documentation/bmtTime.md)| 104 | | bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)| 105 | | bmtTest | bmtTestFunc | 901 | internal library test | [bmtTest help file](documentation/bmtTest.md)| 106 | 107 | The library contains eight section's, Each section has one file with one function. 108 | Which contains 54 sub-sections in total. 109 | The sections are grouped per logical function. 110 | Printing, prompting, Linux related, file related, 111 | data related, time related , network related and miscellaneous. 112 | The sections are mostly independent of each other 113 | you can source them individually if you wish, however the prompt file *is* 114 | dependent on print. There is also a ninth test section bmtTest used to test library. 115 | 116 | The repo also contains a *test folder* where a test file used in development are available, one function for each library file. The test file "testTest.sh", runs an semi-automated test on entire library and produces a report. Pass the test file a number between 1-9 , 1-8 correspond to the sections, 9 will test entire library. 117 | 118 | Example 119 | ---------------------------- 120 | 121 | Output of basic example file in example folder, showing basic usage. 122 | 123 | ![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/example.png) 124 | 125 | Output report of test script testTest.sh. 126 | 127 | ![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/test.png) 128 | -------------------------------------------------------------------------------- /documentation/bmtData.md: -------------------------------------------------------------------------------- 1 | 2 | | Library file | Function | Sections | Content | help file | 3 | | ---- | ---- | ---- | ---- | ---- | 4 | | bmtData | btmDataFunc | 601-607 | Data related | bmtData.md| 5 | 6 | **Section Six, Data** 7 | 8 | * 601 integer user input check 9 | * 602 alphabet user input check 10 | * 603 alphanumeric user input check 11 | * 604 convert string to lowercase 12 | * 605 convert string to uppercase 13 | * 606 trim white space from string 14 | * 607 String Length 15 | 16 | **Sub-Sections** 17 | 18 | 601) integer input check 19 | 20 | Keyword intcheck, first option the item to be checked if integer 21 | 22 | ```sh 23 | bmtDataFunc intcheck "$age" 24 | ``` 25 | 26 | Returns 0 for integer , 2 for non integer. 27 | 28 | 602) Alphanumeric input check 29 | 30 | Keyword alphanumcheck, first option the item to be checked if Alphanumeric 31 | 32 | ```sh 33 | bmtDataFunc alphanumcheck "$address" 34 | ``` 35 | 36 | Returns 0 for alphanumcheck , 2 for non alphanumcheck. 37 | 38 | 603) alphabet input check 39 | 40 | Keyword alphacheck) , first option the item to be checked if alphabet 41 | 42 | ```sh 43 | bmtDataFunc alphacheck "$name" 44 | ``` 45 | 46 | Returns 0 for alphabet , 2 for non alphabet. 47 | 48 | 604) convert a string to lowercase 49 | 50 | ```sh 51 | result=$(bmtDataFunc lowercase "TEST") 52 | echo $result 53 | ``` 54 | 55 | 605) convert a string to uppercase 56 | 57 | ```sh 58 | result=$(bmtDataFunc upperrcase "test") 59 | echo $result 60 | ``` 61 | 62 | 606) trim whitespace from a strin 63 | 64 | ```sh 65 | result2=$(bmtDataFunc trim " test " 66 | echo $result2 67 | ``` 68 | 69 | 607) String Length 70 | Returns string length , maximum 249 , 250 is Null string error. 71 | 72 | ```sh 73 | bmtDataFunc strlen "test string 123" #15 74 | echo $? 75 | ``` 76 | -------------------------------------------------------------------------------- /documentation/bmtFiles.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file| 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtFiles | bmtFilesFunc | 501-510 | File related | bmtFiles.md | 4 | 5 | **Section Five, File** 6 | 7 | * 501 Check if directory exists and empty 8 | * 502 Make and enter a formatted directory 9 | * 503 Directory exists 10 | * 504 File exists 11 | * 505 Device exists 12 | * 506 File empty 13 | * 507 File size 14 | * 508 File size in bytes 15 | * 509 mime type exists? 16 | * 510 File name extraction 17 | 18 | **Sub-Sections** 19 | 20 | 501) Make formated directory 21 | 22 | The keyword is makedir, First option is path , second is the text 23 | appended to end. 24 | 25 | ```sh 26 | bmtFilesFunc makedir "/tmp/" "-TEST" 27 | ``` 28 | 29 | Output folders are created with following time/date stamp syntax 30 | HHMM-DDMONYY-X where X is text from third option. 31 | Makes the directory and cds into it 32 | Returns 0 for success, 52 if in cannot access or create the directory 33 | 34 | 502) Does directory exist and is it empty 35 | 36 | The keyword is isdirempty , the first option is path returns 0 for empty 37 | , 2 for not empty , 3 if it does not exist. 38 | 39 | ```sh 40 | bmtFilesFunc isdirempty "$HOME/Desktop/TEST/file/" 41 | ``` 42 | 43 | 503) directory exists 44 | 45 | returns 0 for success, 2 for failure 46 | 47 | ```sh 48 | bmtFilesFunc directoryexists /tmp/foo 49 | ``` 50 | 51 | 504) file exists 52 | 53 | returns 0 for success, 2 for failure 54 | 55 | ```sh 56 | bmtFilesFunc fileexists /tmp/foo 57 | ``` 58 | 59 | 505) device exists 60 | 61 | returns 0 for success, 2 for failure 62 | 63 | ```sh 64 | bmtFilesFunc deviceexists /dev/sda 65 | ``` 66 | 67 | 506) Empty File 68 | Check if file empty 69 | returns 0 if not empty , 2 if empty 70 | 71 | ```sh 72 | bmtFilesFunc isfileempty "/foo/foo.txt" 73 | echo $? 74 | ``` 75 | 76 | 507) File size 77 | Prints file size and returns 0 if file does not exist returns 2 78 | ```sh 79 | bmtFilesFunc getfilesize "/foo/foo.txt" 80 | ``` 81 | 82 | 508) File Size in bytes 83 | Prints file size and returns 0 if file does not exist returns 2 84 | ```sh 85 | bmtFilesFunc getfilesizebytes "/foo/foo.txt" 86 | ``` 87 | 88 | 509) Display mime type of input file 89 | Returns 4 If file/directory does not exist. , 3 If file or mimetype command not found in system. 90 | 2 if missing arguments, 0 for success. 91 | 92 | ```sh 93 | bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt" >> /tmp/mytempfile123.txt 94 | echo $? 95 | ``` 96 | 510) File name extraction 97 | Returns 0 for success, 2 for missing arguments , 3 for wrong 2nd argument value, 4 for missing file extension 98 | 99 | 1. Param1 Filepath 100 | 2. Param2 1-4 1 for filename, 2 for basename, 3 for extension ,4 for folder path 101 | 102 | ```sh 103 | bmtFilesFunc filename "/foo/foo123/tv.png" 4 104 | echo " :: Folder name $?" 105 | ``` 106 | -------------------------------------------------------------------------------- /documentation/bmtLinux.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file| 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtLinux | bmtLinuxFunc | 401-408 | Linux related | bmtLinux.md | 4 | 5 | **Section Four, Linux** 6 | 7 | * 401 Check package installed 8 | * 402 Linux distribution family checker 9 | * 403 Set text editor $EDITOR if not set 10 | * 404 Log file handler 11 | * 405 Check if user exists 12 | * 406 Variable set and/or empty check 13 | * 407 Run script as root check 14 | * 408 Check if command exists in system 15 | 16 | **Sub-Sections** 17 | 18 | 401) Check package installed 19 | 20 | Keyword is checkpac . First option is package name, 21 | Second option is type of distro(options are 1 for pacman based, 2 22 | for debian based, 3 for rpm based) 23 | Third option is wheter to display message or not include "MES" 24 | for verbose output 25 | 26 | ```sh 27 | bmtLinuxFunc checkpac "firefox" 2 "MES" 28 | ``` 29 | 30 | Returns 0 for installed , 2 for not installed , 31 | 52 for unsupported linux distro 32 | 33 | 402) Linux distro family checker 34 | 35 | ```sh 36 | bmtLinuxFunc distrocheck 37 | ``` 38 | 39 | Returns 2-7 for known distro family groups or 52 for unknown. 40 | (2 redhat based, 3 fedora based, 4 debian based, 5 pacman based, 41 | 6 gentoo based , 7 slackware based.) 42 | 43 | 403) Is text editor variable $EDITOR set? 44 | 45 | ```sh 46 | bmtLinuxFunc isTextEdSet 47 | ``` 48 | 49 | returns 0 if it was set, 2 if not and sets it to vi 50 | 51 | 404) log file handler 52 | Creates a log file entry with standard formated date/time stamp. 53 | 54 | | Option | Option description | 55 | | ---- | ---- | 56 | | 1 State | valid states are EMERGENCY, ALERT, CRITICAL, ERROR,WARNING,NOTICE,INFO,DEBUG,OK,FAILED,PASSED returns 55 for invalid state| 57 | | 2 Message | if blank message passed "-- empty log message" appended | 58 | | 3 Filename | .log will be appended | 59 | | 4 Path | path for log file | 60 | | 5 Echo | if "MES" log message will also be echoed to console| 61 | 62 | ```sh 63 | bmtLinuxFunc log "CRITICAL" "1201 alarm Executive overflow - no vacant areas" mylog /tmp/ 64 | bmtLinuxFunc log "CRITICAL" "1202 alarm Executive overflow - no core sets" mylog /tmp/ 65 | bmtLinuxFunc log "INFO" "62 Watchdog reset" mylog /tmp/ "MES" 66 | ``` 67 | 68 | 405) Check if user exists 69 | Check if user exist on system 70 | Returns 0 if exists, 2 if not. 71 | 72 | ```sh 73 | bmtLinuxFunc user "gavin" 74 | echo "$?" 75 | ``` 76 | 406) Check if variable is set and is empty 77 | Returns 0 if set and non-empty, 2 if set and empty , 3 if unset 78 | 79 | ```sh 80 | bmtLinuxFunc isvarempty varsetfull 81 | echo "$?" 82 | ``` 83 | 84 | 407) Run Script as root check 85 | Returns 2 if not running as root 86 | 87 | ```sh 88 | bmtLinuxFunc runasroot 89 | ``` 90 | 91 | 408) Check if command exists in system 92 | Returns 2 if command does not exist on system. 93 | 94 | ```sh 95 | bmtLinuxFunc iscommand tput 96 | echo "$?" 97 | ``` 98 | -------------------------------------------------------------------------------- /documentation/bmtMisc.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | bmtMisc.md | 4 | 5 | 6 | **Section Eight , misc** 7 | 8 | * 801 Password generator 9 | * 802 Get laptop battery level 10 | * 803 Create a multi-line box with text inside it 11 | * 804 Create a single line box with variable box character. 12 | * 805 Centered text with variable banner character 13 | * 806 Display gauge 14 | 15 | **Sub-Sections** 16 | 17 | 801) Password generator 18 | Generates a random password in passwordBMT.txt, returns 0 for success. 19 | Prompts user for length of password. Optional path can be added, if no path added 20 | file passed in /tmp/. 21 | 22 | ```sh 23 | bmtMiscFunc password "/home/foo" 24 | ``` 25 | 26 | 802) Return laptop battery level 27 | * Return 0-100 , % of battery remaining , 127 and 128 file errors 28 | * Param 1 Battery name, BAT0 or BAT1 at /sys/class/power_supply 29 | * Param 2 "MES" or blank , if exist print message 30 | 31 | ```sh 32 | bmtMiscFunc getbatlevel "BAT0" "MES" 33 | echo "$?" 34 | ``` 35 | 803) Create a multi-line box with text inside it 36 | 37 | 1. Param1 color of box , tput setaf , 1 = red 38 | 2. Param2 color of text , tput setaf , 2 = green 39 | 3. The Rest of Params are the lines of text 40 | 41 | ```sh 42 | bmtMiscFunc drawbox 1 2 'first line' 'second line' 'third line' 43 | ``` 44 | 45 | 804) Create a single line box with variable box character. 46 | 1. Param 1 color of box, tput setaf 2=green 47 | 2. Param 2 color of text , tput setaf 6=cyan 48 | 3. Param 3 symbol to make the box lines out of. 49 | 4. Param 4 text 50 | 51 | ```sh 52 | bmtMiscFunc title 2 6 '#' 'hello' 53 | ``` 54 | 55 | 805) Centered text with option banner filler 56 | 1. Param1 Text to center 57 | 2. Param2 Banner symbol 58 | 59 | ```sh 60 | bmtMiscFunc centertext "Hello World" = 61 | ``` 62 | 63 | 806) Display Gauge, display a gauge bar showing variable value 64 | 65 | 1. Param1 Text label 66 | 2. Param2 Value to display 67 | 3. Param3 Minimum value of gauge 68 | 4. Param4 Maximum value of gauge 69 | 5. Param5 Gauge full symbol 70 | 6. Param6 Gauge empty symbol 71 | 72 | ```sh 73 | bmtMiscFunc gauge "Volts" 25 1 50 "#" "." 74 | ``` 75 | -------------------------------------------------------------------------------- /documentation/bmtNetwork.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtNetwork | bmtNetworkFunc | 301-302 | Network | bmtNetwork.md | 4 | 5 | **Section Three, Network** 6 | 7 | * 301 Check if a website is up 8 | * 302 Weather forecast 9 | 10 | **Sub-Sections** 11 | 12 | 301) Check website up uses netcat utility 13 | 14 | Keyword checknet, first option url of website. Returns 0 for connectivity , 2 for no connectivity 15 | 16 | 1. Param1 The URL 17 | 2. Param2 NOMES(optional) can be used to surpress verbose output. 18 | 19 | ```sh 20 | bmtNetworkFunc checknet "www.google.ie" 21 | ``` 22 | 23 | ```sh 24 | bmtNetworkFunc checknet "www.google.ie" "NOMES" 25 | ``` 26 | 27 | 302) weather 28 | 29 | Weather report by wttr.in, uses wget utility 30 | 31 | 1. Param1 Type a City name, airport code, domain name or area code:- 32 | 2. Param2 format 1-4 33 | 34 | ```sh 35 | bmtNetworkFunc weather Dublin 4 36 | ``` 37 | -------------------------------------------------------------------------------- /documentation/bmtPrint.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtPrint | bmtPrintFunc | 101 | Printing text | bmtPrint.md | 4 | 5 | **Section One , Printing** 6 | 7 | * 101 Coloured printed text, 8 colours, 7 modes. 56 options in total. 8 | 9 | Colours: Black, Red, Green, Yellow, Blue, Purple, Cyan, White. 10 | 11 | Modes: normal, bold, underline, background, high intensity, 12 | bold high intensity, background high intensity. 13 | 14 | 1. Param1 mode 15 | 2. Param2 text to print(optional can be left out just to change cursor colour 16 | for next objects or text printed ) 17 | 18 | **Sub-Sections** 19 | 20 | 101) Colored printed text 21 | 22 | The keyword represent the color, the text to be printed is first option. 23 | leave text option blank to just change the colour mode of cursor 24 | 25 | ```sh 26 | bmtPrintFunc red # change colour, no output. 27 | echo "red text" 28 | bmtPrintFunc norm "default terminal text" 29 | 30 | bmtPrintFunc black "black" 31 | bmtPrintFunc red "red" 32 | bmtPrintFunc green "green" 33 | bmtPrintFunc yellow "yellow" 34 | bmtPrintFunc blue "blue " 35 | bmtPrintFunc purple "purple" 36 | bmtPrintFunc cyan "cyan" 37 | bmtPrintFunc white "white" 38 | bmtPrintFunc b_black "bold black " 39 | bmtPrintFunc b_red "bold red " 40 | bmtPrintFunc b_green "bold green " 41 | bmtPrintFunc b_yellow "bold yellow " 42 | bmtPrintFunc b_blue "bold blue " 43 | bmtPrintFunc b_purple "bold purple " 44 | bmtPrintFunc b_cyan "bold cyan " 45 | bmtPrintFunc b_white "bold white " 46 | bmtPrintFunc u_black "underline black " 47 | bmtPrintFunc u_red "underline red " 48 | bmtPrintFunc u_green "underline green " 49 | bmtPrintFunc u_yellow "underline yellow " 50 | bmtPrintFunc u_blue "underline blue " 51 | bmtPrintFunc u_purple "underline purple " 52 | bmtPrintFunc u_cyan "underline cyan " 53 | bmtPrintFunc u_white "underline white " 54 | bmtPrintFunc bg_black "background black " 55 | bmtPrintFunc bg_red "background red " 56 | bmtPrintFunc bg_green "background green " 57 | bmtPrintFunc bg_yellow "background yellow " 58 | bmtPrintFunc bg_blue "background blue " 59 | bmtPrintFunc bg_purple "background purple " 60 | bmtPrintFunc bg_cyan "background cyan " 61 | bmtPrintFunc bg_white "background white " 62 | bmtPrintFunc i_black "high intensity black " 63 | bmtPrintFunc i_red "high intensity red " 64 | bmtPrintFunc i_green "high intensity green " 65 | bmtPrintFunc i_yellow "high intensity yellow " 66 | bmtPrintFunc i_blue "high intensity blue " 67 | bmtPrintFunc i_purple "high intensity purple " 68 | bmtPrintFunc i_cyan "high intensity cyan " 69 | bmtPrintFunc i_white "high intensity white " 70 | bmtPrintFunc bh_black "high intensity bold black " 71 | bmtPrintFunc bh_red "high intensity bold red " 72 | bmtPrintFunc bh_green "high intensity bold green " 73 | bmtPrintFunc bh_yellow "high intensity bold yellow " 74 | bmtPrintFunc bh_blue "high intensity bold blue " 75 | bmtPrintFunc bh_purple "high intensity bold purple " 76 | bmtPrintFunc bh_cyan "high intensity bold cyan " 77 | bmtPrintFunc bh_white "high intensity bold white " 78 | bmtPrintFunc hbg_black "high intensity background black " 79 | bmtPrintFunc hbg_red "high intensity background red " 80 | bmtPrintFunc hbg_green "high intensity background green " 81 | bmtPrintFunc hbg_yellow "high intensity background yellow " 82 | bmtPrintFunc hbg_blue "high intensity background blue " 83 | bmtPrintFunc hbg_purple "high intensity background purple " 84 | bmtPrintFunc hbg_cyan "high intensity background cyan " 85 | bmtPrintFunc hbg_white "high intensity background white " 86 | ``` 87 | 88 | **Example Output:** 89 | 90 | ![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/colour_print_example.png) 91 | 92 | ![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/output_test_print.png) 93 | -------------------------------------------------------------------------------- /documentation/bmtPrompt.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtPrompt | bmtPromptFunc | 201-210 | Prompts | bmtPrompt.md| 4 | 5 | 6 | **Section Two, Prompts** 7 | 8 | * 201 Horizontal lines across terminal, in any colour 9 | * 202 yes-no-quit [y/n/q] loop prompt 10 | * 203 yes-NO [y/N] prompt 11 | * 204 YES-no [Y/n] prompt 12 | * 205 Anykey to continue prompt, in any colour 13 | * 206 quit-NO [q/N] prompt 14 | * 207 QUIT-no [Q/N] prompt 15 | * 208 Wish to continue loop prompt 16 | * 209 Print centered text 17 | * 210 Print event status 18 | 19 | **Sub-Sections** 20 | 21 | 201) Horizontal lines across terminal of single character 22 | 23 | Keyword is line, first option the character, second option is colour, 24 | if no colour passed default is "bold cyan" 25 | 26 | ```sh 27 | bmtPromptFunc line "=" 28 | bmtPromptFunc line "8" red 29 | ``` 30 | 31 | 202) yes-no-quit prompt y/n/q 32 | 33 | Keyword is yesnoquit , returns codes based on user input 34 | 35 | ```sh 36 | echo "Do you want to foo? [y/n/q] :" 37 | bmtPromptFunc yesnoquit 38 | ``` 39 | Returns 0 for yes , 2 for no , 3 for quit 40 | 41 | 203) Yes-no prompt [y/N] where no is default 42 | 43 | Keyword is yesno , returns codes based on user input 44 | second option yes 45 | 46 | ```sh 47 | echo "Do you want to foo? [y/N] :" 48 | bmtPromptFunc yesno yes 49 | ``` 50 | Returns 0 for yes , 2 for no , 50 for bad user option 51 | 52 | 204) Yes-no prompt [Y/n] where yes is default 53 | 54 | Keyword is yesno , returns codes based on user input 55 | second option is no 56 | 57 | ```sh 58 | echo "Do you want to foo? [Y/n] :" 59 | bmtPromptFunc yesno no 60 | ``` 61 | Returns 0 for no , 2 for yes , 50 for bad user option 62 | 63 | 205) Anykey prompt 64 | 65 | Keyword is anykey , first option amended text, second option is colour, 66 | if no colour passed default is "bold cyan" 67 | 68 | ```sh 69 | bmtPromptFunc anykey "my Text here" 70 | bmtPromptFunc anykey "my Text here" u_red 71 | ``` 72 | 73 | 206) QUIT-no prompt [q/N] where quit is default 74 | 75 | Keyword is quitno , returns codes based on user input 76 | second option quit 77 | 78 | ```sh 79 | echo "Do you want to foo? [q/N] :" 80 | bmtPromptFunc quitno quit 81 | ``` 82 | Returns 0 for quit , 2 for no , 50 for bad user option 83 | 84 | 207) quit-NO prompt [Q/n] where no is default 85 | 86 | Keyword is quitno , returns codes based on user input 87 | second option no 88 | ```sh 89 | echo "Do you want to foo? [Q/n] :" 90 | bmtPromptFunc quitno no 91 | ``` 92 | Returns 0 for no , 2 for quit , 50 for bad user option 93 | 94 | 208) Wish to continue loop prompt 95 | Exits program if user presses N , continues if user presses yes. 96 | Param1 Message Custom. Param2 is colour, 97 | if no colour passed default is "bold cyan" 98 | 99 | ```sh 100 | bmtPromptFunc wishtocontinue "Do you wish to contine?" 101 | ```` 102 | 209) Print centred text in terminal 103 | 104 | ```sh 105 | bmtPromptFunc centertext "Hello World." 106 | ```` 107 | 108 | 210) Print an event status , Installing bashMultiTool ...... [OK] 109 | 110 | * Param 1 text on left 111 | * Param 2 text on right 112 | * Param 3 colour , if no colour passed default is "bold cyan" 113 | 114 | ```sh 115 | bmtPromptFunc eventstatus "Installing bashMultiTool" "OK" 116 | ```` 117 | -------------------------------------------------------------------------------- /documentation/bmtTest.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtTest | bmtTestFunc | 901 | Test | bmtTest.md | 4 | 5 | **Section nine, Test** 6 | 7 | Used to conduct semi-automated testing and test report of library function. 8 | 9 | -------------------------------------------------------------------------------- /documentation/bmtTime.md: -------------------------------------------------------------------------------- 1 | | Library file | Function | Sections | Content | help file | 2 | | ---- | ---- | ---- | ---- | ---- | 3 | | bmtTime | bmtTimeFunc | 701-710 | Timing related | bmtTime.md | 4 | 5 | **Section Seven, Time** 6 | 7 | * 701 Convert time to epoch time 8 | * 702 Print current time Stamp 9 | * 703 Spinner Animation multiple character for long non-verbose commands 10 | * 704 - 707 Stopwatch / timer 11 | * 708 Progress Bar 12 | * 709 Convert Epoch time to date format 13 | * 710 Spinner Animation single character for long non-verbose commands 14 | 15 | **Sub-Sections** 16 | 17 | 701) Converts passed date-time string to UNIX epoch time 18 | 19 | ```sh 20 | bmtTimeFunc epochconvert "2022-04-27 19:42:01 " 21 | ``` 22 | 23 | 702) Print current unix epoch time. 24 | 25 | ```sh 26 | bmtTimeFunc epochnow 27 | ``` 28 | 29 | 703) Spinner Animation for non-verbose process/commands that take long time 30 | 31 | ```sh 32 | # call spinner section put run in background and save PID 33 | bmtTimeFunc spin & 34 | pid=$! 35 | disown 36 | 37 | # 'do stuff' 38 | echo "START" 39 | find ~ -name mint 2>/dev/null 40 | echo "END" 41 | 42 | # Stop spin function with PID 43 | kill $pid 44 | sleep 2 45 | ``` 46 | 47 | 704-707) Stop watch 48 | 49 | Stop watch timer that returns value in seconds between the stop and start 50 | with a scale of 6. Mircoseconds 1.000000. 51 | startwatch creates a global variable called _BMT_START_WATCH 52 | and uses bc An arbitrary precision calculator language. 53 | 54 | ```sh 55 | bmtTimeFunc startWatch 56 | sleep 2.8 57 | bmtTimeFunc stopWatch 58 | # returns ~ 2.813207 59 | ``` 60 | 708) Progress Bar 61 | 62 | Parameter 1, time in seconds to increment bar 63 | 64 | Displays a progress bar the increment is passed by user 65 | The progress displays a percentage and a count of number of times 66 | percentage completed. 67 | 68 | ```sh 69 | echo " " 70 | echo "Test 708 " 71 | bmtTimeFunc progressbar 1 & 72 | pid=$! 73 | disown 74 | echo "START" 75 | sleep 25 # do stuff 25 seconds for one progress bar complete pass 76 | echo " " 77 | echo "END" 78 | # Stop spin function with PID 79 | kill $pid 80 | sleep 2 81 | echo " " 82 | ``` 83 | 84 | 709) Convert Epoch time to date format 85 | 86 | ```sh 87 | bmtTimeFunc dateformat "1651084921" "%FT%T%z" 88 | # prints ~ 2022-04-27T19:42:01+0100 89 | ``` 90 | 91 | 710) Spinner Animation, number two for long non-verbose commands 92 | 93 | ```sh 94 | # call spinner section put run in background and save PID 95 | bmtTimeFunc spintwo & 96 | pid=$! 97 | disown 98 | 99 | # 'do stuff' 100 | find ~ -name mint 2>/dev/null 101 | 102 | # Stop spintwo function with PID 103 | kill $pid 104 | sleep 2 105 | ``` 106 | -------------------------------------------------------------------------------- /documentation/misc/changelog.md: -------------------------------------------------------------------------------- 1 | 2 | Version control 3 | --------------------------- 4 | 5 | ### version 1.0-1 070118 6 | * first version 7 | 8 | ### version 1.1-2 200218 9 | * increased color printing options 10 | * increased sub-sections from 10 to 16 11 | * made library modular. multiple files 12 | 13 | ### version 1.2-3 280318 14 | * Added two new modes to printing options bringing total 15 | number of option to 56 (8 colours * 7 modes) 16 | * Increased number of sub-sections from 16 to 26 including stopwatch. 17 | 18 | ### version 1.4-5 040718 19 | * updating PPA to Ubuntu 18.04 LTS (Bionic Beaver) 20 | 21 | ### version 1.5-6 290718 22 | * Add script with meta data and help. 23 | * re-org of Documentation. 24 | 25 | ### version 1.7-8 04202020 26 | * updating PPA to Ubuntu 20.04 LTS (Focal Fossa) 27 | 28 | ### Version 2.0-1 28-04-2022 29 | * updating PPA to Ubuntu 22.04 LTS (Jammy Jellyfish) 30 | * Added 23 new sub-sections. 31 | 32 | ### Version 2.1-2 21-09-2022 33 | * Added 4 new sub-sections, 510 710 805 806. -------------------------------------------------------------------------------- /documentation/screenshot/colour_print_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/documentation/screenshot/colour_print_example.png -------------------------------------------------------------------------------- /documentation/screenshot/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/documentation/screenshot/example.png -------------------------------------------------------------------------------- /documentation/screenshot/output_test_print.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/documentation/screenshot/output_test_print.png -------------------------------------------------------------------------------- /documentation/screenshot/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/documentation/screenshot/test.png -------------------------------------------------------------------------------- /example/example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #==HEADER== 4 | # Title : Bashmultitool example.sh 5 | # Description: 6 | # A basic example file to show use of library shown in output screenshot 7 | # Readme.md 8 | # URL: https://github.com/gavinlyonsrepo/bashmultitool 9 | 10 | # Source the library 11 | LIBPATH="/usr/lib/bashmultitool/" 12 | for MYFILE in "$LIBPATH"*; 13 | do 14 | source "$MYFILE" 15 | done 16 | 17 | function Display_Func 18 | { 19 | bmtMiscFunc title 3 2 '#' "Bashmultitool library Demo" 20 | bmtMiscFunc drawbox 3 2 "A file to demo bash library" "Written by Gavin Lyons " 21 | bmtPromptFunc anykey "and download files " b_cyan 22 | bmtPromptFunc eventstatus "File 1 Download" "OK" b_green 23 | bmtPromptFunc eventstatus "File 2 Download" "Fail" b_red 24 | bmtPromptFunc eventstatus "File 3 Download" "Fail" b_red 25 | bmtPrintFunc b_cyan "Do you want to Log error? [y/n/q] :" 26 | bmtPromptFunc yesnoquit b_yellow 27 | case $? in 28 | 0) 29 | bmtPrintFunc b_red 30 | bmtLinuxFunc log "NOTICE" "File 2 failed" mylog /tmp/ "MES" 31 | bmtLinuxFunc log "NOTICE" "File 3 failed" mylog /tmp/ "MES" 32 | ;; 33 | 2) bmtPrintFunc norm "No logging done!" ;; 34 | 3) exit 1;; 35 | esac 36 | bmtPrintFunc b_cyan "Do you want to Upload log file ? [y/n/q] :" 37 | bmtPromptFunc yesnoquit b_yellow 38 | case $? in 39 | 0) 40 | bmtPrintFunc b_green "Uploading Log file" 41 | bmtTimeFunc progressbar 1 & 42 | pid=$! 43 | disown 44 | sleep 25 # do here stuff 45 | echo " " 46 | bmtPromptFunc eventstatus "Log File uploaded" "OK" b_green 47 | # Stop spin function with PID 48 | kill $pid 49 | ;; 50 | 2) : ;; 51 | 3) exit 1;; 52 | esac 53 | bmtPromptFunc anykey "to exit" b_cyan 54 | } 55 | 56 | #=== MAIN CODE === 57 | clear 58 | Display_Func 59 | # === END === 60 | -------------------------------------------------------------------------------- /lib/bmtData: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtData 5 | #Function: Contains Data utilities. 6 | #library name: bashmultitool 7 | #Written: Gavin Lyons 8 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 9 | 10 | # ===FUNCTIONS === 11 | function bmtDataFunc 12 | { 13 | 14 | case "$1" in 15 | 16 | intcheck) # 601 17 | if [[ "$2" != *[!0-9]* ]]; 18 | then 19 | #success an integer 20 | return 0 21 | fi 22 | ;; 23 | 24 | alphanumcheck) #602 25 | if [[ "$2" != *[!0-9a-zA-Z]* ]]; 26 | then 27 | #success an alpha numeric string 28 | return 0 29 | fi 30 | ;; 31 | 32 | alphacheck) # 603 33 | if [[ "$2" != *[!a-zA-Z]* ]]; 34 | then 35 | #success an alpha string 36 | return 0 37 | fi 38 | ;; 39 | 40 | # 604 41 | lowercase) 42 | echo "$2" | tr '[:upper:]' '[:lower:]' 43 | ;; 44 | 45 | # 605 46 | uppercase) 47 | echo "$2" | tr '[:lower:]' '[:upper:]' 48 | ;; 49 | 50 | # 606 51 | trim) 52 | : "${2#"${2%%[![:space:]]*}"}" 53 | : "${_%"${_##*[![:space:]]}"}" 54 | printf '%s\n' "$_" 55 | ;; 56 | 57 | #607 58 | strlen) 59 | [ -z "$2" ] && return 250 60 | return "$(printf "%s\\n" "${#2}")" 61 | ;; 62 | 63 | *) # Catch all users typos 64 | printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtData : bmtDataFunc" 65 | return 255 66 | ;; 67 | 68 | esac 69 | 70 | return 2 # needed default 71 | } 72 | 73 | -------------------------------------------------------------------------------- /lib/bmtFiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtFiles 5 | #Function: Contains file related utilities 6 | #library name: bashmultitool 7 | #Written: Gavin Lyons 8 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 9 | 10 | # === FUNCTIONS === 11 | 12 | function bmtFilesFunc 13 | { 14 | 15 | case "$1" in 16 | 17 | isdirempty) # 501 18 | if [ -d "$2" ]; then 19 | # the directory exists 20 | local checkVar=0 21 | checkVar=$(find "$2" -mindepth 1 -print | wc -l) 22 | if [ "$checkVar" == 0 ]; then 23 | return 0 #not empty 24 | else 25 | return 2 #empty 26 | fi 27 | else #dir does not exist 28 | return 3 29 | fi 30 | ;; 31 | 32 | makedir) #502 33 | # make dir makes a directory at path $2 with time/date stamp and enters it 34 | # appends $3 to directory name 35 | if [[ -d "$2" ]]; then 36 | cd "$2" || return 51 37 | local dirVar="" 38 | dirVar=$(date +%H%M-%d%b%y)"$3" 39 | mkdir -p "$dirVar" 40 | cd "$dirVar" || return 52 41 | printf '%s\n' "Directory made at:-" 42 | pwd 43 | return 0 44 | else 45 | return 50 46 | fi 47 | ;; 48 | 49 | directoryexists) # 503 50 | if [[ -d "$2" ]]; then 51 | return 0 52 | fi 53 | return 2 54 | ;; 55 | 56 | fileexists) #504 57 | if [[ -f "$2" ]]; then 58 | return 0 59 | fi 60 | return 2 61 | ;; 62 | 63 | deviceexists) # 505 64 | if [[ -b "$2" ]]; then 65 | return 0 66 | fi 67 | return 2 68 | ;; 69 | 70 | isfileempty) # 506 71 | if [ -s "$2" ]; then 72 | return 0 #not empty 73 | else 74 | return 2 75 | fi 76 | ;; 77 | 78 | getfilesize) #507 79 | if [[ -f "$2" ]]; then 80 | du -h "$2" | cut -f1 81 | return 0 82 | fi 83 | return 2 84 | ;; 85 | 86 | getfilesizebytes) #508 87 | if [[ -f "$2" ]]; then 88 | wc -c "$2" | cut -d ' ' -f1 89 | return 0 90 | fi 91 | return 2 92 | ;; 93 | 94 | getmimetype) #509 95 | [ -z "$2" ] && return 2 96 | 97 | local inputdata="${2}" 98 | local mime_output 99 | 100 | if [[ -f "$inputdata" ]] || [[ -d "$inputdata" ]]; then 101 | if type -p mimetype &> /dev/null; then 102 | mime_output=$(mimetype --output-format %m "$inputdata") 103 | elif type -p file &> /dev/null; then 104 | mime_output=$(file --brief --mime-type "$inputdata") 105 | else 106 | return 3 107 | fi 108 | else 109 | return 4 110 | fi 111 | 112 | printf "%s" "${mime_output}" 113 | ;; 114 | 115 | filename) #510 /tmp/text.txt 116 | [ -z "$2" ] && return 2 117 | case "$3" in 118 | 1) #510-1 full filename text.txt 119 | printf "%s" "${2##*/}" # parameter expansion retain after / 120 | ;; 121 | 2) #510-2 basename text 122 | local filename basename 123 | filename="${2##*/}" # parameter expansion retain after / 124 | basename="${filename%.*}" # parameter expansion retain before . 125 | printf "%s" "${basename}" 126 | ;; 127 | 3) #510.3 extension .txt 128 | local filename extension 129 | filename="${2##*/}" # parameter expansion retain after / 130 | extension="${filename##*.}" # parameter expansion after . 131 | [[ "${filename}" = "${extension}" ]] && return 4 132 | 133 | printf "%s" "${extension}" 134 | ;; 135 | 4) #folder path /tmp 136 | declare folderpath=${2:-.} 137 | folderpath=${2%/*} 138 | printf "%s" "${folderpath}" 139 | ;; 140 | *) 141 | return 3 142 | ;; 143 | esac 144 | return 0 145 | ;; 146 | 147 | *) # Catch all user typos 148 | printf '%s\n' "Error: Unknown keyword : bashmultitool :bmtFiles : bmtFilesFunc" 149 | return 255 150 | ;; 151 | 152 | esac 153 | 154 | } 155 | 156 | 157 | -------------------------------------------------------------------------------- /lib/bmtLinux: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtLinux 5 | #Function: Contains linux related utilities 6 | #library name: bashmultitool 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # === FUNCTIONS === 10 | 11 | function bmtLinuxFunc 12 | { 13 | local red 14 | red=$(printf "\033[0;31m") 15 | local normal 16 | normal=$(printf "\033[0m") 17 | local pacVar="" 18 | 19 | case "$1" in 20 | 21 | checkpac) # 401 check if package installed 22 | case "$3" in 23 | 1) # pacman based 24 | pacVar=$(pacman -Qqs "$2") 25 | ;; 26 | 27 | 2) # debian based 28 | pacVar=$(dpkg -l "$2" 2> /dev/null) 29 | ;; 30 | 31 | 3) # rpm based 32 | pacVar=$(rpm -qa | grep "$2" 2>/dev/null) 33 | ;; 34 | 35 | *) # unknown 36 | printf '%s\n' "Unsupported Linux distro" 37 | return 52 38 | ;; 39 | esac 40 | 41 | if [ -n "$pacVar" ] 42 | then #installed 43 | #if text input is MES print good install message 44 | if [ "$4" = "MES" ] 45 | then 46 | printf '%s\n' "$2 is Installed" 47 | fi 48 | return 0 49 | else #not installed 50 | #if text input is MES print install bad message 51 | if [ "$4" = "MES" ]; 52 | then 53 | printf '%s\n' "${red}$2 is Not installed ${normal}" 54 | fi 55 | return 2 56 | fi 57 | ;; 58 | 59 | distrocheck) #402 check what distro on 60 | if [ -f /etc/redhat-release ]; then 61 | # rpm based 62 | return 2 63 | elif [ -f /etc/fedora-release ]; then 64 | # fedora based 65 | return 3 66 | elif [ -f /etc/lsb-release ]; then 67 | # deb based 68 | return 4 69 | elif [ -d /etc/pacman.d ]; then 70 | # pacman based 71 | return 5 72 | elif [ -f /etc/gentoo-release ]; then 73 | # gentoo based 74 | return 6 75 | elif [ -f /etc/slackware-release ]; then 76 | # slackware based 77 | return 7 78 | else 79 | printf '%s\n' "UnKnown Linux distro" 80 | return 52 81 | fi 82 | ;; 83 | 84 | isTextEdSet) #403 set text editor 85 | if [ -z "${EDITOR}" ] 86 | then 87 | export EDITOR="vi" 88 | return 2 89 | else 90 | return 0 91 | fi 92 | ;; 93 | 94 | log) #404 95 | declare logdatfVar="%FT%T%z" 96 | local logstrVar="" 97 | local statusVar="$2" 98 | local logmsgVar="$3" 99 | logfileVar="$4.log" 100 | local dateVar 101 | dateVar=$(date +"$logdatfVar") 102 | 103 | # Check that $statusvar is valid 104 | case "$statusVar" in 105 | EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG|OK|FAILED|PASSED) : ;; 106 | *) printf '%s\n' "Error bmtLinux : log : Invalid state : $statusVar" 107 | return 55 ;; 108 | esac 109 | 110 | # Create the log message 111 | if [ -n "$logmsgVar" ] 112 | then 113 | logstrVar="$dateVar - $statusVar - $logmsgVar" 114 | else 115 | logstrVar="$dateVar -- empty log message" 116 | fi 117 | 118 | mkdir -p "$5" 119 | echo "$logstrVar" >> "$5$logfileVar" 120 | 121 | # If param 6 added echo as well as log 122 | [ "$6" = "MES" ] && echo "$logstrVar" 123 | return 0 124 | ;; 125 | 126 | user) #405 127 | [ -z "$2" ] && return 1 128 | if id -u "$2" >/dev/null 2>&1; then 129 | return 0 130 | else 131 | return 2 132 | fi 133 | ;; 134 | 135 | isvarempty) #406 136 | local var_name="$2" 137 | local var_value="${!var_name}" 138 | if [[ -v "$var_name" ]]; then 139 | if [[ -n "$var_value" ]]; then 140 | return 0 # "set and non-empty" 141 | else 142 | return 2 # "set and empty" 143 | fi 144 | else 145 | return 3 # "unset" 146 | fi 147 | ;; 148 | 149 | runasroot) #407 150 | if [[ ${EUID} -ne 0 ]]; then 151 | printf '%s\n' "${red} Error :: This script must run as root, program exiting! ${normal}" 152 | return 2 153 | else 154 | echo "Info :: Running as root" 155 | return 0 156 | fi 157 | ;; 158 | 159 | iscommand) #408 160 | hash "$2" 2>/dev/null || return 2 161 | return 0 162 | ;; 163 | 164 | *) # Catch all user typos 165 | printf '%s\n' "Error: Unknown keyword : bashmultitool :bmtLinux: bmtLinuxFunc" 166 | return 255 167 | ;; 168 | esac 169 | } 170 | -------------------------------------------------------------------------------- /lib/bmtMisc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # === HEADER === 3 | #FileName: bmtMisc 4 | #Function: Contains miscellaneous utilities. 5 | #library name: bashmultitool 6 | #Written: Gavin Lyons 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # ===FUNCTIONS === 10 | 11 | function bmtMiscFunc 12 | { 13 | 14 | case "$1" in 15 | 16 | password) #801 17 | local mylengthVar=0 18 | echo "Random Password generator :" 19 | if [ -z "$2" ]; then 20 | cd "/tmp/" || return 3 21 | echo "Output Path /tmp/" 22 | else 23 | cd "$2" || return 3 24 | echo "Output Path $2" 25 | fi 26 | touch passwordBMT.txt 27 | echo "Enter length:-" 28 | read -r mylengthVar 29 | # if just enter pressed set default 20 30 | if [ -z "$mylengthVar" ]; then 31 | mylengthVar=20 32 | fi 33 | #check integer 34 | if [[ "$mylengthVar" != *[!0-9]* ]];then 35 | echo -n "$(< /dev/urandom tr -dc "_*?#!A-Z-a-z-0-9" | head -c "$mylengthVar";)">passwordBMT.txt 36 | echo "Password generated" 37 | return 0 38 | else 39 | return 2 40 | fi 41 | ;; 42 | 43 | getbatlevel) #802 44 | local Filepath="/sys/class/power_supply/$2/capacity" 45 | if ! [[ -f $Filepath ]]; then 46 | echo "File '$Filepath' not found." 47 | return 127 48 | elif ! [[ -r $Filepath ]]; then 49 | echo "File '$Filepath' unreadable." 50 | return 128 51 | fi 52 | 53 | read -r < "/sys/class/power_supply/$2/capacity" 54 | if [ "$3" = "MES" ] 55 | then 56 | printf 'Battery is at %d%% capacity.\n' "$REPLY" # Reply is built into read. 57 | fi 58 | return "$REPLY" 59 | ;; 60 | 61 | drawbox) #803 62 | local width 63 | local place 64 | local textarray=("$@") 65 | local colorbox="$2" 66 | local colortext="$3" 67 | local inputparam 68 | 69 | # remove color's and subsection name from array 70 | for inputparam in 0 1 2 71 | do 72 | unset 'textarray[inputparam]' 73 | done 74 | 75 | #${s[@]} – all elements of array s; ((width<${#l})) – ((..)) shell arithmetic testing 76 | #whether variable width's value is less than variable l value's length, obtained 77 | #with parameter expansion (# – string length); ${place//?/-} – parameter expansion 78 | #replacing all occurrences of any character with a “-” (// – replace all; ? – 79 | #wildcard meaning any character). 80 | for word in "${textarray[@]}"; do 81 | ((width<${#word})) && { place="$word"; width="${#word}"; } 82 | done 83 | tput setaf "$colorbox" 84 | echo -e " -${place//?/-}-\n| ${place//?/ } |" 85 | for word in "${textarray[@]}"; do 86 | printf '| %s%*s%s |\n' "$(tput setaf "$colortext")" "-$width" "$word" "$(tput setaf "$colorbox")" 87 | done 88 | echo -e "| ${place//?/ } |\n -${place//?/-}-" 89 | tput sgr 0 90 | ;; 91 | 92 | title) 93 | local colorbox="$2" 94 | local colortext="$3" 95 | local bannersymbol="$4" 96 | local textmsg="$5" 97 | local edge 98 | 99 | edge=$(echo "$textmsg####" | sed "s/./$bannersymbol/g") 100 | 101 | tput setaf "$colorbox" 102 | printf '%s\n' "$edge" 103 | printf '%s%s%s%s%s\n' "$bannersymbol " "$(tput setaf "$colortext")" "$textmsg" "$(tput setaf "$colorbox")" " $bannersymbol" 104 | printf '%s\n' "$edge" 105 | tput sgr 0 106 | 107 | ;; 108 | 109 | centertext) 110 | local banner outputtext 111 | local inputtext=" ${2} " bannersymbol="${3:- }" 112 | local stringlength=${#inputtext} 113 | local bannerlength="$((($(tput cols) - stringlength) / 2))" 114 | 115 | [[ -n "${bannersymbol}" ]] && bannersymbol="${bannersymbol:0:1}" 116 | for ((i = 0; i < bannerlength; i++)); do 117 | banner+="${bannersymbol}" 118 | done 119 | 120 | outputtext="${banner}${inputtext}${banner}" 121 | [[ $((($(tput cols) - stringlength) % 2)) -ne 0 ]] && outputtext+="${bannersymbol}" 122 | printf "%s" "${outputtext}" 123 | ;; 124 | 125 | gauge) 126 | local label="$2" 127 | local value="$3" 128 | local min="$4" 129 | local max="$5" 130 | local symbol="$6" 131 | local symbolempty="$7" 132 | 133 | printf "%s=%3d %d" "$label" "$value" "$min" 134 | echo -n "[" 135 | for ((i = min ; i <= value; i++)); do echo -n "$symbol"; done 136 | for ((j = value+1 ; j <= max ; j++)); do echo -n "$symbolempty"; done 137 | echo -n "]" 138 | printf "%d" "$max" 139 | echo 140 | ;; 141 | 142 | 143 | *) # Catch all users typos 144 | printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtMisc: bmtMiscFunc" 145 | return 255 146 | ;; 147 | esac 148 | } 149 | 150 | -------------------------------------------------------------------------------- /lib/bmtNetwork: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtNetwork 5 | #Function: Contains network related functions 6 | #library name: bashmultitool 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # === FUNCTIONS === 10 | 11 | function bmtNetworkFunc 12 | { 13 | local red 14 | red=$(printf "\033[0;31m") 15 | local normal 16 | normal=$(printf "\033[0m") 17 | 18 | case "$1" in 19 | 20 | checknet) # 301 heck if website up 21 | #This uses netcat (nc) in its port scan mode, 22 | #a quick poke (-z is zero-I/O mode [used for 23 | #scanning]) with a quick timeout 24 | #(-w 1 waits at most one second 25 | #It checks passed website $1 on port 80 (HTTP). 26 | if nc -zw1 "$2" 80 2>>/tmp/bmtchecknet.log ; then 27 | if [ "$3" != "NOMES" ] 28 | then 29 | printf '%s\n' "We have connectivity $2" 30 | fi 31 | return 0 32 | else 33 | if [ "$3" != "NOMES" ] 34 | then 35 | printf '%s\n' "${red}We do not have connectivity $2 ${normal}" 36 | fi 37 | return 2 38 | fi 39 | ;; 40 | 41 | weather) # 302 42 | local mycityVar="$2" 43 | local myformat="$3" 44 | wget -qO - wttr.in/"$mycityVar"?format="$myformat" 45 | ;; 46 | 47 | *) # Catch all users typos 48 | printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtNetwork: bmtNetworkFunc" 49 | return 255 50 | ;; 51 | esac 52 | } 53 | 54 | -------------------------------------------------------------------------------- /lib/bmtPrint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtPrint 5 | #Function: prints to screen 6 | #library name: bashmultitool 7 | #Written: Gavin Lyons 8 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 9 | 10 | # === FUNCTIONS === 11 | 12 | # Name: function for printing text , test 101 13 | # Process: Prints passed text "$2" in 7 modes and 8 colours 14 | # "$1" is keyword. return 0 for ok 255 for error 15 | 16 | function bmtPrintFunc 17 | { 18 | local -r normal=$(printf "\033[0m") # Text Reset 19 | local modeVar="" # hold the mode 20 | local colorVar="" # hold the color 21 | local printVar="" 22 | 23 | # Normal text with reset 24 | if [ "$1" = "norm" ] 25 | then 26 | printf '%s\n' "${normal}$2" 27 | return 0 28 | fi 29 | 30 | # check for "_" i.e. for regular text mode 31 | if [[ "$1" != *"_"* ]]; then 32 | modeVar="n" #r for regular 33 | colorVar="$1" 34 | else 35 | local strVar="$1" 36 | # Extract from this string using parameter expansion 37 | modeVar=${strVar%_*} # Retain before the colon for code 38 | colorVar=${strVar##*_} # retain after the colon for colour 39 | fi 40 | 41 | # Get mode 42 | case $modeVar in 43 | n) modeVar="\033[0;3";; # normal 44 | b) modeVar="\033[1;3";; # Bold 45 | u) modeVar="\033[4;3";; # Underline 46 | bg) modeVar="\033[4";; # background 47 | i) modeVar="\033[0;9";; # high intensity 48 | bh) modeVar="\033[1;9";; # high intensity bold 49 | hbg) modeVar="\033[0;10";; # High intensity backgrounds 50 | *) # Catch user typos 51 | printf '%s\n' "1 Error: Unknown keyword $1 : bashmultitool: bmtPrint: bmtPrintFunc" 52 | return 255 53 | ;; 54 | esac 55 | 56 | # get colour 57 | case $colorVar in 58 | black)colorVar="0m";; 59 | red)colorVar="1m";; 60 | green)colorVar="2m";; 61 | yellow)colorVar="3m";; 62 | blue)colorVar="4m";; 63 | purple)colorVar="5m";; 64 | cyan)colorVar="6m";; 65 | white)colorVar="7m";; 66 | *) # Catch user typos 67 | printf '%s\n' "Error: Unknown keyword $1 : bashmultitool: bmtPrint: bmtPrintFunc" 68 | return 255 69 | ;; 70 | esac 71 | 72 | # add mode + color strings and print text 73 | #if no text don't print Carriage return or reset for just color change 74 | printVar=$(printf "%s""$modeVar$colorVar") 75 | if [ -n "$2" ] 76 | then 77 | printf '%s\n' "${printVar}$2${normal}" 78 | else 79 | printf '%s' "${printVar}$2" 80 | fi 81 | return 0 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /lib/bmtPrompt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtPrompt 5 | #Function: Contains various screen prompts for user. 6 | #library name: bashmultitool 7 | #Written: Gavin Lyons 8 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 9 | 10 | # === FUNCTIONS === 11 | 12 | function bmtPromptFunc 13 | { 14 | local normal 15 | normal=$(printf "\033[0m") 16 | local colorVar="" 17 | 18 | case "$1" in 19 | 20 | line) #201 print cyan horizontal line of $2 i.e ====== 21 | if [ -n "$3" ] 22 | then 23 | colorVar="$3" 24 | else 25 | colorVar="b_cyan" 26 | fi 27 | bmtPrintFunc "$colorVar" 28 | printf "%*s\n" "${COLUMNS:-$(tput cols)}" '' | tr ' ' "$2" 29 | printf '%s' "${normal}" 30 | ;; 31 | 32 | anykey) #205 any key cyan prompt, appends second text input to prompt 33 | if [ -n "$3" ] 34 | then 35 | colorVar="$3" 36 | else 37 | colorVar="b_cyan" 38 | fi 39 | bmtPrintFunc "$colorVar" 40 | read -n 1 -r -s -p "Press any key to continue $2" 41 | printf '%s\n' "${normal}" 42 | ;; 43 | 44 | yesnoquit) #202 print yes no quit prompt [y/n/q] 45 | if [ -n "$2" ] 46 | then 47 | colorVar="$2" 48 | else 49 | colorVar="b_cyan" 50 | fi 51 | local yesnoVar="" 52 | while true; do 53 | read -r yesnoVar 54 | case $yesnoVar in 55 | [Yy]*) return 0;; 56 | [Nn]*) return 2;; 57 | [Qq]*) return 3;; 58 | *) bmtPrintFunc "$colorVar" "Please answer: (y/Y for yes) OR (n/N for no) OR (q/Q to quit)!" ;; 59 | esac 60 | done 61 | ;; 62 | 63 | yesno) #203 204 print yes no prompt [y/N] or [Y/n] $2 determines option 64 | local yesnoVar="" 65 | local choiceVar="" 66 | 67 | if [ "$2" = yes ]; then 68 | choiceVar="yY" 69 | elif [ "$2" = no ]; then 70 | choiceVar="nN" 71 | else 72 | bmtPrintFunc norm "Error: Unknown Option to keyword yesno: bashmultitool, bmtPrompt, bmtPromptFunc" 73 | return 51 74 | fi 75 | 76 | while true; do 77 | read -r yesnoVar 78 | case $yesnoVar in 79 | ["$choiceVar"]*) return 0;; 80 | *) return 2;; 81 | esac 82 | done 83 | ;; 84 | 85 | quitno) #206 207 print quit or no prompt [q/N] or [Q/n] $2 determines option 86 | local quitnoVar="" 87 | local choiceVar="" 88 | 89 | if [ "$2" = quit ]; then 90 | choiceVar="qQ" 91 | elif [ "$2" = no ]; then 92 | choiceVar="nN" 93 | else 94 | bmtPrintFunc norm "Error: Unknown Option to keyword yesno: bashmultitool, bmtPrompt, bmtPromptFunc" 95 | return 51 96 | fi 97 | 98 | while true; do 99 | read -r quitnoVar 100 | case $quitnoVar in 101 | ["$choiceVar"]*) return 0;; 102 | *) return 2;; 103 | esac 104 | done 105 | ;; 106 | 107 | #208 do you wish to continue 108 | wishtocontinue) 109 | if [ -n "$3" ] 110 | then 111 | colorVar="$3" 112 | else 113 | colorVar="b_cyan" 114 | fi 115 | 116 | local message="$2" 117 | local waitingforanswer=true 118 | local ynanswer="" 119 | bmtPrintFunc "$colorVar" 120 | 121 | while "$waitingforanswer"; do 122 | read -r -p "$message :: Press 'y/Y' to continue, 'n/N' to Exit::" ynanswer 123 | case "$ynanswer" in 124 | [Yy] ) waitingforanswer=false; break;; 125 | [Nn] ) exit 1;; 126 | *) echo "Please answer either (y/Y) or (n/N).";; 127 | esac 128 | done 129 | echo "" 130 | printf '%s' "${normal}" 131 | ;; 132 | 133 | centertext) #209 print centred text on screen 134 | printf "%*s\n" $(((${#2}+$(tput cols))/2)) "$2" 135 | ;; 136 | 137 | eventstatus) #210 print event status on screen i.e. event ..... [ status ] 138 | [ -z "$2" ] && return 2 139 | [ -z "$3" ] && return 2 140 | if [ -n "$4" ] 141 | then 142 | colorVar="$4" 143 | else 144 | colorVar="b_cyan" 145 | fi 146 | 147 | local symbol="." 148 | local noofdots printlength fulloutput symbolline termlength 149 | local input1="${2} " 150 | local input2="${3}" 151 | 152 | bmtPrintFunc "$colorVar" 153 | input2="[ $input2 ]" 154 | termlength=${COLUMNS:-$(tput cols)} 155 | printlength=$(( termlength - ( ${#input1} + ${#input2} ) )) 156 | symbolline="$(printf '%*s' $printlength '')" 157 | noofdots=${symbolline// /${symbol}} 158 | fulloutput="${input1}${noofdots}${input2}" 159 | 160 | printf "%s\n" "${fulloutput}" 161 | ;; 162 | 163 | *) # Catch all users typos 164 | bmtPrintFunc norm "Error: Unknown keyword : bashMultiTool: bmtPrompt : bmtPromptFunc" 165 | return 255 166 | ;; 167 | 168 | esac 169 | } 170 | -------------------------------------------------------------------------------- /lib/bmtTest: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtTest 5 | #Function: Contains a test function for automated testing library 6 | #library name: bashmultitool 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # === FUNCTIONS === 10 | 11 | function bmtTestFunc 12 | { 13 | 14 | local urlTestDir="$HOME/Documents/Tech/Scripts/BashMultiTool/test/testlog/" 15 | mkdir -p "$urlTestDir" 16 | local TestFile="test" 17 | 18 | case "$3" in 19 | START) # Start message 20 | printf "%s\n" "=== Start Automatic Tests === " 21 | bmtPrintFunc norm "Delete log file if exists" 22 | rm -iv "$urlTestDir""$TestFile.log" 23 | bmtLinuxFunc log "NOTICE" "Run Start" "$TestFile" "$urlTestDir" ;; 24 | END) 25 | # End message 26 | if [ "$3" == "END" ] 27 | then 28 | bmtLinuxFunc log "NOTICE" "Run Over" "$TestFile" "$urlTestDir" 29 | bmtPrintFunc norm "=== End Automatic Tests ===" 30 | bmtPromptFunc anykey " " norm 31 | clear 32 | bmtMiscFunc title 14 226 "#" " BashMultiTool library :: Test Results :: $TestFile.log " 33 | bmtPromptFunc eventstatus "Test Total" "$(grep -c "Test" "$urlTestDir""$TestFile.log" )" b_white 34 | bmtPromptFunc eventstatus "Test Passed" "$(grep -c "PASSED" "$urlTestDir""$TestFile.log" )" b_green 35 | bmtPromptFunc eventstatus "Test Failed" "$(grep -c "FAILED" "$urlTestDir""$TestFile.log" )" b_red 36 | bmtPromptFunc eventstatus "Test Errors" "$(grep -c "ERROR" "$urlTestDir""$TestFile.log" )" b_yellow 37 | bmtPromptFunc line "=" 38 | 39 | # View File 40 | bmtPromptFunc anykey "and view test log file." norm 41 | cat "$urlTestDir""$TestFile.log" 42 | bmtPromptFunc line "=" 43 | bmtPromptFunc anykey "and delete test log file." norm 44 | #remove file? 45 | rm -iv "$urlTestDir""$TestFile.log" 46 | bmtPromptFunc line "=" 47 | fi 48 | ;; 49 | *) 50 | if [ "$4" == "NOAUTO" ] # non -automatic test 51 | then 52 | local yesnoVar="" 53 | while true; do 54 | bmtPrintFunc norm "Did Test $3 pass? [y/n/q]" 55 | read -r yesnoVar 56 | case $yesnoVar in 57 | [Yy]*) bmtLinuxFunc log "PASSED" "Test $3 Result :: User Check" "$TestFile" "$urlTestDir" && return 0;; 58 | [Nn]*) bmtLinuxFunc log "FAILED" "Test $3 Result :: User Check" "$TestFile" "$urlTestDir" && return 2;; 59 | [Qq]*) 60 | bmtLinuxFunc log "ERROR" "User aborted Test at $3" "$TestFile" "$urlTestDir" 61 | return 3 62 | ;; 63 | *) bmtPrintFunc b_yellow "Please answer: (y/Y for yes) OR (n/N for no) OR (q/Q to quit)!";; 64 | esac 65 | done 66 | else 67 | if [ "$1" -eq "$2" ] # Automatic test 68 | then 69 | bmtLinuxFunc log "PASSED" "Test $3 Result :: $1 $2" "$TestFile" "$urlTestDir" 70 | return 0 71 | else 72 | bmtLinuxFunc log "FAILED" "Test $3 Result :: $1 $2" "$TestFile" "$urlTestDir" 73 | return 2 74 | fi 75 | fi 76 | ;; 77 | esac 78 | } 79 | 80 | -------------------------------------------------------------------------------- /lib/bmtTime: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | #FileName: bmtTime 5 | #Function: Contains time related utilities. 6 | #library name: bashmultitool 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # === FUNCTIONS === 10 | 11 | function bmtTimeFunc 12 | { 13 | 14 | case "$1" in 15 | 16 | epochconvert) # 701 17 | [ -z "$2" ] && return 2 18 | local date 19 | date=$(date -d "$2" +"%s") || return 3 20 | printf "%s" "${date}" 21 | ;; 22 | 23 | epochnow) # 702 24 | local now 25 | now="$(date --universal +%s)" || return 2 26 | printf "%s" "${now}" 27 | ;; 28 | 29 | spin) # 703 animation 30 | local spinner=( Ooooo oOooo ooOoo oooOo ooooO oooOo ooOoo oOooo); 31 | while true; do 32 | for i in "${spinner[@]}"; 33 | do 34 | # no new line , \r reset line 35 | echo -ne "\r$i"; 36 | sleep 0.2; 37 | done; 38 | done 39 | ;; 40 | 41 | # 704 Displays the current timestamp 42 | now) date +%s%N ;; 43 | 44 | # 705 Displays the time elapsed between two times 45 | elapsed) 46 | local startVar="$2" 47 | local stopVar="$3" 48 | local diffVar="" 49 | #https://serverfault.com/questions/151109/how-do-i-get-current-unix-time-in-milliseconds-using-bash#151112 50 | diffVar=$(echo "scale=6;($stopVar - ${startVar})/(1*10^09)" | bc) 51 | echo "$diffVar" 52 | ;; 53 | 54 | # 706 Starts the timer 55 | startWatch) 56 | __BMT_START_WATCH=$(bmtTimeFunc now) 57 | ;; 58 | 59 | # 707 Stops the timer 60 | stopWatch) 61 | if [ -n "$__BMT_START_WATCH" ] 62 | then 63 | local stopWatchVar=0 64 | stopWatchVar=$(bmtTimeFunc now) 65 | bmtTimeFunc elapsed "$__BMT_START_WATCH" "$stopWatchVar" 66 | return 0 67 | else 68 | return 2 69 | fi 70 | ;; 71 | 72 | progressbar) #708 73 | local k 74 | local j 75 | local i 76 | local count 77 | local percent 78 | count=1 79 | 80 | [ -z "$2" ] && return 2 81 | 82 | while true; do 83 | for ((k = 1; k <= 25 ; k++)) 84 | do 85 | echo -n "[" 86 | for ((i = 0 ; i <= k; i++)); do echo -n "##"; done 87 | for ((j = i ; j <= 25 ; j++)); do echo -n ".."; done 88 | echo -n "] " 89 | percent=$((k * 4)) 90 | printf "%3d%% : %d\r" "$percent" "$count" 91 | sleep "$2" 92 | done 93 | count=$((count + 1)) 94 | done 95 | 96 | ;; 97 | 98 | dateformat) 99 | [ -z "$2" ] && return 2 100 | local timestamp formatstr output 101 | timestamp="$2" 102 | formatstr="${3:-"%F %T"}" 103 | output="$(date -d "@${timestamp}" +"${formatstr}")" || return 3 104 | printf "%s" "${output}" 105 | ;; 106 | 107 | spintwo) # 710 spinner two 108 | local spinner=("|" "/" "-" "\\" "\\"); 109 | while true; do 110 | for i in "${spinner[@]}"; 111 | do 112 | # no new line , \r reset line 113 | echo -ne "\r$i"; 114 | sleep 0.2; 115 | done; 116 | done 117 | ;; 118 | 119 | *) # Catch all users typos 120 | printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtTime: bmtTimeFunc" 121 | return 255 122 | ;; 123 | esac 124 | } 125 | 126 | -------------------------------------------------------------------------------- /main/bashmultitool: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # === HEADER === 4 | 5 | #name: Gavin Lyons 6 | #Title : Bashmultitool 7 | #Description: A Bash Shell library for commonly used functions 8 | # can be imported into shell scripts to create functional and colorful 9 | # scripts and Terminal users interfaces(TUI). This file is placeholder 10 | # for library with meta data 11 | #URL: https://github.com/gavinlyonsrepo/bashmultitool 12 | 13 | LIBPATH="/usr/lib/bashmultitool/" 14 | for MYFILE in "$LIBPATH"*; 15 | do 16 | source "$MYFILE" 17 | done 18 | 19 | # === FUNCTIONS === 20 | 21 | #FUNCTION HEADER 22 | # NAME : Bmt_Metadata_Func 23 | # DESCRIPTION : Function to display metadata on Bashmultitool 24 | 25 | function Bmt_Metadata_Func 26 | { 27 | bmtPromptFunc line "=" b_yellow 28 | bmtPrintFunc norm " Title : Bashmultitool" 29 | bmtPrintFunc norm " Description : A Bash Shell library file for commonly used functions 30 | can be imported into shell scripts to create functional and colorful 31 | scripts and Terminal users interfaces(TUI). " 32 | bmtPrintFunc norm " Version : 2.1-2" 33 | bmtPrintFunc norm " License: MIT" 34 | bmtPrintFunc norm " URL : https://github.com/gavinlyonsrepo/bashmultitool " 35 | bmtPrintFunc norm " Path : /usr/lib/bashmultitool" 36 | bmtPromptFunc line "=" b_yellow 37 | bmtPromptFunc anykey "and exit." b_yellow 38 | } 39 | 40 | #==MAIN CODE== 41 | echo " " 42 | Bmt_Metadata_Func 43 | echo " " 44 | #==END == 45 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | 2 | PREFIX ?= /usr 3 | 4 | all: 5 | @echo Run \'make install\' to install bashmultitool. 6 | @echo 'or' 7 | @echo Run \'make uninstall\' to uninstall bashmultitool. 8 | 9 | install: 10 | 11 | @echo 'Installing bashmultitool ... ' 12 | @echo 'Making directory...' 13 | @mkdir -vp $(PREFIX)/lib/bashmultitool/ 14 | @mkdir -vp $(PREFIX)/share/doc/bashmultitool/ 15 | 16 | @echo 'Installing software...' 17 | @cp -vp lib/* $(PREFIX)/lib/bashmultitool/ 18 | @cp -vp main/bashmultitool $(PREFIX)/bin 19 | @chmod 755 $(PREFIX)/bin/bashmultitool 20 | 21 | @echo 'Installing Documentation...' 22 | @cp -vp README.md $(PREFIX)/share/doc/bashmultitool/ 23 | @cp -vp documentation/bmt* $(PREFIX)/share/doc/bashmultitool/ 24 | 25 | @echo 'DONE!' 26 | 27 | uninstall: 28 | @echo 'uninstalling bashmultitool ... ' 29 | @echo 'uninstalling software...' 30 | @rm -vf $(PREFIX)/bin/bashmultitool 31 | @rm -vf $(PREFIX)/lib/bashmultitool/bmt* 32 | @echo 'uninstalling Documentation...' 33 | @rm -vf $(PREFIX)/share/doc/bashmultitool/*.md 34 | @echo 'DONE!' 35 | -------------------------------------------------------------------------------- /test/testObjects/NonEmptyDir/text.txt: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /test/testObjects/dummyfile.foofoo: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /test/testObjects/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/test/testObjects/empty.txt -------------------------------------------------------------------------------- /test/testObjects/full.txt: -------------------------------------------------------------------------------- 1 | test -------------------------------------------------------------------------------- /test/testObjects/tv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/22552b619854b31a8a4188ce95de1374b8cf3f27/test/testObjects/tv.png -------------------------------------------------------------------------------- /test/testTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #shellcheck disable=SC1090 # source "$MYFILE" 3 | 4 | # === HEADER === 5 | #Name: testTest.sh 6 | #Description: File to run Automatic tests on library bashmultitool 7 | #URL: https://github.com/gavinlyonsrepo/BashMultiTool 8 | 9 | # === FUNCTIONS === 10 | 11 | function testprintFunc 12 | { 13 | printf "%s\n" "=== Start Print Tests === " # Section 1 14 | #error handling check(catch typos) 10E 15 | echo "Error handling" 16 | bmtPrintFunc 17 | bmtTestFunc "$?" 255 "10E-a" 18 | bmtPrintFunc foofoo 19 | bmtTestFunc "$?" 255 "10E-b" 20 | 21 | #print text 22 | 23 | #reg 1 24 | echo 25 | bmtPrintFunc norm "reg colours" 26 | echo 27 | bmtPrintFunc black "black" 28 | bmtPrintFunc red "red " 29 | bmtPrintFunc green "green " 30 | bmtPrintFunc yellow "yellow" #tan 31 | bmtPrintFunc blue "blue " 32 | bmtPrintFunc purple "purple " 33 | bmtPrintFunc cyan "cyan " 34 | bmtPrintFunc white "white " #light grey 35 | 36 | #bold 2 37 | echo 38 | bmtPrintFunc norm "bold colours" 39 | echo 40 | bmtPrintFunc b_black "bold black " #dark grey 41 | bmtPrintFunc b_red "bold red " 42 | bmtPrintFunc b_green "bold green " 43 | bmtPrintFunc b_yellow "bold yellow " 44 | bmtPrintFunc b_blue "bold blue " 45 | bmtPrintFunc b_purple "bold purple " 46 | bmtPrintFunc b_cyan "bold cyan " 47 | bmtPrintFunc b_white "bold white " 48 | 49 | # underline 3 50 | echo 51 | bmtPrintFunc norm "underline colours" 52 | echo 53 | bmtPrintFunc u_black "underline black " 54 | bmtPrintFunc u_red "underline red" 55 | bmtPrintFunc u_green "underline green " 56 | bmtPrintFunc u_yellow "underline yellow " 57 | bmtPrintFunc u_blue "underline blue " 58 | bmtPrintFunc u_purple "underline purple " 59 | bmtPrintFunc u_cyan "underline cyan " 60 | bmtPrintFunc u_white "underline white " 61 | 62 | # background 4 63 | echo 64 | bmtPrintFunc norm "background colours" 65 | echo 66 | bmtPrintFunc bg_black "background black " 67 | bmtPrintFunc bg_red "background red " 68 | bmtPrintFunc bg_green "background green " 69 | bmtPrintFunc bg_yellow "background yellow " 70 | bmtPrintFunc bg_blue "background blue " 71 | bmtPrintFunc bg_purple "background purple " 72 | bmtPrintFunc bg_cyan "background cyan " 73 | bmtPrintFunc bg_white "background white " #very light grey 74 | 75 | # high intensity bold 5 76 | echo 77 | bmtPrintFunc norm "high intensity colours" 78 | echo 79 | bmtPrintFunc i_black "high intensity black " #very dark grey 80 | bmtPrintFunc i_red "high intensity red " 81 | bmtPrintFunc i_green "high intensity green " 82 | bmtPrintFunc i_yellow "high intensity yellow " 83 | bmtPrintFunc i_blue "high intensity blue " 84 | bmtPrintFunc i_purple "high intensity purple " 85 | bmtPrintFunc i_cyan "high intensity cyan " 86 | bmtPrintFunc i_white "high intensity white " 87 | 88 | # high intensity bold 6 89 | echo 90 | bmtPrintFunc norm "high intensity bold colours" 91 | echo 92 | bmtPrintFunc bh_black "high intensity bold black " #very dark grey 93 | bmtPrintFunc bh_red "high intensity bold red " 94 | bmtPrintFunc bh_green "high intensity bold green " 95 | bmtPrintFunc bh_yellow "high intensity bold yellow " 96 | bmtPrintFunc bh_blue "high intensity bold blue " 97 | bmtPrintFunc bh_purple "high intensity bold purple " 98 | bmtPrintFunc bh_cyan "high intensity bold cyan " 99 | bmtPrintFunc bh_white "high intensity bold white " 100 | 101 | # high intensity bold 7 102 | echo 103 | bmtPrintFunc norm "high intensity background colours" 104 | echo 105 | bmtPrintFunc hbg_black "high intensity background black " #light grey 106 | bmtPrintFunc hbg_red "high intensity background red " 107 | bmtPrintFunc hbg_green "high intensity background green " 108 | bmtPrintFunc hbg_yellow "high intensity background yellow " 109 | bmtPrintFunc hbg_blue "high intensity background blue " 110 | bmtPrintFunc hbg_purple "high intensity background purple " 111 | bmtPrintFunc hbg_cyan "high intensity background cyan " 112 | bmtPrintFunc hbg_white "high intensity background white " # very light grey 113 | bmtTestFunc 1 1 "101-a" "NOAUTO" 114 | } 115 | 116 | function testpromptFunc 117 | { 118 | printf "%s\n" "=== Start Prompt Tests === " # Section 2 119 | #error handling check(catch user typos) 120 | echo "Error handling :: " 121 | bmtPromptFunc 122 | bmtTestFunc "$?" 255 "20E-a" 123 | bmtPromptFunc foo 124 | bmtTestFunc "$?" 255 "20E-b" 125 | 126 | #draw a line 201 127 | printf "\n%s\n" "Test 201 :: Draw Line " 128 | bmtPromptFunc line "=" red 129 | printf "%s\n" "Before Line" 130 | bmtPromptFunc line "+" 131 | printf "%s\n\n" "After line" 132 | 133 | bmtPromptFunc line "=" green 134 | bmtPromptFunc line "#" b_cyan 135 | bmtTestFunc 1 1 "201-a" "NOAUTO" 136 | 137 | # Associate key value array' to hold expected prompt return values 138 | declare -A resArr res1Arr res2Arr res3Arr res4Arr 139 | local key 140 | 141 | # yesnoquit 202 142 | resArr+=( ["y"]=0 ["n"]=2 ["q"]=3) 143 | printf "%s\n" "Test 202 :: yesnoquit" 144 | for key in "${!resArr[@]}"; do 145 | printf "%s\n" "press ${key} [y/n/q] :-" 146 | bmtPromptFunc yesnoquit b_yellow 147 | bmtTestFunc "$?" "${resArr[${key}]}" "202-${key}" 148 | done 149 | 150 | # yesno yes 203 [ y/N], return 0 for yes 151 | # 'a' here represents "any other key" 152 | res1Arr+=( ["y"]=0 ["n"]=2 ["a"]=2 ) 153 | printf "\n%s\n" "Test 203 :: yesno yes" 154 | for key in "${!res1Arr[@]}"; do 155 | printf "%s\n" "press ${key} [y/N] :-" 156 | bmtPromptFunc yesno yes 157 | bmtTestFunc "$?" "${res1Arr[${key}]}" "203-${key}" 158 | done 159 | 160 | # yesno no 204 [Y/n], return 0 for no 161 | # 'a' here represents "any other key" 162 | res2Arr+=( ["y"]=2 ["n"]=0 ["a"]=2 ) 163 | printf "\n%s\n" "Test 204 :: yesno no" 164 | for key in "${!res2Arr[@]}"; do 165 | printf "%s\n" "press ${key} [Y/n] :-" 166 | bmtPromptFunc yesno no 167 | bmtTestFunc "$?" "${res2Arr[${key}]}" "204-${key}" 168 | done 169 | 170 | # user type catch 203 & 204 171 | printf "\n%s\n" "catch user type keyword for test 203 & 204" 172 | bmtPromptFunc yesno foofoo 173 | bmtTestFunc "$?" 51 "204-d" 174 | 175 | # anykey prompt 205 176 | printf "\n%s\n" "Test 205-a anykey test " 177 | bmtPromptFunc anykey "" u_green 178 | echo "my text here" 179 | bmtPromptFunc anykey " and go on to next step" 180 | echo "my text here" 181 | bmtTestFunc 1 1 "205-a" "NOAUTO" 182 | 183 | # quitno quit 206 [ q/N], return 0 for quit 184 | # 'a' here represents "any other key" 185 | res3Arr+=( ["q"]=0 ["n"]=2 ["a"]=2 ) 186 | printf "\n%s\n" "Test 206 :: quitno quit" 187 | for key in "${!res3Arr[@]}"; do 188 | printf "%s\n" "press ${key} [q/N] :-" 189 | bmtPromptFunc quitno quit 190 | bmtTestFunc "$?" "${res3Arr[${key}]}" "206-${key}" 191 | done 192 | 193 | #quitno no 207 [Q/n] : return 0 for no 194 | # 'a' here represents "any other key" 195 | res4Arr+=( ["q"]=2 ["n"]=0 ["a"]=2 ) 196 | printf "\n%s\n" "Test 207 :: quitno no" 197 | for key in "${!res4Arr[@]}"; do 198 | printf "%s\n" "press ${key} [Q/n] :-" 199 | bmtPromptFunc quitno no 200 | bmtTestFunc "$?" "${res4Arr[${key}]}" "207-${key}" 201 | done 202 | 203 | # user type catch 206 & 207 204 | printf "\n%s\n" "Catch user type keyword for test 206 & 207" 205 | bmtPromptFunc quitno foofoo 206 | bmtTestFunc "$?" 51 "207-d" 207 | 208 | #208 209 | printf "\n%s\n" "Test 208" 210 | bmtPromptFunc wishtocontinue "Do you wish to continue?" b_yellow 211 | bmtTestFunc "$?" 0 "208-a" 212 | printf "\n%s\n" "Continued " 213 | 214 | #209 215 | printf "\n%s\n" "Test 209 center text" 216 | bmtPromptFunc centertext "Hello World." 217 | bmtTestFunc 1 1 "209-a" "NOAUTO" 218 | 219 | #210 220 | printf "\n%s\n" "Test 210 event status" 221 | bmtPromptFunc eventstatus "Installing bashMultiTool" "OK" b_green 222 | bmtPromptFunc eventstatus "File upload" "Fail" b_red 223 | bmtPromptFunc eventstatus "File upload" "Pending" 224 | bmtTestFunc 1 1 "210-a" "NOAUTO" 225 | 226 | } 227 | 228 | function testnetworkFunc 229 | { 230 | printf "|\n%s\n" "=== Start Network Tests === " # Section 3 231 | # error handling check(catch typos) 232 | echo "Error handling" 233 | bmtNetworkFunc 234 | bmtTestFunc "$?" 255 "30E-a" 235 | bmtNetworkFunc foo 236 | bmtTestFunc "$?" 255 "30E-b" 237 | 238 | # 301 checknet 239 | echo " " 240 | echo "Test 301 " 241 | bmtNetworkFunc checknet "www.google.ie" 242 | bmtTestFunc "$?" 0 "301-a" 243 | bmtNetworkFunc checknet "www.fgfoofoondoid4gnd.ie" 244 | bmtTestFunc "$?" 2 "301-b" 245 | bmtNetworkFunc checknet "www.google.ie" "NOMES" 246 | bmtTestFunc "$?" 0 "301-c" 247 | bmtNetworkFunc checknet "www.ggleff11199g.ie" "NOMES" 248 | bmtTestFunc "$?" 2 "301-d" 249 | 250 | # 302 251 | echo " " 252 | echo "Test 302 " 253 | bmtNetworkFunc weather Cork 4 254 | bmtTestFunc "$?" 0 "302-a" 255 | } 256 | 257 | function testlinuxFunc 258 | { 259 | printf "\n%s\n" "=== Start Linux Tests === " # Section 4 260 | #check for bad user input 261 | bmtLinuxFunc foo 262 | bmtTestFunc "$?" 255 "40E-a" 263 | bmtLinuxFunc foo 264 | bmtTestFunc "$?" 255 "40E-b" 265 | 266 | # checkpac 267 | printf "\n%s\n" "check packages 401" 268 | bmtLinuxFunc checkpac "cylondeb" 2 #installed package 269 | bmtTestFunc "$?" 0 "401-a" 270 | bmtLinuxFunc checkpac "foooodds" 2 #non installed package 271 | bmtTestFunc "$?" 2 "401-b" 272 | 273 | bmtLinuxFunc checkpac "cylondeb" 2 "MES" #installed package 274 | bmtTestFunc "$?" 0 "401-c" 275 | bmtLinuxFunc checkpac "fooigkfnmgi" 2 "MES" #non installed package 276 | bmtTestFunc "$?" 2 "401-d" 277 | 278 | 279 | # distrocheck 280 | printf "\n%s\n" " Check distro 402" 281 | bmtLinuxFunc distrocheck 282 | bmtTestFunc "$?" 4 "402-a" 283 | 284 | 285 | # env text editor check 286 | echo 287 | printf "\n%s\n" "Is text editor set? 403" 288 | echo "$EDITOR" 289 | bmtLinuxFunc isTextEdSet 290 | echo "$?" 291 | echo "$EDITOR" 292 | bmtTestFunc 1 1 "403-a" "NOAUTO" 293 | 294 | # logfile 295 | printf "\n%s\n" "logfile 404" 296 | # error handing non valid label test 297 | bmtLinuxFunc log "non valid label test " "overflow" mylog /tmp/ 298 | bmtTestFunc "$?" 55 "404-a" 299 | echo 300 | 301 | # section subsection 302 | bmtLinuxFunc log "WARNING" "overflow" mylog /tmp/ 303 | bmtTestFunc "$?" 0 "404-b" 304 | bmtLinuxFunc log "INFO" "my message" mylog /tmp/ 305 | bmtTestFunc "$?" 0 "404-c" 306 | bmtPrintFunc b_red 307 | bmtLinuxFunc log "NOTICE" "my notice" mylog /tmp/ "MES" 308 | bmtTestFunc "$?" 0 "404-d" 309 | bmtPrintFunc norm 310 | bmtTestFunc 1 1 "404-e" "NOAUTO" 311 | 312 | # if user exists on the system 313 | printf "\n%s\n" "user check 405" 314 | bmtLinuxFunc user "gavin" 315 | bmtTestFunc "$?" 0 "405-a" 316 | bmtLinuxFunc user "foo12323" 317 | bmtTestFunc "$?" 2 "405-b" 318 | 319 | 320 | # check if varible set and empty 321 | printf "\n%s\n" "Variable check 406" 322 | local varsetfull="foo" 323 | local varsetempty="" 324 | 325 | bmtLinuxFunc isvarempty varsetfull 326 | bmtTestFunc "$?" 0 "406-a" 327 | bmtLinuxFunc isvarempty varsetempty 328 | bmtTestFunc "$?" 2 "406-b" 329 | bmtLinuxFunc isvarempty foofoo 330 | bmtTestFunc "$?" 3 "406-c" 331 | 332 | printf "\n%s\n" "Root running check 407" 333 | bmtLinuxFunc runasroot 334 | bmtTestFunc "$?" 2 "407-a" 335 | 336 | printf "\n%s\n" "Is command check 408" 337 | bmtLinuxFunc iscommand tput 338 | bmtTestFunc "$?" 0 "408-a" 339 | bmtLinuxFunc iscommand foofoo 340 | bmtTestFunc "$?" 2 "408-b" 341 | } 342 | 343 | function testfileFunc 344 | { 345 | printf "\n%s\n" "=== Start Files Tests === " # Section 5 346 | #check for bad user input 347 | echo "Error handling :" 348 | bmtFilesFunc foo 349 | bmtTestFunc "$?" 255 "50E-a" 350 | bmtFilesFunc 351 | bmtTestFunc "$?" 255 "50E-b" 352 | echo 353 | 354 | # 'dir empty ' 355 | echo "DIR EMPTY Test 501" 356 | bmtFilesFunc isdirempty "$TESTOBJECTS/EmptyDir/" 357 | bmtTestFunc "$?" 0 "501-a" # empty 358 | bmtFilesFunc isdirempty "$TESTOBJECTS/NonEmptyDir/" 359 | bmtTestFunc "$?" 2 "501-b" # non -empty 360 | bmtFilesFunc isdirempty "/foo/foo" 361 | bmtTestFunc "$?" 3 "501-c" # does not exist 362 | echo 363 | 364 | #make dir 365 | echo "MAKE DIR Test 502" 366 | bmtFilesFunc makedir "/tmp/" "-TEST" 367 | bmtTestFunc "$?" 0 "502-a" # success 368 | bmtFilesFunc makedir "/foo/" "-foo" 369 | bmtTestFunc "$?" 50 "502-b" # path does not exist 370 | bmtFilesFunc makedir "/usr/" "-iamnotroot" 371 | bmtTestFunc "$?" 52 "502-c" # Could not make directory , Permissions maybe 372 | echo 373 | 374 | # dir exists 375 | echo "DIR exist 503" 376 | bmtFilesFunc directoryexists /tmp/ 377 | bmtTestFunc "$?" 0 "503-a" # success 378 | bmtFilesFunc directoryexists /tmp/foo 379 | bmtTestFunc "$?" 2 "503-b" # fail 380 | echo 381 | 382 | # File exists 383 | echo "File exist 504" 384 | bmtFilesFunc fileexists "$TESTOBJECTS/full.txt" 385 | bmtTestFunc "$?" 0 "504-a" # success 386 | bmtFilesFunc fileexists /tmp/foo.txt 387 | bmtTestFunc "$?" 2 "504-b" # fail 388 | echo 389 | 390 | 391 | # Device exists 392 | echo "device exist 505" 393 | bmtFilesFunc deviceexists /dev/sda 394 | bmtTestFunc "$?" 0 "505-a" # success 395 | bmtFilesFunc deviceexists /dev/sdf 396 | bmtTestFunc "$?" 2 "505-b" # fail 397 | echo 398 | 399 | # File empty 400 | echo "file empty 506" 401 | bmtFilesFunc isfileempty "$TESTOBJECTS/full.txt" 402 | bmtTestFunc "$?" 0 "506-a" # success 403 | bmtFilesFunc isfileempty "$TESTOBJECTS/empty.txt" 404 | bmtTestFunc "$?" 2 "506-b" # fail 405 | echo " " 406 | 407 | # Get file size 408 | echo "getfilesize 507" 409 | bmtFilesFunc getfilesize "$TESTOBJECTS/tv.png" 410 | bmtTestFunc "$?" 0 "507-a" # success 411 | bmtTestFunc 1 1 "507-b" "NOAUTO" 412 | bmtFilesFunc getfilesize "/foo/foo.txt" 413 | bmtTestFunc "$?" 2 "507-c" # fail 414 | echo 415 | 416 | echo "getfilesizebytes 508" 417 | bmtFilesFunc getfilesizebytes "$TESTOBJECTS/tv.png" 418 | bmtTestFunc "$?" 0 "508-a" # success 419 | bmtTestFunc 1 1 "508-b" "NOAUTO" 420 | bmtFilesFunc getfilesizebytes "/foo/foo.txt" 421 | bmtTestFunc "$?" 2 "508-c" # fail 422 | echo 423 | 424 | echo "Get mime type of provided input 509" 425 | # print to console 426 | bmtFilesFunc getmimetype "$TESTOBJECTS/tv.png" 427 | echo 428 | bmtTestFunc 1 1 "509-a" "NOAUTO" 429 | echo 430 | 431 | # send to a file 432 | bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt" >> /tmp/mytempfile123.txt 433 | echo " /tmp/mytempfile123.txt file created" 434 | bmtTestFunc 1 1 "509-b" "NOAUTO" 435 | 436 | bmtFilesFunc getmimetype "/foo/foo/tv.png" 437 | bmtTestFunc "$?" 4 "509-c" # file does not exist 438 | 439 | # 510 440 | echo 441 | echo "Filename extraction 510 /foo/foo123/tv.png" 442 | bmtFilesFunc filename "/foo/foo123/tv.png" 1 443 | echo " :: File name $?" 444 | bmtFilesFunc filename "/foo/foo123/tv.png" 2 445 | echo " :: Base name $?" 446 | bmtFilesFunc filename "/foo/foo123/tv.png" 3 447 | echo " :: Extension $?" 448 | bmtFilesFunc filename "/foo/foo123/tv.png" 4 449 | echo " :: Folder name $?" 450 | bmtTestFunc 1 1 "510-a" "NOAUTO" 451 | 452 | # 510 errors 453 | bmtFilesFunc filename # no args passed 454 | bmtTestFunc "$?" 2 "510-b" 455 | bmtFilesFunc filename "/foo/foo123/tv.png" # no or wrong condition($2) passed 456 | bmtTestFunc "$?" 3 "510-c" 457 | bmtFilesFunc filename "/foo/foo123/tv" 3 # no extension passed. 458 | bmtTestFunc "$?" 4 "510-d" 459 | } 460 | 461 | function testdataFunc 462 | { 463 | printf "\n%s\n" "=== Start Data Tests === " # Section 6 464 | echo "Error handling check" 465 | bmtDataFunc foofoo 466 | bmtTestFunc "$?" 255 "60E-a" 467 | bmtDataFunc 468 | bmtTestFunc "$?" 255 "60E-b" 469 | 470 | # intcheck 601 471 | printf "\n%s\n" "601-a Enter an integer" 472 | read -r ID 473 | bmtDataFunc intcheck "$ID" 474 | bmtTestFunc "$?" 0 "601-a" 475 | 476 | printf "\n%s\n" "601-b Enter a NON integer" 477 | read -r ID 478 | bmtDataFunc intcheck "$ID" 479 | bmtTestFunc "$?" 2 "601-b" 480 | 481 | ## alphanumeric 602 482 | printf "\n%s\n" "602-a Enter an alpha numeric string" 483 | read -r ID1 484 | bmtDataFunc alphanumcheck "$ID1" 485 | bmtTestFunc "$?" 0 "602-a" 486 | 487 | printf "\n%s\n" "602-b Enter a NON alpha numeric string" 488 | read -r ID1 489 | bmtDataFunc alphanumcheck "$ID1" 490 | bmtTestFunc "$?" 2 "602-b" 491 | 492 | ## alpha check 603 493 | printf "\n%s\n" "603-a Enter an alphabetical string" 494 | read -r ID2 495 | bmtDataFunc alphacheck "$ID2" 496 | bmtTestFunc "$?" 0 "603-a" 497 | 498 | printf "\n%s\n" "603-b Enter an NON alphabetical string" 499 | read -r ID2 500 | bmtDataFunc alphacheck "$ID2" 501 | bmtTestFunc "$?" 2 "603-b" 502 | 503 | # lowercase 504 | printf "\n%s\n" "604 lowercase test" 505 | result=$(bmtDataFunc lowercase "TEST") # or result=`myfunc` 506 | printf "%s\n" "$result" 507 | bmtTestFunc 1 1 "604-a" "NOAUTO" 508 | 509 | #uppercase 510 | printf "\n%s\n" "605 uppercase test" 511 | result1=$(bmtDataFunc uppercase "test") 512 | printf "%s\n" "$result1" 513 | bmtTestFunc 1 1 "605-a" "NOAUTO" 514 | 515 | # trim 516 | printf "\n%s\n" "606 trim test" 517 | mytrim=" test " 518 | result2=$(bmtDataFunc trim "$mytrim") 519 | printf "%s\n" "$result2" 520 | bmtTestFunc 1 1 "606-a" "NOAUTO" 521 | 522 | # string length 523 | printf "\n%s\n" "607 string length test" 524 | bmtDataFunc strlen "test string 123" # 15 525 | bmtTestFunc "$?" 15 "607-a" 526 | bmtDataFunc strlen "" #report 250 error 527 | bmtTestFunc "$?" 250 "607-b" 528 | } 529 | 530 | function testtimeFunc 531 | { 532 | printf "\n%s\n" "=== Start Time Tests === " # Section 7 533 | # error handling check(catch typos) 534 | printf "%s\n" "Error handling" 535 | bmtTimeFunc 536 | bmtTestFunc "$?" 255 "70E-a" 537 | bmtTimeFunc foo 538 | bmtTestFunc "$?" 255 "70E-b" 539 | 540 | # 701 , prints 1651084921 541 | printf "\n%s\n" "701-a Convert time to epoch time ::" 542 | bmtTimeFunc epochconvert "2022-04-27 19:42:01 " 543 | printf "%s\n" " Pass :: 1651084921" 544 | bmtTestFunc 1 1 "701-a" "NOAUTO" 545 | 546 | # 702 547 | printf "\n%s\n" "702-b Current time Stamp ::" 548 | bmtTimeFunc epochnow 549 | echo 550 | bmtTestFunc 1 1 "702-b" "NOAUTO" 551 | 552 | # 703 call spinner function put run in background and save PID 553 | printf "\n%s\n" "Test 703-a spinner" 554 | 555 | bmtTimeFunc spin & 556 | pid=$! 557 | disown 558 | 559 | sleep 10 # Do stuff here 560 | 561 | kill $pid # Stop spin function with PID 562 | sleep 1 563 | printf "\r%s\n" " " 564 | bmtTestFunc 1 1 "703-a" "NOAUTO" 565 | 566 | # 704-707 567 | printf "\n%s\n" "Test 704-707 Stopwatch timer" 568 | bmtTimeFunc startWatch 569 | sleep .100 570 | bmtTimeFunc stopWatch 571 | echo " 0.1 S" 572 | 573 | bmtTimeFunc startWatch 574 | sleep 1 575 | bmtTimeFunc stopWatch 576 | echo " 1.0 S" 577 | 578 | bmtTimeFunc startWatch 579 | sleep 4.8 580 | bmtTimeFunc stopWatch 581 | echo " 4.8 S" 582 | bmtTestFunc 1 1 "704-a" "NOAUTO" 583 | 584 | # 708 call progressbar function put run in background and save PID 585 | 586 | printf "\n%s\n" "Test 708 progress bar " 587 | bmtTimeFunc progressbar 1 & 588 | pid=$! 589 | disown 590 | sleep 25 # Do stuff , 25 seconds one bar 591 | kill $pid # Stop spin function with PID 592 | sleep 1 593 | echo 594 | bmtTestFunc 1 1 "708-a" "NOAUTO" 595 | 596 | #709 597 | printf "\n%s\n" "Test 709 " 598 | bmtTimeFunc dateformat "1651084921" 599 | printf "\n%s\n" " Pass :: 2022-04-27 19:42:01" 600 | 601 | bmtTimeFunc dateformat "1651084921" "%FT%T%z" 602 | printf "\n%s\n" " Pass :: 2022-04-27T19:42:01+0100" 603 | 604 | bmtTestFunc 1 1 "709-a" "NOAUTO" 605 | 606 | #701 702 & 709 combined 607 | local timeVar2 608 | local timeVar 609 | printf "\n%s\n" " Test 70X-a 701 702 and 709 combined" 610 | timeVar="$(bmtTimeFunc epochnow)" # get current time in epoch seconds 611 | printf "%s\n" "Epoch time in :: $timeVar" 612 | timeVar2="$(bmtTimeFunc dateformat "$timeVar")" # Convert that to a date time 613 | printf "%s\n%s" "Time converted :: $timeVar2" "Epoch Time Out :: " 614 | bmtTimeFunc epochconvert "$timeVar2" # Convert back to epoch 615 | echo 616 | bmtTestFunc 1 1 "70X-a" "NOAUTO" 617 | 618 | # 710 call spinner function put run in background and save PID 619 | printf "\n%s\n" "Test 710 spinner" 620 | 621 | bmtTimeFunc spintwo & 622 | pid=$! 623 | disown 624 | 625 | sleep 10 # Do stuff here 626 | 627 | kill $pid # Stop spin function with PID 628 | sleep 1 629 | printf "\r%s\n" " " 630 | bmtTestFunc 1 1 "710-a" "NOAUTO" 631 | 632 | } 633 | 634 | function testmiscFunc 635 | { 636 | printf "\n%s\n" "=== Start Misc Tests === " # Section 8 637 | # error handling check(catch typos) 638 | echo "Error handling:: " 639 | bmtMiscFunc # No keyword 640 | bmtTestFunc "$?" 255 "80E-a" 641 | bmtMiscFunc foo # Wrong keyword 642 | bmtTestFunc "$?" 255 "80E-a" 643 | 644 | # 801 password generator 645 | echo 646 | bmtMiscFunc password "/home/gavin/Documents/Tech/Scripts/BashMultiTool/stuff/" 647 | bmtTestFunc "$?" 0 "801-a" 648 | echo 649 | 650 | bmtMiscFunc password 651 | bmtTestFunc "$?" 0 "801-b" 652 | echo 653 | 654 | #802 battery level 655 | echo "802 test" 656 | bmtMiscFunc getbatlevel "BAT0" "MES" 657 | echo "$?" 658 | bmtTestFunc 1 1 "802-a" "NOAUTO" 659 | 660 | bmtMiscFunc getbatlevel "foo" "MES" 661 | bmtTestFunc "$?" 127 "802-b" 662 | echo 663 | 664 | #803 665 | echo "803 test box" 666 | # 1 = red,box 2 = green,text "tput setaf colours" 667 | bmtMiscFunc drawbox 1 2 'first line' 'second line' 'third line' 668 | bmtTestFunc 1 1 "803-a" "NOAUTO" 669 | echo 670 | # 7 = white,box 6= cyan,text "tput setaf colours" 671 | bmtMiscFunc drawbox 7 6 'hello world' 672 | bmtTestFunc 1 1 "803-b" "NOAUTO" 673 | echo 674 | 675 | #804 676 | echo "804 test title" 677 | # 7 = white,box 6= cyan,text "tput setaf colours" 678 | bmtMiscFunc title 7 6 '#' 'hello' 679 | bmtTestFunc 1 1 "804-a" "NOAUTO" 680 | echo 681 | # 2 = green,box 6= cyan,text "tput setaf colours" 682 | bmtMiscFunc title 2 6 '+' 'World bye' 683 | bmtTestFunc 1 1 "804-b" "NOAUTO" 684 | echo 685 | 686 | #805 687 | echo "805 Test center text" 688 | bmtMiscFunc centertext "Hello World" - 689 | bmtTestFunc 1 1 "805-a" "NOAUTO" 690 | echo 691 | 692 | bmtPrintFunc b_red 693 | bmtMiscFunc centertext "HelloWorld In Red" = 694 | bmtTestFunc 1 1 "805-b" "NOAUTO" 695 | echo 696 | 697 | #806 698 | echo "806 test Display Gauge" 699 | bmtMiscFunc gauge "Value" 25 1 50 "#" "." 700 | bmtTestFunc 1 1 "806-a" "NOAUTO" 701 | echo 702 | 703 | bmtPrintFunc b_red 704 | bmtMiscFunc gauge "Value" 2 1 10 "=" " " 705 | bmtTestFunc 1 1 "806-b" "NOAUTO" 706 | echo 707 | } 708 | 709 | # === MAIN CODE === 710 | #Source the lib 711 | #(LOCAL path not installed for development) 712 | #LIBPATH="/home/gavin/Documents/Tech/Scripts/BashMultiTool/lib/" 713 | #installed path 714 | LIBPATH="/usr/lib/bashmultitool/" 715 | for MYFILE in "$LIBPATH"*; 716 | do 717 | source "$MYFILE" 718 | done 719 | 720 | TESTOBJECTS="$HOME/Documents/Tech/Scripts/BashMultiTool/test/testObjects" # for testfileFunc 721 | declare numberinput="$1" 722 | clear 723 | 724 | # Valid input 725 | if [ -z "$numberinput" ] # there an input? 726 | then 727 | printf "%s\n" "Enter Argument 1-8 or 9 for all tests" 728 | exit 1 729 | else 730 | # Valid number? 731 | [[ "$numberinput" =~ ^[0-9]+$ ]] || { printf "%s\n" "Enter a valid number 1-9 "; exit 1; } 732 | # Valid range? 733 | if ((numberinput == 0 || numberinput >= 10)); then 734 | printf "%s\n" "Enter a number in range 1-9 " 735 | exit 1 736 | fi 737 | fi 738 | 739 | 740 | bmtTestFunc 1 1 "START" 741 | read -n 1 -r -s -p "Press any key to continue" 742 | 743 | case "$numberinput" in 744 | 1|9) testprintFunc ;;& 745 | 2|9) testpromptFunc ;;& 746 | 3|9) testnetworkFunc ;;& 747 | 4|9) testlinuxFunc ;;& 748 | 5|9) testfileFunc ;;& 749 | 6|9) testdataFunc ;;& 750 | 7|9) testtimeFunc ;;& 751 | 8|9) testmiscFunc ;; 752 | esac 753 | 754 | printf "\n" 755 | bmtTestFunc 1 1 "END" 756 | # === EOF === 757 | -------------------------------------------------------------------------------- /test/testlog/pass.log: -------------------------------------------------------------------------------- 1 | 2022-09-22T14:58:41+0100 - NOTICE - Run Start 2 | 2022-09-22T14:58:44+0100 - PASSED - Test 10E-a Result :: 255 255 3 | 2022-09-22T14:58:44+0100 - PASSED - Test 10E-b Result :: 255 255 4 | 2022-09-22T14:58:46+0100 - PASSED - Test 101-a Result :: User Check 5 | 2022-09-22T14:58:46+0100 - PASSED - Test 20E-a Result :: 255 255 6 | 2022-09-22T14:58:46+0100 - PASSED - Test 20E-b Result :: 255 255 7 | 2022-09-22T14:58:48+0100 - PASSED - Test 201-a Result :: User Check 8 | 2022-09-22T14:58:54+0100 - PASSED - Test 202-y Result :: 0 0 9 | 2022-09-22T14:58:55+0100 - PASSED - Test 202-q Result :: 3 3 10 | 2022-09-22T14:58:57+0100 - PASSED - Test 202-n Result :: 2 2 11 | 2022-09-22T14:59:00+0100 - PASSED - Test 203-y Result :: 0 0 12 | 2022-09-22T14:59:01+0100 - PASSED - Test 203-n Result :: 2 2 13 | 2022-09-22T14:59:02+0100 - PASSED - Test 203-a Result :: 2 2 14 | 2022-09-22T14:59:03+0100 - PASSED - Test 204-y Result :: 2 2 15 | 2022-09-22T14:59:04+0100 - PASSED - Test 204-n Result :: 0 0 16 | 2022-09-22T14:59:05+0100 - PASSED - Test 204-a Result :: 2 2 17 | 2022-09-22T14:59:05+0100 - PASSED - Test 204-d Result :: 51 51 18 | 2022-09-22T14:59:09+0100 - PASSED - Test 205-a Result :: User Check 19 | 2022-09-22T14:59:11+0100 - PASSED - Test 206-q Result :: 0 0 20 | 2022-09-22T14:59:12+0100 - PASSED - Test 206-n Result :: 2 2 21 | 2022-09-22T14:59:13+0100 - PASSED - Test 206-a Result :: 2 2 22 | 2022-09-22T14:59:14+0100 - PASSED - Test 207-q Result :: 2 2 23 | 2022-09-22T14:59:15+0100 - PASSED - Test 207-n Result :: 0 0 24 | 2022-09-22T14:59:16+0100 - PASSED - Test 207-a Result :: 2 2 25 | 2022-09-22T14:59:16+0100 - PASSED - Test 207-d Result :: 51 51 26 | 2022-09-22T14:59:20+0100 - PASSED - Test 208-a Result :: 0 0 27 | 2022-09-22T14:59:22+0100 - PASSED - Test 209-a Result :: User Check 28 | 2022-09-22T14:59:23+0100 - PASSED - Test 210-a Result :: User Check 29 | 2022-09-22T14:59:23+0100 - PASSED - Test 30E-a Result :: 255 255 30 | 2022-09-22T14:59:23+0100 - PASSED - Test 30E-b Result :: 255 255 31 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-a Result :: 0 0 32 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-b Result :: 2 2 33 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-c Result :: 0 0 34 | 2022-09-22T14:59:24+0100 - PASSED - Test 301-d Result :: 2 2 35 | 2022-09-22T14:59:25+0100 - PASSED - Test 302-a Result :: 0 0 36 | 2022-09-22T14:59:25+0100 - PASSED - Test 40E-a Result :: 255 255 37 | 2022-09-22T14:59:25+0100 - PASSED - Test 40E-b Result :: 255 255 38 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-a Result :: 0 0 39 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-b Result :: 2 2 40 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-c Result :: 0 0 41 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-d Result :: 2 2 42 | 2022-09-22T14:59:25+0100 - PASSED - Test 402-a Result :: 4 4 43 | 2022-09-22T14:59:28+0100 - PASSED - Test 403-a Result :: User Check 44 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-a Result :: 55 55 45 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-b Result :: 0 0 46 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-c Result :: 0 0 47 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-d Result :: 0 0 48 | 2022-09-22T15:00:22+0100 - PASSED - Test 404-e Result :: User Check 49 | 2022-09-22T15:00:22+0100 - PASSED - Test 405-a Result :: 0 0 50 | 2022-09-22T15:00:22+0100 - PASSED - Test 405-b Result :: 2 2 51 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-a Result :: 0 0 52 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-b Result :: 2 2 53 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-c Result :: 3 3 54 | 2022-09-22T15:00:22+0100 - PASSED - Test 407-a Result :: 2 2 55 | 2022-09-22T15:00:22+0100 - PASSED - Test 408-a Result :: 0 0 56 | 2022-09-22T15:00:22+0100 - PASSED - Test 408-b Result :: 2 2 57 | 2022-09-22T15:00:22+0100 - PASSED - Test 50E-a Result :: 255 255 58 | 2022-09-22T15:00:22+0100 - PASSED - Test 50E-b Result :: 255 255 59 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-a Result :: 0 0 60 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-b Result :: 2 2 61 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-c Result :: 3 3 62 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-a Result :: 0 0 63 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-b Result :: 50 50 64 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-c Result :: 52 52 65 | 2022-09-22T15:00:22+0100 - PASSED - Test 503-a Result :: 0 0 66 | 2022-09-22T15:00:22+0100 - PASSED - Test 503-b Result :: 2 2 67 | 2022-09-22T15:00:22+0100 - PASSED - Test 504-a Result :: 0 0 68 | 2022-09-22T15:00:22+0100 - PASSED - Test 504-b Result :: 2 2 69 | 2022-09-22T15:00:22+0100 - PASSED - Test 505-a Result :: 0 0 70 | 2022-09-22T15:00:22+0100 - PASSED - Test 505-b Result :: 2 2 71 | 2022-09-22T15:00:22+0100 - PASSED - Test 506-a Result :: 0 0 72 | 2022-09-22T15:00:22+0100 - PASSED - Test 506-b Result :: 2 2 73 | 2022-09-22T15:00:22+0100 - PASSED - Test 507-a Result :: 0 0 74 | 2022-09-22T15:00:33+0100 - PASSED - Test 507-b Result :: User Check 75 | 2022-09-22T15:00:33+0100 - PASSED - Test 507-c Result :: 2 2 76 | 2022-09-22T15:00:33+0100 - PASSED - Test 508-a Result :: 0 0 77 | 2022-09-22T15:00:34+0100 - PASSED - Test 508-b Result :: User Check 78 | 2022-09-22T15:00:34+0100 - PASSED - Test 508-c Result :: 2 2 79 | 2022-09-22T15:00:35+0100 - PASSED - Test 509-a Result :: User Check 80 | 2022-09-22T15:00:36+0100 - PASSED - Test 509-b Result :: User Check 81 | 2022-09-22T15:00:36+0100 - PASSED - Test 509-c Result :: 4 4 82 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-a Result :: User Check 83 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-b Result :: 2 2 84 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-c Result :: 3 3 85 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-d Result :: 4 4 86 | 2022-09-22T15:00:38+0100 - PASSED - Test 60E-a Result :: 255 255 87 | 2022-09-22T15:00:38+0100 - PASSED - Test 60E-b Result :: 255 255 88 | 2022-09-22T15:00:40+0100 - PASSED - Test 601-a Result :: 0 0 89 | 2022-09-22T15:00:42+0100 - PASSED - Test 601-b Result :: 2 2 90 | 2022-09-22T15:00:44+0100 - PASSED - Test 602-a Result :: 0 0 91 | 2022-09-22T15:00:46+0100 - PASSED - Test 602-b Result :: 2 2 92 | 2022-09-22T15:00:49+0100 - PASSED - Test 603-a Result :: 0 0 93 | 2022-09-22T15:00:52+0100 - PASSED - Test 603-b Result :: 2 2 94 | 2022-09-22T15:00:53+0100 - PASSED - Test 604-a Result :: User Check 95 | 2022-09-22T15:00:54+0100 - PASSED - Test 605-a Result :: User Check 96 | 2022-09-22T15:00:55+0100 - PASSED - Test 606-a Result :: User Check 97 | 2022-09-22T15:00:55+0100 - PASSED - Test 607-a Result :: 15 15 98 | 2022-09-22T15:00:55+0100 - PASSED - Test 607-b Result :: 250 250 99 | 2022-09-22T15:00:55+0100 - PASSED - Test 70E-a Result :: 255 255 100 | 2022-09-22T15:00:55+0100 - PASSED - Test 70E-b Result :: 255 255 101 | 2022-09-22T15:00:56+0100 - PASSED - Test 701-a Result :: User Check 102 | 2022-09-22T15:00:57+0100 - PASSED - Test 702-b Result :: User Check 103 | 2022-09-22T15:01:13+0100 - PASSED - Test 703-a Result :: User Check 104 | 2022-09-22T15:01:21+0100 - PASSED - Test 704-a Result :: User Check 105 | 2022-09-22T15:01:49+0100 - PASSED - Test 708-a Result :: User Check 106 | 2022-09-22T15:01:50+0100 - PASSED - Test 709-a Result :: User Check 107 | 2022-09-22T15:01:51+0100 - PASSED - Test 70X-a Result :: User Check 108 | 2022-09-22T15:02:34+0100 - PASSED - Test 710-a Result :: User Check 109 | 2022-09-22T15:02:34+0100 - PASSED - Test 80E-a Result :: 255 255 110 | 2022-09-22T15:02:34+0100 - PASSED - Test 80E-a Result :: 255 255 111 | 2022-09-22T15:02:36+0100 - PASSED - Test 801-a Result :: 0 0 112 | 2022-09-22T15:02:36+0100 - PASSED - Test 801-b Result :: 0 0 113 | 2022-09-22T15:02:38+0100 - PASSED - Test 802-a Result :: User Check 114 | 2022-09-22T15:02:38+0100 - PASSED - Test 802-b Result :: 127 127 115 | 2022-09-22T15:02:38+0100 - PASSED - Test 803-a Result :: User Check 116 | 2022-09-22T15:02:39+0100 - PASSED - Test 803-b Result :: User Check 117 | 2022-09-22T15:02:40+0100 - PASSED - Test 804-a Result :: User Check 118 | 2022-09-22T15:02:40+0100 - PASSED - Test 804-b Result :: User Check 119 | 2022-09-22T15:02:41+0100 - PASSED - Test 805-a Result :: User Check 120 | 2022-09-22T15:02:42+0100 - PASSED - Test 805-b Result :: User Check 121 | 2022-09-22T15:02:43+0100 - PASSED - Test 806-a Result :: User Check 122 | 2022-09-22T15:02:44+0100 - PASSED - Test 806-b Result :: User Check 123 | 2022-09-22T15:02:44+0100 - NOTICE - Run Over 124 | -------------------------------------------------------------------------------- /test/testlog/test.log: -------------------------------------------------------------------------------- 1 | 2022-09-22T14:58:41+0100 - NOTICE - Run Start 2 | 2022-09-22T14:58:44+0100 - PASSED - Test 10E-a Result :: 255 255 3 | 2022-09-22T14:58:44+0100 - PASSED - Test 10E-b Result :: 255 255 4 | 2022-09-22T14:58:46+0100 - PASSED - Test 101-a Result :: User Check 5 | 2022-09-22T14:58:46+0100 - PASSED - Test 20E-a Result :: 255 255 6 | 2022-09-22T14:58:46+0100 - PASSED - Test 20E-b Result :: 255 255 7 | 2022-09-22T14:58:48+0100 - PASSED - Test 201-a Result :: User Check 8 | 2022-09-22T14:58:54+0100 - PASSED - Test 202-y Result :: 0 0 9 | 2022-09-22T14:58:55+0100 - PASSED - Test 202-q Result :: 3 3 10 | 2022-09-22T14:58:57+0100 - PASSED - Test 202-n Result :: 2 2 11 | 2022-09-22T14:59:00+0100 - PASSED - Test 203-y Result :: 0 0 12 | 2022-09-22T14:59:01+0100 - PASSED - Test 203-n Result :: 2 2 13 | 2022-09-22T14:59:02+0100 - PASSED - Test 203-a Result :: 2 2 14 | 2022-09-22T14:59:03+0100 - PASSED - Test 204-y Result :: 2 2 15 | 2022-09-22T14:59:04+0100 - PASSED - Test 204-n Result :: 0 0 16 | 2022-09-22T14:59:05+0100 - PASSED - Test 204-a Result :: 2 2 17 | 2022-09-22T14:59:05+0100 - PASSED - Test 204-d Result :: 51 51 18 | 2022-09-22T14:59:09+0100 - PASSED - Test 205-a Result :: User Check 19 | 2022-09-22T14:59:11+0100 - PASSED - Test 206-q Result :: 0 0 20 | 2022-09-22T14:59:12+0100 - PASSED - Test 206-n Result :: 2 2 21 | 2022-09-22T14:59:13+0100 - PASSED - Test 206-a Result :: 2 2 22 | 2022-09-22T14:59:14+0100 - PASSED - Test 207-q Result :: 2 2 23 | 2022-09-22T14:59:15+0100 - PASSED - Test 207-n Result :: 0 0 24 | 2022-09-22T14:59:16+0100 - PASSED - Test 207-a Result :: 2 2 25 | 2022-09-22T14:59:16+0100 - PASSED - Test 207-d Result :: 51 51 26 | 2022-09-22T14:59:20+0100 - PASSED - Test 208-a Result :: 0 0 27 | 2022-09-22T14:59:22+0100 - PASSED - Test 209-a Result :: User Check 28 | 2022-09-22T14:59:23+0100 - PASSED - Test 210-a Result :: User Check 29 | 2022-09-22T14:59:23+0100 - PASSED - Test 30E-a Result :: 255 255 30 | 2022-09-22T14:59:23+0100 - PASSED - Test 30E-b Result :: 255 255 31 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-a Result :: 0 0 32 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-b Result :: 2 2 33 | 2022-09-22T14:59:23+0100 - PASSED - Test 301-c Result :: 0 0 34 | 2022-09-22T14:59:24+0100 - PASSED - Test 301-d Result :: 2 2 35 | 2022-09-22T14:59:25+0100 - PASSED - Test 302-a Result :: 0 0 36 | 2022-09-22T14:59:25+0100 - PASSED - Test 40E-a Result :: 255 255 37 | 2022-09-22T14:59:25+0100 - PASSED - Test 40E-b Result :: 255 255 38 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-a Result :: 0 0 39 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-b Result :: 2 2 40 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-c Result :: 0 0 41 | 2022-09-22T14:59:25+0100 - PASSED - Test 401-d Result :: 2 2 42 | 2022-09-22T14:59:25+0100 - PASSED - Test 402-a Result :: 4 4 43 | 2022-09-22T14:59:28+0100 - PASSED - Test 403-a Result :: User Check 44 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-a Result :: 55 55 45 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-b Result :: 0 0 46 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-c Result :: 0 0 47 | 2022-09-22T14:59:28+0100 - PASSED - Test 404-d Result :: 0 0 48 | 2022-09-22T15:00:22+0100 - PASSED - Test 404-e Result :: User Check 49 | 2022-09-22T15:00:22+0100 - PASSED - Test 405-a Result :: 0 0 50 | 2022-09-22T15:00:22+0100 - PASSED - Test 405-b Result :: 2 2 51 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-a Result :: 0 0 52 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-b Result :: 2 2 53 | 2022-09-22T15:00:22+0100 - PASSED - Test 406-c Result :: 3 3 54 | 2022-09-22T15:00:22+0100 - PASSED - Test 407-a Result :: 2 2 55 | 2022-09-22T15:00:22+0100 - PASSED - Test 408-a Result :: 0 0 56 | 2022-09-22T15:00:22+0100 - PASSED - Test 408-b Result :: 2 2 57 | 2022-09-22T15:00:22+0100 - PASSED - Test 50E-a Result :: 255 255 58 | 2022-09-22T15:00:22+0100 - PASSED - Test 50E-b Result :: 255 255 59 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-a Result :: 0 0 60 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-b Result :: 2 2 61 | 2022-09-22T15:00:22+0100 - PASSED - Test 501-c Result :: 3 3 62 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-a Result :: 0 0 63 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-b Result :: 50 50 64 | 2022-09-22T15:00:22+0100 - PASSED - Test 502-c Result :: 52 52 65 | 2022-09-22T15:00:22+0100 - PASSED - Test 503-a Result :: 0 0 66 | 2022-09-22T15:00:22+0100 - PASSED - Test 503-b Result :: 2 2 67 | 2022-09-22T15:00:22+0100 - PASSED - Test 504-a Result :: 0 0 68 | 2022-09-22T15:00:22+0100 - PASSED - Test 504-b Result :: 2 2 69 | 2022-09-22T15:00:22+0100 - PASSED - Test 505-a Result :: 0 0 70 | 2022-09-22T15:00:22+0100 - PASSED - Test 505-b Result :: 2 2 71 | 2022-09-22T15:00:22+0100 - PASSED - Test 506-a Result :: 0 0 72 | 2022-09-22T15:00:22+0100 - PASSED - Test 506-b Result :: 2 2 73 | 2022-09-22T15:00:22+0100 - PASSED - Test 507-a Result :: 0 0 74 | 2022-09-22T15:00:33+0100 - PASSED - Test 507-b Result :: User Check 75 | 2022-09-22T15:00:33+0100 - PASSED - Test 507-c Result :: 2 2 76 | 2022-09-22T15:00:33+0100 - PASSED - Test 508-a Result :: 0 0 77 | 2022-09-22T15:00:34+0100 - PASSED - Test 508-b Result :: User Check 78 | 2022-09-22T15:00:34+0100 - PASSED - Test 508-c Result :: 2 2 79 | 2022-09-22T15:00:35+0100 - PASSED - Test 509-a Result :: User Check 80 | 2022-09-22T15:00:36+0100 - PASSED - Test 509-b Result :: User Check 81 | 2022-09-22T15:00:36+0100 - PASSED - Test 509-c Result :: 4 4 82 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-a Result :: User Check 83 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-b Result :: 2 2 84 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-c Result :: 3 3 85 | 2022-09-22T15:00:38+0100 - PASSED - Test 510-d Result :: 4 4 86 | 2022-09-22T15:00:38+0100 - PASSED - Test 60E-a Result :: 255 255 87 | 2022-09-22T15:00:38+0100 - PASSED - Test 60E-b Result :: 255 255 88 | 2022-09-22T15:00:40+0100 - PASSED - Test 601-a Result :: 0 0 89 | 2022-09-22T15:00:42+0100 - PASSED - Test 601-b Result :: 2 2 90 | 2022-09-22T15:00:44+0100 - PASSED - Test 602-a Result :: 0 0 91 | 2022-09-22T15:00:46+0100 - PASSED - Test 602-b Result :: 2 2 92 | 2022-09-22T15:00:49+0100 - PASSED - Test 603-a Result :: 0 0 93 | 2022-09-22T15:00:52+0100 - PASSED - Test 603-b Result :: 2 2 94 | 2022-09-22T15:00:53+0100 - PASSED - Test 604-a Result :: User Check 95 | 2022-09-22T15:00:54+0100 - PASSED - Test 605-a Result :: User Check 96 | 2022-09-22T15:00:55+0100 - PASSED - Test 606-a Result :: User Check 97 | 2022-09-22T15:00:55+0100 - PASSED - Test 607-a Result :: 15 15 98 | 2022-09-22T15:00:55+0100 - PASSED - Test 607-b Result :: 250 250 99 | 2022-09-22T15:00:55+0100 - PASSED - Test 70E-a Result :: 255 255 100 | 2022-09-22T15:00:55+0100 - PASSED - Test 70E-b Result :: 255 255 101 | 2022-09-22T15:00:56+0100 - PASSED - Test 701-a Result :: User Check 102 | 2022-09-22T15:00:57+0100 - PASSED - Test 702-b Result :: User Check 103 | 2022-09-22T15:01:13+0100 - PASSED - Test 703-a Result :: User Check 104 | 2022-09-22T15:01:21+0100 - PASSED - Test 704-a Result :: User Check 105 | 2022-09-22T15:01:49+0100 - PASSED - Test 708-a Result :: User Check 106 | 2022-09-22T15:01:50+0100 - PASSED - Test 709-a Result :: User Check 107 | 2022-09-22T15:01:51+0100 - PASSED - Test 70X-a Result :: User Check 108 | 2022-09-22T15:02:34+0100 - PASSED - Test 710-a Result :: User Check 109 | 2022-09-22T15:02:34+0100 - PASSED - Test 80E-a Result :: 255 255 110 | 2022-09-22T15:02:34+0100 - PASSED - Test 80E-a Result :: 255 255 111 | 2022-09-22T15:02:36+0100 - PASSED - Test 801-a Result :: 0 0 112 | 2022-09-22T15:02:36+0100 - PASSED - Test 801-b Result :: 0 0 113 | 2022-09-22T15:02:38+0100 - PASSED - Test 802-a Result :: User Check 114 | 2022-09-22T15:02:38+0100 - PASSED - Test 802-b Result :: 127 127 115 | 2022-09-22T15:02:38+0100 - PASSED - Test 803-a Result :: User Check 116 | 2022-09-22T15:02:39+0100 - PASSED - Test 803-b Result :: User Check 117 | 2022-09-22T15:02:40+0100 - PASSED - Test 804-a Result :: User Check 118 | 2022-09-22T15:02:40+0100 - PASSED - Test 804-b Result :: User Check 119 | 2022-09-22T15:02:41+0100 - PASSED - Test 805-a Result :: User Check 120 | 2022-09-22T15:02:42+0100 - PASSED - Test 805-b Result :: User Check 121 | 2022-09-22T15:02:43+0100 - PASSED - Test 806-a Result :: User Check 122 | 2022-09-22T15:02:44+0100 - PASSED - Test 806-b Result :: User Check 123 | 2022-09-22T15:02:44+0100 - NOTICE - Run Over 124 | --------------------------------------------------------------------------------