Skip to content

Commit 2505a29

Browse files
version 2.0
1 parent 29a8d26 commit 2505a29

34 files changed

+1425
-499
lines changed

README.md

Lines changed: 46 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
Overview
22
--------------------------------------------
33
* Name: bashMultiTool
4-
* Description: A Bash Shell library file for commonly used functions
4+
* Description:
5+
6+
A Bash Shell library file for commonly used functions
57
can be imported into shell scripts to create functional and colorful
68
scripts and Terminal users interfaces(TUI).
9+
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.
10+
711
* Author: Gavin Lyons
12+
* GNU bash: version 5.1.16
813

914
Table of contents
1015
---------------------------
1116

1217
* [Installation](#installation)
13-
* [Dependencies](#dependencies)
1418
* [Usage](#usage)
15-
* [Files](#files)
1619
* [Software](#software)
17-
20+
* [Demo](#demo)
21+
1822
Installation
1923
-----------------------------------------------
2024

21-
**Linux debian based systems built on Ubuntu 20.04 LTS (Focal Fossa)**
25+
**Linux debian based systems built on Ubuntu 22.04 LTS (Jammy Jellyfish)**
2226

2327
A Personal Package Archives (PPA) has been created on Ubuntu
2428
package building and hosting section of launchpad site
@@ -35,27 +39,22 @@ sudo apt install bashmultitool
3539
**For other linux systems**
3640

3741
Download latest fixed release and run the makefile as per
38-
terminal commands below for version 1.7 latest release at time of writing
42+
terminal commands below for version 2.0 latest release at time of writing
3943
Note: If you install with this method you will not be informed of updates
4044
by system.
4145

4246
```sh
43-
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/1.7.tar.gz | tar xz
44-
cd bashmultitool-1.7
47+
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.0.tar.gz | tar xz
48+
cd bashmultitool-2.0
4549
sudo make install
4650
```
4751
**Arch based System**
4852

4953
It's also available in the Arch Linux user repo AUR
5054

51-
Dependencies
52-
-------------------------------------
53-
1. GNU bash, version 4.4.18-2
54-
55-
2. The check website section requires netcat installed. [Netcat](https://en.wikipedia.org/wiki/Netcat)
56-
5755
Usage
5856
-------------------------------------------
57+
5958
Source the library from your bash shell scripts like so:
6059

6160
```sh
@@ -64,100 +63,55 @@ for MYFILE in "$LIBPATH"*;
6463
do
6564
source "$MYFILE"
6665
done
67-
68-
6966
```
7067

71-
There are six files in library and they are independent of each other
68+
There are eight files in library and they are independent of each other
7269
you can source them individually if you wish, however the prompt file *is*
73-
dependent on print.
74-
75-
Each file has one function, To access functions from your shell scripts type:
76-
77-
70+
dependent on print. Each file has one function, To access functions from your shell scripts type:
7871

7972
```sh
80-
[functionname] [keyword] [options]
73+
[function-name] [keyword] [options]
74+
75+
[section] [sub-section] [options]
8176
```
8277

83-
Six separate markdown help files with detailed information,
78+
Software
79+
-----------------------------------------
80+
81+
Eight separate markdown help files with detailed information,
8482
in documentation folder are available.
85-
For shortcut to each file click on link in 2nd table in *Files and setup* section below.
86-
The repo also contains a test folder where test files used in development are available.
83+
For shortcut to each help file click on link in 2nd table in *software* section below.
8784

88-
A script to print library meta data for test and debug is also installed.
85+
The repo also contains a *test folder* where test files used in development are available,
86+
one for each library file.
8987

90-
Files and setup
91-
-----------------------------------------
88+
A script to print library meta data is also installed.
9289

93-
| File Path | Description |
90+
| Installed File Path | Description |
9491
| ------ | ------ |
95-
| /usr/bin/bashmultitool.sh | Script to print library meta data |
96-
| /usr/lib/bashmultitool/bashmultitool/* | 6 library files see next table|
97-
| /usr/lib/bashmultitool/doc/README.md | help |
98-
| /usr/lib/bashmultitool/doc/documentation/license.md | copyright |
99-
| /usr/lib/bashmultitool/doc/documentation/changelog.md | history |
100-
92+
| /usr/bin/bashmultitool | Script to print library meta data |
93+
| /usr/lib/bashmultitool/bashmultitool/* | 8 library files see next table|
94+
| /usr/lib/bashmultitool/doc/README.md | readme |
95+
| /usr/lib/bashmultitool/doc/bmt*.md | 8 Documentation files see next table |
10196

10297
| Library file | Function | Sections | Content | Doc link |
10398
| ---- | ---- | ---- | ---- | ---- |
10499
| bmtPrint | bmtPrintFunc | 101 | Printing text | [bmtPrint help file](documentation/bmtPrint.md)|
105-
| bmtPrompt | bmtPromptFunc | 201-207 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)|
106-
| bmtMisc | bmtMiscFunc | 301-304 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
107-
| bmtLinux | bmtLinuxFunc | 401-404 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)|
108-
| bmtFiles | bmtFilesFunc | 501-505 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
109-
| bmtData | btmDataFunc | 601-606 | Data related | [bmtData help file](documentation/bmtData.md)|
110-
111-
112-
Software
113-
----------------------
114-
The library contains six files and six functions,
115-
which contains 27 sections in total.
116-
The sections are grouped in six files as per logical function.
100+
| bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)|
101+
| bmtNetwork | bmtNetworkFunc | 301-302 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md)|
102+
| bmtLinux | bmtLinuxFunc | 401-408 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)|
103+
| bmtFiles | bmtFilesFunc | 501-509 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
104+
| bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)|
105+
| bmtTime | btmTimeFunc | 701-709 | Time related | [bmtTime help file](documentation/bmtTime.md)|
106+
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
107+
108+
The library contains eight section's, Each section has one file with one function.
109+
which contains 43 sub-sections in total.
110+
The sections are grouped per logical function.
117111
Printing, prompting, Linux related, file related,
118-
data related and miscellaneous.
112+
data related, time related , network related and miscellaneous.
119113

114+
Output
115+
----------------------------
120116

121-
## Section numbered list
122-
123-
* 101 Coloured printed text, 8 colours, 7 modes. 56 options in total.
124-
125-
Colours: Black, Red, Green, Yellow, Blue, Purple, Cyan, White.
126-
127-
Modes: normal, bold, underline, background, high intensity,
128-
bold high intensity, background high intensity.
129-
130-
Example Output:
131-
132-
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/colour_print_example.png)
133-
134-
* 201 Horizontal lines across terminal in any colour
135-
* 202 yes-no-quit [y/n/q] prompt
136-
* 203 YES-no [Y/n] prompt
137-
* 204 yes-NO [y/N] prompt
138-
* 205 Anykey to continue prompt in any colour
139-
* 206 QUIT-no [Q/n] prompt
140-
* 207 quit-NO [q/N] prompt
141-
142-
* 301 Check if a website is up
143-
* 302 Spinner Animation for long non-verbose commands
144-
* 303 Stopwatch / timer
145-
* 304 Weather forecast
146-
147-
* 401 Check package installed
148-
* 402 Linux distro family checker
149-
* 403 Set text editor $EDITOR if not set
150-
* 404 log file handler
151-
152-
* 501 Make and enter a formated directory
153-
* 502 check if directory exists and empty
154-
* 503 directory exists
155-
* 504 file exists
156-
* 505 device exists
157-
158-
* 601 integer user input check
159-
* 602 alphabet user input check
160-
* 603 alphanumeric user input check
161-
* 604 convert string to lowercase
162-
* 605 convert string to uppercase
163-
* 606 trim whitespace from string
117+
![ScreenShot](https://raw.githubusercontent.com/gavinlyonsrepo/bashmultitool/master/documentation/screenshot/example.png)

documentation/bmtData.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
12
| Library file | Function | Sections | Content | help file |
23
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtData | btmDataFunc | 601-606 | Data related | bmtData.md|
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**
417

518
601) integer input check
619

@@ -46,9 +59,17 @@ Returns 0 for alphabet , 2 for non alphabet.
4659
echo $result
4760
```
4861

49-
606) trim whitespace from a strin
62+
606) trim whitespace from a strin
5063

5164
```sh
5265
result2=$(bmtDataFunc trim " test "
5366
echo $result2
5467
```
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+
```

documentation/bmtFiles.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
| Library file | Function | Sections | Content | help file|
22
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtFiles | bmtFilesFunc | 501-505 | File related | bmtFiles.md |
3+
| bmtFiles | bmtFilesFunc | 501-508 | File related | bmtFiles.md |
4+
5+
**Section Five, File**
6+
7+
* 501 Make and enter a formatted directory
8+
* 502 Check if directory exists and empty
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+
16+
**Sub-Sections**
417

518
501) Make formated directory
619

@@ -48,3 +61,33 @@ returns 0 for success, 2 for failure
4861
```sh
4962
bmtFilesFunc deviceexists /dev/sda
5063
```
64+
65+
506) Empty File
66+
Check if file empty
67+
returns 0 if not empty , 2 if empty
68+
69+
```sh
70+
bmtFilesFunc isfileempty "/foo/foo.txt"
71+
echo $?
72+
```
73+
74+
507) File size
75+
Prints file size and returns 0 if file does not exist returns 2
76+
```sh
77+
bmtFilesFunc getfilesize "/foo/foo.txt"
78+
```
79+
80+
508) File Size in bytes
81+
Prints file size and returns 0 if file does not exist returns 2
82+
```sh
83+
bmtFilesFunc getfilesizebytes "/foo/foo.txt"
84+
```
85+
86+
509) Display mime type of input file
87+
Returns 4 If file/directory does not exist. , 3 If file or mimetype command not found in system.
88+
2 if missing arguments.
89+
90+
```sh
91+
echo "$(bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt")" >> /tmp/mytempfile123.txt
92+
echo $?
93+
```

documentation/bmtLinux.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
| Library file | Function | Sections | Content | help file|
22
| ---- | ---- | ---- | ---- | ---- |
3-
| bmtLinux | bmtLinuxFunc | 401-404 | Linux related | bmtLinux.md |
3+
| bmtLinux | bmtLinuxFunc | 401-407 | Linux related | bmtLinux.md |
44

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**
517

618
401) Check package installed
719

@@ -38,12 +50,48 @@ returns 0 if it was set, 2 if not and sets it to vi
3850

3951
404) log file handler
4052
Creates a log file entry with standard formated date/time stamp.
41-
First option is state, valid values are
42-
(EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG|OK|FAILED|PASSED)
43-
second option is message, third option is file name .log is appended i.e mylog becomes mylog.log
44-
Fourth option is path to file.
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|
4561

4662
```sh
4763
bmtLinuxFunc log "CRITICAL" "1201 alarm Executive overflow - no vacant areas" mylog /tmp/
4864
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 id 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 "$?"
4997
```

0 commit comments

Comments
 (0)