Coder Social home page Coder Social logo

dsu's Introduction

Diomeh's Script Utilities

Overview

A set of utilities to handle various file operations like

  • file backup and restore
  • archive extraction
  • file cleaning
  • copying and pasting from and to the shell

Getting started

Two distribution method are available, either:

  • standalone bash scripts
  • rust CLI tool

Standalone bash scripts

Please refer to the wiki for information on building and running the standalone bash scripts; Alternatively you can find a pre-built tarball in the releases page.

Rust CLI tool

A unix binary named as dsu-X-Y-Z can be found in the releases page where X-Y-Z is the version number. Alternatively you can build it on your own.

Usage

Ensure that the utility is executable by running the following command:

chmod +x dsu-X-Y-Z

Run the utility with the --help flag to see the available options and how to use them:

./dsu-X-Y-Z --help

Each utility has its own set of options and arguments that you can see running the --help flag with the utility name:

./dsu-X-Y-Z <utility> --help

For a breakdown of all the utilities, their options and what do they do please refer to the wiki

Installation

There are several different ways to install the utility on your system:

  • copy|install the binary to a directory in your PATH
  • create a symbolic link to the binary in a directory in your PATH
  • install it globally to /opt/dsu and make that directory part of your PATH

Installing to a directory in your PATH

To install the utility you can copy the binary to a directory in your PATH. Common directories are:

  • Single user:
    • ~/.local/bin
    • ~/bin
  • System-wide:
    • /usr/local/bin
    • /usr/bin
    • /opt

For single user:

install -Dm755 dsu-X-Y-Z ~/.local/bin/dsu

Or

mkdir -p ~/.local/bin
cp dsu-X-Y-Z ~/.local/bin/dsu
chmod +x ~/.local/bin/dsu

For system-wide:

Note that you may need to run this command as root or with sudo.

install -Dm755 dsu-X-Y-Z /usr/local/bin/dsu

Or

mkdir -p /usr/local/bin
cp dsu-X-Y-Z /usr/local/bin/dsu
chmod +x /usr/local/bin/dsu

Creating a symbolic link

You can also create a symbolic link to the binary in a directory in your PATH. This is useful if you want to keep the binary in a different directory than the one in your PATH.

For single user:

ln -s /path/to/dsu-X-Y-Z ~/.local/bin/dsu

For system-wide:

Note that you may need to run this command as root or with sudo.

ln -s /path/to/dsu-X-Y-Z /usr/local/bin/dsu

Installing to /opt

As a third option, you can install the utility globally to /opt/dsu and make that directory part of your PATH.

Note that you'll need sudo or root permissions to do this.

First, create the directory:

mkdir -p /opt/dsu

Then copy the binary to the directory:

cp dsu-X-Y-Z /opt/dsu/dsu
chmod +x /opt/dsu/dsu

Add the directory to your PATH by adding the following line to your shell configuration file (e.g. ~/.bashrc, ~/.zshrc, etc.):

# Add diomeh's script utilities to PATH
export PATH="$PATH:/opt/dsu"

Finally, source the shell configuration file to apply the changes:

source ~/.bashrc

This will ensure that the binary is always available at /opt/dsu/dsu no matter the version. If you want to update the binary, simply replace the symbolic link with a new one pointing to the new one.

Uninstallation

To uninstall the utility, simply remove the binary from the directory where you installed it.

  • If you installed it to a directory in your PATH, remove the binary from that directory.
  • If you created a symbolic link, remove the symbolic link.
  • If you installed it to /opt, remove the binary from /opt/dsu.
    • Also remove the directory from your PATH in your shell configuration file.

Local development

To build the rust CLI tool, you will need to have the rust toolchain installed on your system. Please refer to the rust website for instructions on how to install the rust toolchain.

bacon is used as the build tool for this project. To install bacon, run the following command:

cargo install bacon

Afterwards you can build the project by running the following command:

bacon

This will build and watch for any changes in the source code and rebuild the project automatically. For more information on how to use bacon, please refer to the bacon documentation and the bacon config file.

Project structure

Each utility is defined as a module in the src directory. The main entry point for the CLI tool is in the src/main.rs file.

The module src/cli.rs contains the command line interface for dsu and defines all options and arguments for both the tool itself and all the utilities.

Testing

As of now, testing has only been implemented for standalone bash scripts. Refer to the bash scripts wiki for more information on how to run the tests.

Deployment

To deploy the rust CLI tool, you can run the following command:

cargo build --release

This will build the project in release mode and create a binary optimized for release in the target/release directory.

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

dsu's People

Contributors

diomeh avatar dependabot[bot] avatar

Watchers

 avatar

dsu's Issues

[FEATREQ] Add dry run to bash scripts

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Add a dry run (-n | --dry) flag to every script

Describe alternatives you've considered
None

Additional context
None

[FEATREQ] Implement rust CLI tool support for (un)installer

Is your feature request related to a problem? Please describe.
Both installer and uninstaller scripts should have mechanisms to let the user choose which tool to use (either rust CLI or bash), or maybe even both

Describe the solution you'd like
Possibly prompt the user for tools to install or command line arguments to auto select

Describe alternatives you've considered
None

Additional context
None

[FEATREQ] Refactor bash files according to standard

Is your feature request related to a problem? Please describe.
I would be a good idea to stick with a set or style rules for bash.

Describe the solution you'd like
Write bash according to rules

Describe alternatives you've considered
Remain as is.

Additional context
None

[FEATREQ] [bash,rust] implement shell completion

Is your feature request related to a problem? Please describe.
Improvement

Describe the solution you'd like
Implement shell completion for all scripts in both rust and bash tools

