Skip to content

Commit 0fffaec

Browse files
Merge pull request #1 from jd-apprentice/feat/functions
create functions and separate code
2 parents 763a01f + cda2f9b commit 0fffaec

15 files changed

Lines changed: 171 additions & 60 deletions

DEBIAN/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: dbn-tools
2-
Version: 1.1
2+
Version: 1.2
33
Section: utils
44
Priority: optional
55
Architecture: all

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@
1919
┃ ┣ 📜control
2020
┃ ┣ 📜postinst
2121
┃ ┗ 📜postrm
22-
┣ 📂utils
23-
┃ ┗ 📜debian_builder.sh
2422
┣ 📂usr
2523
┃ ┗ 📂bin
24+
┃ ┃ ┣ 📂constants
25+
┃ ┃ ┃ ┗ 📜colors.sh
26+
┃ ┃ ┣ 📂functions
27+
┃ ┃ ┃ ┗ 📜uptime.sh
2628
┃ ┃ ┗ 📜dbn-tools.sh
29+
┣ 📂utils
30+
┃ ┗ 📜debian_builder.sh
2731
┣ 📜CONTRIBUTE.md
32+
┣ 📜INSTALL.md
2833
┣ 📜LICENSE
29-
┗ 📜README.md
34+
┣ 📜README.md
35+
┗ 📜readme.png
3036
```
3137

3238
## 📁 Dependencies

readme.png

-183 KB
Loading

usr/bin/constants/colors.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!bin/bash
2+
3+
export colors=(red green yellow blue purple)

usr/bin/dbn-tools.sh

100644100755
Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
# Iterate over all the files in the folder
4+
for file in usr/bin/functions/*; do
5+
source "$file"
6+
done
7+
38
# Show the menu options
49
echo "
510
____ ____ _ _ _____ ___ ___ _ ____
@@ -9,62 +14,68 @@ echo "
914
|____/|____/|_| \_| |_| \___/ \___/|_____|____/
1015
"
1116
echo "---------------"
12-
echo "1) Analyze disk usage"
13-
echo "2) Delete temporary files"
14-
echo "3) Empty recycle bin"
15-
echo "4) Uninstall program"
16-
echo "5) System information"
17-
echo "6) Memory usage"
18-
echo "7) Exit"
17+
echo -e "\033[31m1) Analyze disk usage\033[0m"
18+
echo -e "\033[32m2) Delete temporary files\033[0m"
19+
echo -e "\033[33m3) Empty recycle bin\033[0m"
20+
echo -e "\033[34m4) Uninstall program\033[0m"
21+
echo -e "\033[35m5) System information\033[0m"
22+
echo -e "\033[36m6) Memory usage\033[0m"
23+
echo -e "\033[31m7) System uptime\033[0m"
24+
echo -e "\033[32m8) Open ports\033[0m"
25+
echo -e "\033[33m9) Search for a file\033[0m"
26+
echo -e "\033[34m10) Exit\033[0m"
1927

2028
# Read the user's option
2129
read -p "Enter an option: " option
2230

2331
# Perform the action corresponding to the chosen option
2432
case $option in
25-
1)
26-
# Show the used and available space in each of the system's hard drives
27-
printf "Disk usage:\n"
28-
printf "%-10s %-10s %-10s %-10s %s\n" "Filesystem" "Size" "Used" "Available" "Use%"
29-
df -h | tail -n +2 | awk '{ printf "%-10s %-10s %-10s %-10s %s\n", $1, $2, $3, $4, $5 }'
30-
;;
31-
2)
32-
# Delete the system's temporary files
33-
echo "Deleting temporary files..."
34-
sudo rm -rf /tmp/*
35-
;;
36-
3)
37-
# Empty the recycle bin
38-
echo "Emptying recycle bin..."
39-
sudo rm -rf ~/.local/share/Trash/*
40-
;;
41-
4)
42-
# Ask the user to enter the name of the program to uninstall
43-
read -p "Enter the name of the program to uninstall: " program
44-
# Uninstall the program
45-
echo "Uninstalling $program..."
46-
sudo dpkg --purge $program
47-
;;
48-
5)
49-
# Show detailed information about CPU and system
50-
echo "CPU information:"
51-
lscpu
52-
echo ""
53-
echo "System information:"
54-
uname -a
55-
;;
56-
6)
57-
# We display the ram usage and the swap usage information
58-
echo "Memory usage:"
59-
free -h
60-
;;
61-
7)
62-
# Exit the application
63-
exit
64-
;;
65-
*)
66-
echo "Invalid option"
67-
;;
33+
1)
34+
35+
DiskUsage
36+
;;
37+
2)
38+
39+
DeleteTemporary
40+
;;
41+
3)
42+
43+
DeleteTemporary
44+
;;
45+
4)
46+
47+
UninstallPackage
48+
;;
49+
5)
50+
51+
SystemInfo
52+
;;
53+
6)
54+
55+
MemoryUsage
56+
;;
57+
7)
58+
59+
Uptime
60+
;;
61+
8)
62+
63+
OpenPorts
64+
;;
65+
9)
66+
67+
FindFile
68+
;;
69+
10)
70+
71+
# Exit the application
72+
exit
73+
;;
74+
*)
75+
76+
# Invalid argument
77+
echo "Invalid option"
78+
;;
6879
esac
6980

70-
echo "Done!"
81+
echo "Done!"

usr/bin/functions/delete-temp.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Delete the system's temporary files
4+
function DeleteTemporary() {
5+
printf "Deleting temporary files..."
6+
sudo rm -rf /tmp/*
7+
}
8+
9+
export -f DeleteTemporary

usr/bin/functions/disk-usage.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Show the used and available space in each of the system's hard drives
4+
function DiskUsage() {
5+
printf "Disk usage:\n"
6+
printf "%-10s %-10s %-10s %-10s %s\n" "Filesystem" "Size" "Used" "Available" "Use%"
7+
df -h | tail -n +2 | awk '{ printf "%-10s %-10s %-10s %-10s %s\n", $1, $2, $3, $4, $5 }'
8+
}
9+
10+
export -f DiskUsage
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Empty the recycle bin
4+
function EmptyRecycleBin() {
5+
echo "Emptying recycle bin..."
6+
sudo rm -rf ~/.local/share/Trash/*
7+
}
8+
9+
export -f EmptyRecycleBin

usr/bin/functions/memory-usage.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!bin/bash
2+
3+
# We display the ram usage and the swap usage information
4+
function MemoryUsage() {
5+
echo "Memory usage:"
6+
free -h
7+
}
8+
9+
export -f MemoryUsage

usr/bin/functions/open-ports.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!bin/bash
2+
3+
# Show open ports
4+
function OpenPorts() {
5+
echo "Open ports:"
6+
netstat -tulpn
7+
}
8+
9+
export -f OpenPorts

0 commit comments

Comments
 (0)