Skip to content

Commit

Permalink
version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Sep 22, 2022
1 parent f14429a commit 22552b6
Show file tree
Hide file tree
Showing 26 changed files with 1,180 additions and 955 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976)

Overview
--------------------------------------------
* Name: bashMultiTool
Expand Down Expand Up @@ -43,13 +45,13 @@ Package available in the Arch Linux user repo AUR
**For other linux systems**

Download latest fixed release and run the makefile as per
terminal commands below for version 2.0 latest release at time of writing
terminal commands below for version 2.1 latest release at time of writing
Note: If you install with this method you will not be informed of updates
by system.

```sh
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.0.tar.gz | tar xz
cd bashmultitool-2.0
curl -sL https://github.com/gavinlyonsrepo/bashmultitool/archive/2.1.tar.gz | tar xz
cd bashmultitool-2.1
sudo make install
```

Expand Down Expand Up @@ -96,22 +98,22 @@ A script to print library meta data is also installed.
| bmtPrompt | bmtPromptFunc | 201-210 | Prompts | [ bmtPrompt help file](documentation/bmtPrompt.md)|
| bmtNetwork | bmtNetworkFunc | 301-302 | Network related | [bmtNetwork help file](documentation/bmtNetwork.md)|
| bmtLinux | bmtLinuxFunc | 401-408 | Linux related | [bmtLinux help file](documentation/bmtLinux.md)|
| bmtFiles | bmtFilesFunc | 501-509 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
| bmtFiles | bmtFilesFunc | 501-510 | File related | [bmtFiles help file](documentation/bmtFiles.md)|
| bmtData | btmDataFunc | 601-607 | Data related | [bmtData help file](documentation/bmtData.md)|
| bmtTime | btmTimeFunc | 701-709 | Time related | [bmtTime help file](documentation/bmtTime.md)|
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
| bmtTest | bmtTestFunc | 901 | library testing | [bmtTest help file](documentation/bmtTest.md)|
| bmtTime | btmTimeFunc | 701-710 | Time related | [bmtTime help file](documentation/bmtTime.md)|
| bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | [bmtMisc help file](documentation/bmtMisc.md)|
| bmtTest | bmtTestFunc | 901 | internal library test | [bmtTest help file](documentation/bmtTest.md)|

The library contains eight section's, Each section has one file with one function.
Which contains 50 sub-sections in total.
Which contains 54 sub-sections in total.
The sections are grouped per logical function.
Printing, prompting, Linux related, file related,
data related, time related , network related and miscellaneous.
The sections are mostly independent of each other
you can source them individually if you wish, however the prompt file *is*
dependent on print. There is also a ninth test section bmtTest used to test library.

The repo also contains a *test folder* where test files used in development are available, one for each library file. There is also a testTest.sh which runs an semi-automated test on entire library and produces a report.
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.

Example
----------------------------
Expand Down
13 changes: 12 additions & 1 deletion documentation/bmtFiles.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| Library file | Function | Sections | Content | help file|
| ---- | ---- | ---- | ---- | ---- |
| bmtFiles | bmtFilesFunc | 501-509 | File related | bmtFiles.md |
| bmtFiles | bmtFilesFunc | 501-510 | File related | bmtFiles.md |

**Section Five, File**

Expand All @@ -13,6 +13,7 @@
* 507 File size
* 508 File size in bytes
* 509 mime type exists?
* 510 File name extraction

**Sub-Sections**

