diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 0000000..3bfe71e --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,10 @@ +version = 1 + +[[analyzers]] +name = "shell" + +[[analyzers]] +name = "python" + + [analyzers.meta] + runtime_version = "3.x.x" \ No newline at end of file diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml new file mode 100644 index 0000000..835a532 --- /dev/null +++ b/.github/workflows/codacy.yml @@ -0,0 +1,61 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow checks out code, performs a Codacy security scan +# and integrates the results with the +# GitHub Advanced Security code scanning feature. For more information on +# the Codacy security scan action usage and parameters, see +# https://github.com/codacy/codacy-analysis-cli-action. +# For more information on Codacy Analysis CLI in general, see +# https://github.com/codacy/codacy-analysis-cli. + +name: Codacy Security Scan + +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '23 4 * * 5' + +permissions: + contents: read + +jobs: + codacy-security-scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + name: Codacy Security Scan + runs-on: ubuntu-latest + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout code + uses: actions/checkout@v3 + + # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b + with: + # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository + # You can also omit the token and run the tools that support default configurations + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + verbose: true + output: results.sarif + format: sarif + # Adjust severity of non-security issues + gh-code-scanning-compat: true + # Force 0 exit code to allow SARIF file generation + # This will handover control about PR rejection to the GitHub side + max-allowed-issues: 2147483647 + + # Upload the SARIF file generated in the previous step + - name: Upload SARIF results file + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: results.sarif diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..822c00e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Build Package + +on: + push: + branches: "master" + paths: + - "usr/**" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Update package and install dpkg-dev + run: sudo apt-get update && sudo apt-get install -y dpkg-dev + + - name: Checkout + run: git clone https://github.com/jd-apprentice/dbn-tools.git && cd dbn-tools + + - name: Get Package Version + id: get_version + run: | + file=$(find ./dbn-tools/DEBIAN -name 'control') + string="Version" + + while read -r line; do + if [[ $line =~ $string ]]; then + version=${line:9} + fi + done <$file + + echo "::set-output name=version::$version" + + - name: Execute Bash Script + run: | + + cd dbn-tools + + rm -rf .git + rm -rf *.png + rm -rf *.md + + cd .. + + dpkg-deb -b dbn-tools "${{ steps.get_version.outputs.version }}"-dbn-tools.deb + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + tag_name: ${{ steps.get_version.outputs.version }} + release_name: 📦 ${{ steps.get_version.outputs.version }} + body: | + + 🤖 Release automatically generated by GitHub Actions + + draft: false + prerelease: false + files: | + ${{ steps.get_version.outputs.version }}-dbn-tools.deb + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ steps.get_version.outputs.version }}-dbn-tools.deb + asset_name: ${{ steps.get_version.outputs.version }}-dbn-tools.deb + asset_content_type: application/octet-stream diff --git a/.gitignore b/.gitignore index 737ea53..0c8a059 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ -.swp -error.log +*.swp +*.env +*.log +*.txt +downloads +app diff --git a/CONTRIBUTE.md b/CONTRIBUTING.md similarity index 64% rename from CONTRIBUTE.md rename to CONTRIBUTING.md index eef1e5a..ee5d723 100755 --- a/CONTRIBUTE.md +++ b/CONTRIBUTING.md @@ -15,3 +15,11 @@ If you are going to change a few things and want to build it to test if it works - Remember to not include anything git related - Don't include anything sensitive + +## 📝 Notes to remember + +- When you are working locally you don't use absolute paths for example /usr/bin/functions since that one is going to be the final one for when the package is installed, instead you use usr/bin/functions since is part of the folder you are working on + +## 🔍 What language should I use? + +- Languages accepted at the moment are python and bash, if I find more ways to implement new ones for example javascript I will accept them, for now I'll go with what I consider stable diff --git a/DEBIAN/control b/DEBIAN/control index 66323f3..7a30e4d 100755 --- a/DEBIAN/control +++ b/DEBIAN/control @@ -1,8 +1,8 @@ Package: dbn-tools -Version: 0.0.4 +Version: 0.1.1 Section: utils Priority: optional Architecture: all -Depends: bash +Recommends: python3-pip, python3-dev, openai Maintainer: Jonathan Dyallo Description: A utility to optimize the system performance diff --git a/DEBIAN/postinst b/DEBIAN/postinst index dba4704..7cbcf69 100755 --- a/DEBIAN/postinst +++ b/DEBIAN/postinst @@ -1,11 +1,11 @@ #!/bin/bash # Create symbolic link -sudo ln -s /usr/share/dbn-tools/usr/bin/dbn-tools.sh /usr/bin/dbn-tools +ln -s /usr/share/dbn-tools/usr/bin/dbn-tools.sh /usr/bin/dbn-tools # Get the project in a more monkey-friendly way cd /usr/share -git clone -b develop https://github.com/jd-apprentice/dbn-tools.git +git clone https://github.com/jd-apprentice/dbn-tools.git # Give permissions to the application and source the files chmod -R 777 /usr/share/dbn-tools diff --git a/DEBIAN/preinst b/DEBIAN/preinst new file mode 100755 index 0000000..53c14eb --- /dev/null +++ b/DEBIAN/preinst @@ -0,0 +1,6 @@ +#!/bin/bash + +sudo apt-get install -y python3-pip python3-dev + +pip3 install requests==2.28.2 \ + yt-dlp==2023.1.6 \ openai==0.27.2 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..804b634 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM alpine:3.18 + +WORKDIR /app + +ENV PYTHONBUFFERED=1 + +RUN apk --update add --no-cache \ + dpkg=1.21.21-r1 \ + binutils=2.40-r7 \ + zstd=1.5.5-r4 \ + libc6-compat=1.2.4-r2 \ + wget=1.21.4-r0 \ + git=2.40.1-r0 \ + curl=8.4.0-r0 \ + python3=3.11.6-r0 && \ + ln -sf python3 /usr/bin/python && \ + rm -rf /var/cache/apk/* + +RUN python3 -m ensurepip && \ + pip3 install --upgrade pip setuptools && \ + pip3 install requests==2.28.2 \ + yt-dlp==2023.1.6 \ openai==0.27.2 + +ARG DOWNLOAD_URL=https://github.com/jd-apprentice/dbn-tools/releases/download/0.1.0/1.0-dbn-tools.deb +ARG PACKAGE_NAME=1.0-dbn-tools +RUN wget $DOWNLOAD_URL + +RUN set -e +RUN ar x $PACKAGE_NAME.deb +RUN zstd -d < control.tar.zst | xz > control.tar.xz +RUN zstd -d < data.tar.zst | xz > data.tar.xz +RUN ar -m -c -a sdsd "$PACKAGE_NAME"_repacked.deb debian-binary control.tar.xz data.tar.xz +RUN rm debian-binary control.tar.xz data.tar.xz control.tar.zst data.tar.zst +RUN dpkg -i ./"$PACKAGE_NAME"_repacked.deb +RUN rm $PACKAGE_NAME + +ENTRYPOINT ["/usr/bin/dbn-tools"] \ No newline at end of file diff --git a/INSTALL.md b/INSTALL.md index 1021f10..f541f2b 100755 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,5 +1,12 @@ ## 💡 Installation +### 🐧 AppImage + +- Tested on Linux Mint 21.2 +- Download the .AppImage package from the repository. +- Give permissions to the package with `chmod +x ./dbn-tools.AppImage` +- Run the package with `./dbn-tools.AppImage` + ### 🤎 Ubuntu - Tested on Ubuntu 22.04 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4833ec8 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +install: + sudo apt-get install dpkg-dev wget + wget https://github.com/jd-apprentice/dbn-tools/releases/download/0.1.0/1.0-dbn-tools.deb + sudo dpkg -i 1.0-dbn-tools.deb + echo "dbn-tools installed" + echo "run 'dbn-tools' to start the program" + +build: + chmod +x ./utils/build_new_version.sh + ./utils/build_new_version.sh + +debian: + chmod +x ./utils/debian_builder.sh + ./utils/debian_builder.sh + +docker: + docker compose up -d + docker exec -it dbn-tools-container bash + \ No newline at end of file diff --git a/README.md b/README.md index 06a30a8..154eb63 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # 💾 DBN-TOOLS +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2780bebe8e2c4ec3abcc784b3d8f29c6)](https://app.codacy.com/gh/jd-apprentice/dbn-tools/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![DeepSource](https://deepsource.io/gh/jd-apprentice/dbn-tools.svg/?label=active+issues&show_trend=true&token=R5d9toJdoCzp6s2De2EUsQxk)](https://deepsource.io/gh/jd-apprentice/dbn-tools/?ref=repository-badge) + ## 💻 With dbn-tools, you can: - 🔍 Analyze disk usage and see which files and directories are taking up the most space. @@ -9,32 +12,61 @@ - 🗑️ Empty the recycle bin to permanently delete files. - 🌧️ Check weather for you current location. - 🧹 Uninstall programs you no longer need. +- 💵 Check local rate for USD-ARS. - 🔍 Search for a specific file. +- 🍎 Download youtube videos. - 🕰️ Check the system uptime. - 🔒 Check open ports. - ![image](./readme.png) +## 📓 Documentation + +- Documentation is hosted on [Here](https://dbn-tools.jonathan.com.ar/) + +## 💾 Can I download the app? + +- Yes! releases are being published -> [HERE](https://github.com/jd-apprentice/dbn-tools/releases) +- Check compatibility for your distro or look at the [INSTALL](./INSTALL.md) for detailed instructions + +## 🌡 Want to see our metrics? + +We use codacy here is the [DASHBOARD](https://app.codacy.com/gh/jd-apprentice/dbn-tools/dashboard) +We also use deepsource here is the [DASHBOARD](https://deepsource.io/gh/jd-apprentice/dbn-tools) + ## 💡 Ideas -- New ideas are being tracked and added in this issue -> [Here](https://github.com/jd-apprentice/dbn-tools/issues/5) +- New ideas are being tracked and added in this issue -> [Here](https://github.com/users/jd-apprentice/projects/3) ## 💾 Compatibility +- Docker ✅ - Ubuntu 22.04 ✅ - Debian 11 ✅ - Arch ✅ +- Fedora ❌ +- Centos ❌ +- Gentoo ❌ +- openSUSE ❌ +- Slackware ❌ ## 🏳️ Flags - `--help`: 📜 Display a help message with a list of all available options. -- `--esp`: 🇪🇸 Enable Spanish translation. +- `--system`: 🖥 Filters the menu to only show system utility options. +- `--esp`: 🇪🇸 Enable Spanish translation (WIP). + +## 📁 Application + +![APP](https://cdn.discordapp.com/attachments/875262629516546089/1071869885250011197/image.png) ## 📁 Folder structure ``` 📦dbn-tools + ┣ 📂.github + ┃ ┗ 📂workflows + ┃ ┃ ┗ 📜codacy.yml ┣ 📂DEBIAN ┃ ┣ 📜control ┣ 📂usr @@ -46,7 +78,9 @@ ┃ ┃ ┗ 📜dbn-tools.sh ┣ 📂utils ┃ ┣ 📜build_new_version.sh + ┣ 📜.gitignore ┣ 📜CONTRIBUTE.md + ┣ 📜Dockerfile ┣ 📜INSTALL.md ┣ 📜LICENSE ┣ 📜README.md @@ -57,7 +91,32 @@ - Bash - Git -- Debtap (Arch) +- Debtap [Repository](https://github.com/helixarch/debtap) +- Python 3 + +## 🐍 Python dependencies + +- Requests [Requests](https://pypi.org/project/requests/) +- Openai [GPT-3](https://pypi.org/project/openai/) + +## 🐛 Troubleshot + +For more information, check the [TROUBLESHOT](./TROUBLESHOT.md) file + +## 🌴 Environment variables + +| Variable | Description | +| -------------- | --------------------------------------------------------------------------------------------- | +| `DOWNLOAD_URL` | URL to download a package get it from here -> https://github.com/jd-apprentice/dbn-tools/tags | +| `PACKAGE_NAME` | Name of the package being downloaded (is the name of the file from the other variable) | +| `GPT_KEY` | Key to use GPT-3 API - Add it on your shell configuration | + +```bash +## For the `GPT_KEY` we are reading it from .bashrc or .zshrc depending on your shell +## Add a line like this: + +GPT_KEY='YOUR_KEY' +``` ## 📁 Install @@ -67,9 +126,13 @@ You can see how to install it in the following file [INSTALL](./INSTALL.md). This project is under the MIT license. See the [LICENSE](./LICENSE) for more information. -## 🤝 Contribute +## 🤝 Contributing + +For more information, check the [CONTRIBUTING](./CONTRIBUTING.md) file + +Other projects were created based on this one! -For more information, check the [CONTRIBUTE](./CONTRIBUTE.md) file +Here is an example [elo-tool](https://github.com/dev-eloy/elo-tool) ## ✨ Contributors diff --git a/TROUBLESHOT.md b/TROUBLESHOT.md new file mode 100644 index 0000000..9c509f3 --- /dev/null +++ b/TROUBLESHOT.md @@ -0,0 +1,39 @@ +## 🌠 Troubleshot + +### 🚫 Common problems and solutions + +- requests module not found + +```py +Traceback (most recent call last): + File "/usr/bin/functions/usd-ars.py", line 4, in + import requests +ModuleNotFoundError: No module named 'requests' +``` + +We can make sure we have requests in our system with the following command: + +```sh +pip3 show requests +``` + +If we don't have it, we can install it with the following command: + +```sh +pip3 install requests==2.28.2 +``` + +In case you don't have pip3 installed, you can install it with the following command: + +```sh +sudo apt install python3-dev=3.10.6-1~22.04 python3-pip=22.0.2+dfsg-1ubuntu0.1 +``` + +Then we can do the same as before: + +```sh +pip3 install requests==2.28.2 \ + yt-dlp==2023.1.6 +``` + +Then we may have to reboot the system to make sure the changes are applied. diff --git a/dbn-tools.desktop b/dbn-tools.desktop new file mode 100644 index 0000000..1c59a0d --- /dev/null +++ b/dbn-tools.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=dbn-tools +Icon=icon +Type=Application +Categories=Utility; +Terminal=true +X-AppImage-Version=0.1.1 \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..07db8c6 Binary files /dev/null and b/icon.png differ diff --git a/readme.png b/readme.png old mode 100755 new mode 100644 index a21e664..4574f8b Binary files a/readme.png and b/readme.png differ diff --git a/usr/bin/constants/help.sh b/usr/bin/constants/help.sh index ef5f7a8..d24dfbe 100755 --- a/usr/bin/constants/help.sh +++ b/usr/bin/constants/help.sh @@ -10,7 +10,10 @@ export descriptions=( "6) Memory usage - Displays information about memory usage, such as total, used, and free memory." "7) System uptime - Displays the amount of time the system has been running since the last boot." "8) Open ports - Displays a list of open network ports and their associated processes." - "9) Get weather - Display a table with the current weather of your location." - "10) Search for a file - Searches for a file by name or wildcard pattern." - "11) Exit - Exits the application." + "9) Get weather - Display a table with the current weather of your location." + "10 Download YT Video - Downloads a video from youtube with the best possible size and quality by default" + "11) Search for a file - Searches for a file by name or wildcard pattern." + "12) USR-ARS Pair - Ask the value of the USD Dolar against the argentine PESO" + "13) Ask GPT 3 - Ask anythig to the GPT 3 AI" + "14) Exit - Exit the application" ) diff --git a/usr/bin/constants/menu-esp.sh b/usr/bin/constants/menu-esp.sh index cbe635e..3036fe3 100755 --- a/usr/bin/constants/menu-esp.sh +++ b/usr/bin/constants/menu-esp.sh @@ -1 +1,18 @@ -export menu_options_spanish=("1) Analizar uso del disco" "2) Eliminar archivos temporales" "3) Vaciar la papelera de reciclaje" "4) Desinstalar programa" "5) Información del sistema" "6) Uso de memoria" "7) Tiempo de actividad del sistema" "8) Puertos abiertos" "9) Clima actual" "10) Buscar archivo" "11) Salir") +#!bin/bash + +export menu_options_spanish=( + "1) Analizar uso del disco" + "2) Eliminar archivos temporales" + "3) Vaciar la papelera de reciclaje" + "4) Desinstalar programa" + "5) Información del sistema" + "6) Uso de memoria" + "7) Tiempo de actividad del sistema" + "8) Puertos abiertos" + "9) Clima actual" + "10) Descargar Video YT" + "11) Buscar archivo" + "12) Dolar a pesos" + "13) Pregunta a GPT 3" + "14) Salir" +) diff --git a/usr/bin/constants/menu.sh b/usr/bin/constants/menu.sh index a36404c..4427e67 100755 --- a/usr/bin/constants/menu.sh +++ b/usr/bin/constants/menu.sh @@ -1 +1,18 @@ -export menu_options=("1) Analyze disk usage" "2) Delete temporary files" "3) Empty recycle bin" "4) Uninstall program" "5) System information" "6) Memory usage" "7) System uptime" "8) Open ports" "9) Get current weather" "10) Search for a file" "11) Exit") +#!bin/bash + +export menu_options=( + "1) Analyze disk usage" + "2) Delete temporary files" + "3) Empty recycle bin" + "4) Uninstall program" + "5) System information" + "6) Memory usage" + "7) System uptime" + "8) Open ports" + "9) Get current weather" + "10) Download YT Video" + "11) Search for a file" + "12) USD-ARS Pair" + "13) Ask GPT 3" + "14) Exit" +) diff --git a/usr/bin/dbn-tools.sh b/usr/bin/dbn-tools.sh index d474376..0114a5f 100755 --- a/usr/bin/dbn-tools.sh +++ b/usr/bin/dbn-tools.sh @@ -1,42 +1,21 @@ #!/bin/bash # Initialize the environment -args=() -prompt="Enter an option: " +export args=() +export prompt="Enter an option: " # Source functions -for file in $(find /usr/bin/functions/ -name '*.sh'); do - if [ -f "$file" ]; then - source "$file" - fi -done - -# Source constants -for file in $(find /usr/bin/constants/ -name '*.sh'); do - if [ -f "$file" ]; then - source "$file" - fi -done - -# Iterate over all the arguments -for arg in "$@"; do - if [[ $arg == "--help" ]]; then - source /usr/bin/constants/help.sh # Look for a way to not source this file again - for description in "${descriptions[@]}"; do - echo "$description" - done - exit +for file in $(find /usr/bin/ -name '*.sh'); do + if [[ $file == *"functions"* ]]; then + source "$file" + elif [[ $file == *"constants"* ]]; then + source "$file" fi - - if [[ $arg == "--esp" ]]; then - language="esp" - continue - fi - - # Otherwise, store the argument in the array - args+=("$arg") done +# Read and build the menu +ReadArguments "$@" + # Display the menu options DisplayMenuOptions diff --git a/usr/bin/functions/ask-gpt-3.py b/usr/bin/functions/ask-gpt-3.py new file mode 100755 index 0000000..473577e --- /dev/null +++ b/usr/bin/functions/ask-gpt-3.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from time import sleep +from random import uniform +import os +import openai + +openai.api_key = os.environ['GPT_KEY'] + +prompt = input("Enter your prompt \n -> ") + +completion = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "user", "content": prompt}, + ] +) + +response = completion.choices[0].message.content + +for x in response: + print(x, end='', flush=True) + sleep(uniform(0, 0.1)) diff --git a/usr/bin/functions/display-menu-options.sh b/usr/bin/functions/display-menu-options.sh old mode 100755 new mode 100644 index e2f54b5..c841735 --- a/usr/bin/functions/display-menu-options.sh +++ b/usr/bin/functions/display-menu-options.sh @@ -1,21 +1,29 @@ #!bin/bash +# Generate random color +function random_color() { + color=$((RANDOM % 6 + 1)) + case $color in + 1) echo -ne "\e[31m" ;; # red + 2) echo -ne "\e[32m" ;; # green + 3) echo -ne "\e[33m" ;; # yellow + 4) echo -ne "\e[34m" ;; # blue + 5) echo -ne "\e[35m" ;; # purple + 6) echo -ne "\e[36m" ;; # cyan + esac +} + # Display the menu options function DisplayMenuOptions() { source /usr/bin/constants/ascii.sh - # Check if the language is Spanish - if [[ $language == "esp" ]]; then - prompt="Ingrese una opción: " - menu_options=("${menu_options_spanish[@]}") - fi - echo "$menu_top" echo "$menu_separator" for i in "${!menu_options[@]}"; do - echo -e "\033[3$((i + 1))m${menu_options[$i]}\033[0m" + color=$(random_color) + echo -e "$color ${menu_options[$i]} \e[0m" done } diff --git a/usr/bin/functions/read-arguments.sh b/usr/bin/functions/read-arguments.sh new file mode 100644 index 0000000..126ca4c --- /dev/null +++ b/usr/bin/functions/read-arguments.sh @@ -0,0 +1,49 @@ +#!bin/bash + +function ReadArguments() { + # Python functions (soon to be moved out) + UsdArs="/usr/bin/functions/usd-ars.py" + AskGPT3="/usr/bin/functions/ask-gpt-3.py" + + # Base options when no arguments is passed + export options=(DiskUsage DeleteTemporary EmptyRecycleBin UninstallPackage SystemInfo MemoryUsage Uptime OpenPorts GetWeather DownloadVideo FindFile $UsdArs $AskGPT3 exit) + + local arguments="$1" + for arg in "$arguments"; do + if [[ $arg == "--help" ]]; then + source /usr/bin/constants/help.sh # Look for a way to not source this file again + for description in "${descriptions[@]}"; do + echo "$description" + done + exit + fi + + # Check if the language is Spanish + if [[ $arg == "--esp" ]]; then + export language="esp" + export prompt="Ingrese una opción: " + menu_options=("${menu_options_spanish[@]}") + continue + fi + + # Menu choice for the system utilities + if [[ $arg == "--system" ]]; then + export options=(DiskUsage SystemInfo UninstallPackage Uptime OpenPorts MemoryUsage exit) + export menu_options=( + "1) Analyze disk usage" + "2) System information" + "3) Uninstall a package" + "4) System uptime" + "5) Open ports" + "6) Memory usage" + "7) Exit" + ) + continue + fi + + # Otherwise, store the argument in the array + args+=("$arg") + done +} + +export -f ReadArguments diff --git a/usr/bin/functions/read-prompt.sh b/usr/bin/functions/read-prompt.sh old mode 100755 new mode 100644 index a9bd8e3..035a43e --- a/usr/bin/functions/read-prompt.sh +++ b/usr/bin/functions/read-prompt.sh @@ -5,58 +5,11 @@ function ReadPrompt() { read -p "$prompt" option # Perform the action corresponding to the chosen option - case $option in - 1) - - DiskUsage - ;; - 2) - - DeleteTemporary - ;; - 3) - - EmptyRecycleBin - ;; - 4) - - UninstallPackage - ;; - 5) - - SystemInfo - ;; - 6) - - MemoryUsage - ;; - 7) - - Uptime - ;; - 8) - - OpenPorts - ;; - 9) - - GetWeather - ;; - 10) - - FindFile - ;; - 11) - - # Exit the application - exit - ;; - *) - - # Invalid argument + if [[ $option -le ${#options[@]} && $option -gt 0 ]]; then + ${options[$option - 1]} + else echo "Invalid option" - ;; - esac + fi } export -f ReadPrompt diff --git a/usr/bin/functions/unistall-package.sh b/usr/bin/functions/unistall-package.sh index c276959..5cb3c65 100755 --- a/usr/bin/functions/unistall-package.sh +++ b/usr/bin/functions/unistall-package.sh @@ -4,7 +4,7 @@ function UninstallPackage() { read -p "Enter the name of the program to uninstall: " program echo "Uninstalling $program..." - sudo dpkg --purge $program + sudo dpkg --purge "$program" } export -f UninstallPackage diff --git a/usr/bin/functions/usd-ars.py b/usr/bin/functions/usd-ars.py new file mode 100755 index 0000000..1a07a1a --- /dev/null +++ b/usr/bin/functions/usd-ars.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +# Imports +import requests + +# Constants +arrData = [] +dolarAPI = "https://api.bluelytics.com.ar/v2/latest" +sackEmoji = "💰 " +arsLabel = " ARS" + +# Get data from the api +def getData(url): + response = requests.get(url) + data = response.json() + arrData.append(data["oficial"]) + arrData.append(data["blue"]) + arrData.append(data["oficial_euro"]) + arrData.append(data["blue_euro"]) + +# Function to print the table +def print_table(data): + col_widths = [max(len(str(item)) for item in col) for col in zip(*data)] + for row in data: + print(" ".join(str(item).ljust(col_widths[i]) for i, item in enumerate(row))) + +# Main function +def main(): + getData(dolarAPI) + table_data = [["💱 Currency", "💸 Value"], + ["💵 Real", sackEmoji + str(arrData[0]["value_avg"]) + arsLabel], + ["💵 Blue", sackEmoji + str(arrData[1]["value_avg"]) + arsLabel], + ["💶 Real_Euro", sackEmoji + str(arrData[2]["value_avg"]) + arsLabel], + ["💶 Blue_Euro", sackEmoji + str(arrData[3]["value_avg"]) + arsLabel]] + print_table(table_data) + +# Init application +main() diff --git a/usr/bin/functions/weather.sh b/usr/bin/functions/weather.sh old mode 100644 new mode 100755 index d74c416..b53d19e --- a/usr/bin/functions/weather.sh +++ b/usr/bin/functions/weather.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Get current weather for the location you are +# Get current weather for the location you are, repo -> https://github.com/chubin/wttr.in function GetWeather() { curl wttr.in } diff --git a/usr/bin/functions/youtube-downloader.sh b/usr/bin/functions/youtube-downloader.sh new file mode 100644 index 0000000..07242e7 --- /dev/null +++ b/usr/bin/functions/youtube-downloader.sh @@ -0,0 +1,9 @@ +#!bin/bash + +# Downloads a video from Youtube with yt-dlp -> https://github.com/yt-dlp/yt-dlp +function DownloadVideo() { + read -p "Enter the video you want to download: " video + yt-dlp "$video" +} + +export -f DownloadVideo diff --git a/utils/build_new_version.sh b/utils/build_new_version.sh index 325b6b9..e32bea6 100755 --- a/utils/build_new_version.sh +++ b/utils/build_new_version.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Starting message +echo "Building latest version of the package..." + # Find version of the package and save it in a variable file=$(find . -name 'control') string="Version" @@ -11,19 +14,24 @@ while read -r line; do done <$file # We locate where the folder is located and move to it -folder=$(find $HOME -type d -name "dbn-tools") -cd $folder +folder=$(find $HOME -type d -name "dbn-tools" -print | tail -n 1) +cd "$folder" # We create a folder for the build and copy the entire file one level above -mkdir -p -- ../"$version-dbn-tools" +cd .. +mkdir -p -- "$version-dbn-tools" copy=$(find $HOME -type d -name ${version}"-dbn-tools") -cp -r $folder/* $copy +cp -r $folder/* "$copy" # Move to the copy directory -cd $copy +cd "$copy" -# We remove git since we don't want it the final build +# We remove git since we don't want it in the final build rm -rf .git +rm LICENSE +rm Makefile +rm -- *.png +rm -- *.md # Move out of the copy directory cd .. diff --git a/utils/debian_builder.sh b/utils/debian_builder.sh index a933d73..cc4cb55 100755 --- a/utils/debian_builder.sh +++ b/utils/debian_builder.sh @@ -3,7 +3,7 @@ echo "Path to the original .deb file -> " read -n path -ar x $path +ar x "$path" zstd -d control.tar.xz zstd -d data.tar.xz ar -m -c -a debian-binary control.tar.xz data.tar.xz debian_repacked.deb diff --git a/utils/source_files.sh b/utils/source_files.sh deleted file mode 100755 index 6ee80b5..0000000 --- a/utils/source_files.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!bin/bash - -### NOT BEING USED ATM ### - -# Source all the files given a path -function SourceFiles() { - if [[ $# -eq 0 ]]; then - echo "Error: No path provided" - return 1 - fi - - for file in "$1"/*; do - source "$file" - done -} - -export -f SourceFiles