Small collection of Bash scripts to launch functionalities in folders when new files appear, such as optimizing videos, converting images or battery management.
Go to file
Andros Fenollosa b16215e58d Update brand
2023-05-02 15:51:22 +02:00
assets Update brand 2023-05-02 15:51:22 +02:00
bash-folders-battery-hook.sh Add battery script 2023-05-02 15:36:38 +02:00
bash-folders-decompress.sh Finish descompress 2023-04-19 22:44:25 +02:00
bash-folders-image-to-webp.sh Update name 2023-04-19 19:32:45 +02:00
bash-folders-random-image.sh Update name 2023-04-19 19:32:45 +02:00
bash-folders-share-files.sh Update name 2023-04-19 19:32:45 +02:00
bash-folders-video-optimizer.sh Update bash-folders-video-optimizer.sh 2023-05-01 19:30:37 +02:00
LICENSE Initial commit 2023-03-21 19:06:21 +01:00
README.md Update brand 2023-05-02 15:51:22 +02:00

Bash folders

Bash folder brand

Collection of Bash scripts to execute functionalities in folders, such as optimizing videos, unzipping files, converting images, etc.


Video optimizer

Folder that watches when new videos are added and optimizes them.

Requirements

  • inotify-tools
  • ffmpeg

Example in Debian.

sudo apt install inotify-tools ffmpeg

Install

curl -o bash-folders-video-optimizer https://raw.githubusercontent.com/tanrax/bash-folders/main/bash-folders-video-optimizer.sh && chmod +x bash-folders-video-optimizer && sudo mv bash-folders-video-optimizer /usr/local/bin && echo "🎉 Successfully installed! 🎉"

Test

bash-folders-video-optimizer --help

Run

bash-folders-video-optimizer --folder [folder to watch]

Example.

mkdir optimizer
bash-folders-video-optimizer --folder optimizer

And leave a video that you want to optimize in the folder optimizer.

Start at operating system startup

Option 1: Service

Create a file in /etc/systemd/system/bash-folders-video-optimizer.service with the following content.

[Unit]
Description=Folder that watches when new videos are added and optimizes them.

[Service]
Restart=always
RestartSec=5
User=[user]
ExecStart=bash-folders-video-optimizer --folder [folder to watch]

[Install]
WantedBy=multi-user.target

Edit it to your needs.

Recharge services.

sudo systemctl daemon-reload

And activate it.

sudo systemctl enable bash-folders-video-optimizer
sudo systemctl start bash-folders-video-optimizer

Option 2: Cron

Open.

crontab -e

Add to document.

@reboot bash-folders-video-optimizer --folder [folder to watch] >/dev/null 2>&1 &

Battery hook

Folder with scripts to be launched in different battery states.

The filename of the scripts must be:

  • discharging: When the battery is in use.
  • charging: When the battery is charging.
  • low: When it reaches the low percentage. Default 15.
  • high: When it reaches the high percentage. Default 85.
  • full: When the battery is full.

They must have execution permissions. If any of them do not exist, they will be ignored.

Install

curl -o bash-folders-battery-hook https://raw.githubusercontent.com/tanrax/bash-folders/main/bash-folders-battery-hook.sh && chmod +x bash-folders-battery-hook && sudo mv bash-folders-battery-hook /usr/local/bin && echo "🎉 Successfully installed! 🎉"

Test

bash-folders-battery-hook --help

Run

bash-folders-battery-hook --folder [folder path]

Example.

mkdir battery-scripts

touch battery-scripts/discharging
chmod +x battery-scripts/discharging
touch battery-scripts/charging
chmod +x battery-scripts/charging
touch battery-scripts/low
chmod +x battery-scripts/low
touch battery-scripts/high
chmod +x battery-scripts/high
touch battery-scripts/full
chmod +x battery-scripts/full

bash-folders-battery-hook --folder battery-scripts

Start at operating system startup

Option 1: Service

Create a file in /etc/systemd/system/bash-folders-battery-hook.service with the following content.

[Unit]
Description=Folder with scripts to be launched in different battery states.

[Service]
Restart=always
RestartSec=5
User=[user]
ExecStart=bash-folders-battery-hook --folder [folder path]

[Install]
WantedBy=multi-user.target

Edit it to your needs.

Now you will need the script to run every so often to check the battery status. The best solution is to create a timer.

Create a file in /etc/systemd/system/bash-folders-battery-hook.timer with the following content.

[Unit]
Description=Folder with scripts to be launched in different battery states every minute.

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true

[Install]
WantedBy=timers.target

Recharge services.

sudo systemctl daemon-reload

And activate it.

sudo systemctl enable bash-folders-battery-hook.timer
sudo systemctl start bash-folders-battery-hook.timer

Option 2: Cron

Open.

crontab -e

Add to document.

@reboot * * * * * bash-folders-battery-hook --folder [folder path]

Development

Check syntax

shellcheck [script]