Expand Down Expand Up @@ -92,3 +93,13 @@ Returns 4 If file/directory does not exist. , 3 If file or mimetype command not
bmtFilesFunc getmimetype "$TESTOBJECTS/full.txt" >> /tmp/mytempfile123.txt
echo $?
```
510) File name extraction
Returns 0 for success, 2 for missing arguments , 3 for wrong 2nd argument value, 4 for missing file extension

1. Param1 Filepath
2. Param2 1-4 1 for filename, 2 for basename, 3 for extension ,4 for folder path

```sh
bmtFilesFunc filename "/foo/foo123/tv.png" 4
echo " :: Folder name $?"
```
25 changes: 24 additions & 1 deletion documentation/bmtMisc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| Library file | Function | Sections | Content | help file |
| ---- | ---- | ---- | ---- | ---- |
| bmtMisc | bmtMiscFunc | 801-804 | Miscellaneous | bmtMisc.md |
| bmtMisc | bmtMiscFunc | 801-806 | Miscellaneous | bmtMisc.md |


**Section Eight , misc**
Expand All @@ -9,6 +9,8 @@
* 802 Get laptop battery level
* 803 Create a multi-line box with text inside it
* 804 Create a single line box with variable box character.
* 805 Centered text with variable banner character
* 806 Display gauge

**Sub-Sections**

Expand Down Expand Up @@ -49,3 +51,24 @@ bmtMiscFunc drawbox 1 2 'first line' 'second line' 'third line'
```sh
bmtMiscFunc title 2 6 '#' 'hello'
```

805) Centered text with option banner filler
1. Param1 Text to center
2. Param2 Banner symbol

```sh
bmtMiscFunc centertext "Hello World" =
```

806) Display Gauge, display a gauge bar showing variable value

1. Param1 Text label
2. Param2 Value to display
3. Param3 Minimum value of gauge
4. Param4 Maximum value of gauge
5. Param5 Gauge full symbol
6. Param6 Gauge empty symbol

```sh
bmtMiscFunc gauge "Volts" 25 1 50 "#" "."
```
7 changes: 7 additions & 0 deletions documentation/bmtNetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@

Keyword checknet, first option url of website. Returns 0 for connectivity , 2 for no connectivity

1. Param1 The URL
2. Param2 NOMES(optional) can be used to surpress verbose output.

```sh
bmtNetworkFunc checknet "www.google.ie"
```

```sh
bmtNetworkFunc checknet "www.google.ie" "NOMES"
```

302) weather

Weather report by wttr.in, uses wget utility
Expand Down
3 changes: 3 additions & 0 deletions documentation/bmtPrint.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Colours: Black, Red, Green, Yellow, Blue, Purple, Cyan, White.
Modes: normal, bold, underline, background, high intensity,
bold high intensity, background high intensity.

1. Param1 mode
2. Param2 text to print(optional can be left out just to change cursor colour
for next objects or text printed )

**Sub-Sections**

Expand Down
2 changes: 1 addition & 1 deletion documentation/bmtTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
| ---- | ---- | ---- | ---- | ---- |
| bmtTest | bmtTestFunc | 901 | Test | bmtTest.md |

**Section nine, Time**
**Section nine, Test**

Used to conduct semi-automated testing and test report of library function.

25 changes: 21 additions & 4 deletions documentation/bmtTime.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
| Library file | Function | Sections | Content | help file |
| ---- | ---- | ---- | ---- | ---- |
| bmtTime | bmtTimeFunc | 701-709 | Timing related | bmtTime.md |
| bmtTime | bmtTimeFunc | 701-710 | Timing related | bmtTime.md |

**Section Seven, Time**

* 701 Convert time to epoch time
* 702 Print current time Stamp
* 703 Spinner Animation for long non-verbose commands
* 703 Spinner Animation multiple character for long non-verbose commands
* 704 - 707 Stopwatch / timer
* 708 Progress Bar
* 709 Convert Epoch time to date format
* 710 Spinner Animation single character for long non-verbose commands

**Sub-Sections**

Expand All @@ -25,7 +26,7 @@ bmtTimeFunc epochconvert "2022-04-27 19:42:01 "
bmtTimeFunc epochnow
```

703) Animation for non-verbose process/commands that take long time
703) Spinner Animation for non-verbose process/commands that take long time

```sh
# call spinner section put run in background and save PID
Expand Down Expand Up @@ -71,7 +72,7 @@ percentage completed.
pid=$!
disown
echo "START"
sleep 25 #do stuff
sleep 25 # do stuff 25 seconds for one progress bar complete pass
echo " "
echo "END"
# Stop spin function with PID
Expand All @@ -86,3 +87,19 @@ percentage completed.
bmtTimeFunc dateformat "1651084921" "%FT%T%z"
# prints ~ 2022-04-27T19:42:01+0100
```

710) Spinner Animation, number two for long non-verbose commands

```sh
# call spinner section put run in background and save PID
bmtTimeFunc spintwo &
pid=$!
disown

# 'do stuff'
find ~ -name mint 2>/dev/null

# Stop spintwo function with PID
kill $pid
sleep 2
```
11 changes: 7 additions & 4 deletions documentation/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Version control

### version 1.1-2 200218
* increased color printing options
* increased options from 10 to 16
* increased sub-sections from 10 to 16
* made library modular. multiple files

### version 1.2-3 280318
* Added two new modes to printing options bringing total
number of option to 56 (8 colours * 7 modes)
* Increased number of functions from 16 to 26 including stopwatch.
* Increased number of sub-sections from 16 to 26 including stopwatch.

### version 1.4-5 040718
* updating PPA to Ubuntu 18.04 LTS (Bionic Beaver)
Expand All @@ -26,5 +26,8 @@ Version control
* updating PPA to Ubuntu 20.04 LTS (Focal Fossa)

### Version 2.0-1 28-04-2022
* updating PPA to Ubuntu 22.04 LTS (Jammy Jellyfish)
* Added 23 new sub-sections.
* updating PPA to Ubuntu 22.04 LTS (Jammy Jellyfish)
* Added 23 new sub-sections.