Describe alternatives you've considered
Remain as-is.

Additional context
None

[BUG] [bash] Possible race condition when operating on files

Describe the bug
For any bash scripts that operates on files, a race condition can be met.

Currently, all files are checked for existence and permission before trying to perform any operation on them. If at any point in time after checks are done but before files are operated on another process or script alters said file (e.g. file is deleted) we'll hit an unhandled error and possibly undefined behavior.

Instead of checking files before operation, we should simply operate on them and handle any kind of error that occurs

To Reproduce
Steps to reproduce the behavior:

  1. Run restore for a backup of a file that already exists
  2. Wait for override prompt to display
  3. On another terminal, delete backup file
  4. Go back to restore and confirm prompt
  5. Race condition hit

Expected behavior
Simply handle errors as they occur, without doing checks for it.
Directories could always be mkdir p as if they already exists nothing happens.

Screenshots
If applicable, add screenshots to help explain your problem.

System info:

  • Tool type [bash, rust]
  • Tool version: 2.2.10
  • Distro: NixOS 24.05 (Uakari)

Additional context
None.

[BUG] Cannot extract zip archives

Describe the bug
When trying to extract a zip archive, utility fails with:

unzip:  cannot find or open /tmp/tmp.GEhAaVivh1, /tmp/tmp.GEhAaVivh1.zip or /tmp/tmp.GEhAaVivh1.ZIP.

To Reproduce
Steps to reproduce the behavior:

  1. Exec xtract archive.zip

Expected behavior
Archive should be extracted in current directory

Screenshots
None

System info:

  • Tool type: bash
  • Tool version: 2.1.23
  • Distro: NixOS 24.05

Additional context
None

[FEATREQ] [bash,rust] manpages should be added

Is your feature request related to a problem? Please describe.
No problems, just general improvements

Describe the solution you'd like
It is a good idea to write manpages for all scripts.

Describe alternatives you've considered
Remain as-is

Additional context
None

[BUG] [bash] `cln.sh` is not working

Describe the bug
When run, cln.sh does nothing
When run with any number of file paths fails with [ERROR] Unknown option: <paths>

To Reproduce
Steps to reproduce the behavior:

  1. Run cln
    or
  2. Run cln ./

Expected behavior
Script should properly clean file names

Screenshots
image

System info:

  • Tool type: bash
  • Tool version: v2.1.30
  • Distro: NixOS 24.05

Additional context
None

[BUG] Cannot extract `7z` archives

Describe the bug
When running xtract on .7z archives, utility fails with

Command Line Error:
Too short switch:
-o

To Reproduce
Steps to reproduce the behavior:

  1. Exec xtract archive.7z

Expected behavior
Archive should be extracted in current directory

Screenshots
None

System info:

  • Tool type: bash
  • Tool version: 2.1.22
  • Distro: NixOS 24.05

Additional context
None

[BUG] [bash: copy/paste] missing call to `main`

Describe the bug
Both copy and paste bash scripts are missing call to main function

Expected behavior
Scripts should operate normally

Screenshots
If applicable, add screenshots to help explain your problem.

System info:

  • Tool type [bash]
  • Tool version: 2.2.10
  • Distro: "NixOS 24.05 (Uakari)"

Additional context
Add any other context about the problem here.

[BUG] [bash] tools are broken

Describe the bug
When running tests for bash scripts, most fail.

  • backup: test failed during backup operation with exit code 127
  • cln: failed to change to test directory
  • xtract failed to change to test directory

To Reproduce
Steps to reproduce the behavior:

  1. cd into repo
  2. run bash tests ./test/run.sh

Expected behavior
Tests should succeed.

Screenshots
If applicable, add screenshots to help explain your problem.
image

System info:

  • Tool type: bash
  • Tool version: v2.2.0
  • Distro: NixOS 24.05

Additional context
None.

[BUG] [all] Calling `--check-version` fails with `404`

Describe the bug
When any tool is called with --check-version flag, it fails with 404 not found

To Reproduce
Steps to reproduce the behavior:

  1. Call any tool hog --check-version
  2. See error [INFO] A new version of hog (404:NotFound) is available!

Expected behavior
Request should not fail

Screenshots
image

System info:

  • Tool type: all
  • Tool version: v2.2.8
  • Distro: NixOS 24.05

Additional context
None.

[FEATREQ] [bash] Add support for colored output

Is your feature request related to a problem? Please describe.
Rather an improvement

Describe the solution you'd like
Add support for ANSI color escape codes on bash script's output

  • Make it opt-out either via env vars NOCOLOR, NO_COLOR, TERM or --color flag

Describe alternatives you've considered
Remain as-is

Additional context
None

[FEATREQ] [bash] add support for tests

Is your feature request related to a problem? Please describe.
Rather an improvement.

Describe the solution you'd like
Currently the implemented tests are really limited in scope and capability, it'll be a net positive to write in-depth unit tests using shunit2

Describe alternatives you've considered
Remain writing our own test library.

Additional context
None.

[FEATREQ] Add an update tracking system

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Adding a routine for checking currently running version against the latest release and hints on how to update

Would be a good idea to add it to .sh scripts too.

Describe alternatives you've considered
Publish crate to crates.io and let cargo handle it.

Additional context
None

[FEATREQ] [rust] add ANSI colored output support

Is your feature request related to a problem? Please describe.
Rather an improvement

Describe the solution you'd like
Add support for ANSI color escape codes on bash script's output

  • Make it opt-out either via env vars NOCOLOR, NO_COLOR, TERM or --color flag

Describe alternatives you've considered
Remain as-is

Additional context
None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.