### Version 2.1-2 21-09-2022
* Added 4 new sub-sections, 510 710 805 806.
33 changes: 33 additions & 0 deletions lib/bmtFiles
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,43 @@ case "$1" in
printf "%s" "${mime_output}"
;;

filename) #510 /tmp/text.txt
[ -z "$2" ] && return 2
case "$3" in
1) #510-1 full filename text.txt
printf "%s" "${2##*/}" # parameter expansion retain after /
;;
2) #510-2 basename text
local filename basename
filename="${2##*/}" # parameter expansion retain after /
basename="${filename%.*}" # parameter expansion retain before .
printf "%s" "${basename}"
;;
3) #510.3 extension .txt
local filename extension
filename="${2##*/}" # parameter expansion retain after /
extension="${filename##*.}" # parameter expansion after .
[[ "${filename}" = "${extension}" ]] && return 4

printf "%s" "${extension}"
;;
4) #folder path /tmp
declare folderpath=${2:-.}
folderpath=${2%/*}
printf "%s" "${folderpath}"
;;
*)
return 3
;;
esac
return 0
;;

*) # Catch all user typos
printf '%s\n' "Error: Unknown keyword : bashmultitool :bmtFiles : bmtFilesFunc"
return 255
;;

esac

}
Expand Down
45 changes: 41 additions & 4 deletions lib/bmtMisc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ case "$1" in

password) #801
local mylengthVar=0
echo "Random Password generator :"
if [ -z "$2" ]; then
cd "/tmp/" || return 3
echo "Output Path /tmp/"
else
cd "$2" || return 3
echo "Output Path $2"
fi
touch passwordBMT.txt
echo "Random Password generator"
echo "Enter length:-"
read -r mylengthVar
# if just enter pressed set default 20
Expand All @@ -42,10 +44,10 @@ case "$1" in
local Filepath="/sys/class/power_supply/$2/capacity"
if ! [[ -f $Filepath ]]; then
echo "File '$Filepath' not found."
return 101
elif ! [[ -f $Filepath ]]; then
return 127
elif ! [[ -r $Filepath ]]; then
echo "File '$Filepath' unreadable."
return 102
return 128
fi

read -r < "/sys/class/power_supply/$2/capacity"
Expand Down Expand Up @@ -92,6 +94,7 @@ case "$1" in
local colortext="$3"
local bannersymbol="$4"
local textmsg="$5"
local edge

edge=$(echo "$textmsg####" | sed "s/./$bannersymbol/g")

Expand All @@ -103,6 +106,40 @@ case "$1" in

;;

centertext)
local banner outputtext
local inputtext=" ${2} " bannersymbol="${3:- }"
local stringlength=${#inputtext}
local bannerlength="$((($(tput cols) - stringlength) / 2))"

[[ -n "${bannersymbol}" ]] && bannersymbol="${bannersymbol:0:1}"
for ((i = 0; i < bannerlength; i++)); do
banner+="${bannersymbol}"
done

outputtext="${banner}${inputtext}${banner}"
[[ $((($(tput cols) - stringlength) % 2)) -ne 0 ]] && outputtext+="${bannersymbol}"
printf "%s" "${outputtext}"
;;

gauge)
local label="$2"
local value="$3"
local min="$4"
local max="$5"
local symbol="$6"
local symbolempty="$7"

printf "%s=%3d %d" "$label" "$value" "$min"
echo -n "["
for ((i = min ; i <= value; i++)); do echo -n "$symbol"; done
for ((j = value+1 ; j <= max ; j++)); do echo -n "$symbolempty"; done
echo -n "]"
printf "%d" "$max"
echo
;;


*) # Catch all users typos
printf '%s\n' "Error: Unknown keyword : bashMultiTool: bmtMisc: bmtMiscFunc"
return 255
Expand Down
12 changes: 9 additions & 3 deletions lib/bmtNetwork
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ case "$1" in
#scanning]) with a quick timeout
#(-w 1 waits at most one second
#It checks passed website $1 on port 80 (HTTP).
if nc -zw1 "$2" 80; then
printf '%s\n' "We have connectivity $2"
if nc -zw1 "$2" 80 2>>/tmp/bmtchecknet.log ; then
if [ "$3" != "NOMES" ]
then
printf '%s\n' "We have connectivity $2"
fi
return 0
else
printf '%s\n' "${red}We do not have connectivity $2 ${normal}"
if [ "$3" != "NOMES" ]
then
printf '%s\n' "${red}We do not have connectivity $2 ${normal}"
fi
return 2
fi
;;
Expand Down
Loading

0 comments on commit 22552b6

Please sign in to comment.