2023-04-19 19:32:45 +02:00
|
|
|
# Bash folders
|
2023-03-22 00:42:07 +01:00
|
|
|
|
2023-05-02 16:03:10 +02:00
|
|
|
![Bash folder brand](assets/social.webp)
|
2023-05-02 15:48:43 +02:00
|
|
|
|
2023-05-02 16:03:58 +02:00
|
|
|
Collection of Bash scripts to execute functionalities in folders, such as:
|
2023-04-04 09:13:39 +02:00
|
|
|
|
2023-05-05 13:36:26 +02:00
|
|
|
- [Video optimizer](#video-optimizer): Folder that watches when new videos are added and optimizes them.
|
|
|
|
- [Battery hook](#battery-hook): Folder with custom scripts to be launched in different battery states.
|
|
|
|
- [Image to webp](#image-to-webp): Folder that watches when new image (PNG or JPEG) are added and transform to WebP format.
|
2023-04-19 19:32:45 +02:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## Video optimizer
|
2023-04-18 12:56:23 +02:00
|
|
|
|
2023-04-18 15:27:40 +02:00
|
|
|
Folder that watches when new videos are added and optimizes them.
|
|
|
|
|
2023-04-18 12:56:23 +02:00
|
|
|
### Requirements
|
|
|
|
|
|
|
|
- `ffmpeg`
|
|
|
|
|
|
|
|
Example in Debian.
|
|
|
|
|
|
|
|
``` sh
|
2023-05-02 16:18:26 +02:00
|
|
|
sudo apt install ffmpeg
|
2023-04-18 12:56:23 +02:00
|
|
|
```
|
2023-04-04 09:13:39 +02:00
|
|
|
|
|
|
|
### Install
|
|
|
|
|
|
|
|
|
2023-04-18 12:56:23 +02:00
|
|
|
``` sh
|
2023-05-03 19:42:05 +02:00
|
|
|
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 rm -f /usr/local/bin/bash-folders-video-optimizer && sudo mv bash-folders-video-optimizer /usr/local/bin && echo "🎉 Successfully installed! 🎉"
|
2023-04-18 14:11:54 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Test
|
|
|
|
|
|
|
|
``` sh
|
2023-04-19 19:32:45 +02:00
|
|
|
bash-folders-video-optimizer --help
|
2023-04-18 12:56:23 +02:00
|
|
|
```
|
2023-04-04 09:13:39 +02:00
|
|
|
|
2023-04-18 12:56:23 +02:00
|
|
|
### Run
|
|
|
|
|
|
|
|
``` sh
|
2023-04-19 19:32:45 +02:00
|
|
|
bash-folders-video-optimizer --folder [folder to watch]
|
2023-04-18 14:11:54 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Example.
|
|
|
|
|
|
|
|
``` sh
|
2023-04-18 16:48:54 +02:00
|
|
|
mkdir optimizer
|
2023-04-19 19:32:45 +02:00
|
|
|
bash-folders-video-optimizer --folder optimizer
|
2023-04-18 12:38:12 +02:00
|
|
|
```
|
|
|
|
|
2023-04-18 14:11:54 +02:00
|
|
|
And leave a video that you want to optimize in the folder `optimizer`.
|
|
|
|
|
2023-04-18 16:43:18 +02:00
|
|
|
### Start at operating system startup
|
|
|
|
|
|
|
|
#### Option 1: Service
|
2023-04-18 12:56:23 +02:00
|
|
|
|
2023-04-19 19:32:45 +02:00
|
|
|
Create a file in `/etc/systemd/system/bash-folders-video-optimizer.service` with the following content.
|
2023-04-18 14:11:54 +02:00
|
|
|
|
|
|
|
|
2023-04-18 12:38:12 +02:00
|
|
|
```ini
|
|
|
|
[Unit]
|
2023-04-18 15:27:40 +02:00
|
|
|
Description=Folder that watches when new videos are added and optimizes them.
|
2023-04-18 12:38:12 +02:00
|
|
|
|
|
|
|
[Service]
|
|
|
|
Restart=always
|
|
|
|
RestartSec=5
|
2023-04-18 12:56:23 +02:00
|
|
|
User=[user]
|
2023-04-19 19:32:45 +02:00
|
|
|
ExecStart=bash-folders-video-optimizer --folder [folder to watch]
|
2023-04-18 12:38:12 +02:00
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
2023-04-18 14:11:54 +02:00
|
|
|
Edit it to your needs.
|
|
|
|
|
|
|
|
Recharge services.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
```
|
|
|
|
|
|
|
|
And activate it.
|
|
|
|
|
|
|
|
``` sh
|
2023-04-19 19:32:45 +02:00
|
|
|
sudo systemctl enable bash-folders-video-optimizer
|
|
|
|
sudo systemctl start bash-folders-video-optimizer
|
2023-04-18 14:11:54 +02:00
|
|
|
```
|
|
|
|
|
2023-04-18 16:43:18 +02:00
|
|
|
#### Option 2: Cron
|
2023-04-18 14:11:54 +02:00
|
|
|
|
|
|
|
Open.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
crontab -e
|
|
|
|
```
|
|
|
|
|
|
|
|
Add to document.
|
|
|
|
|
|
|
|
``` sh
|
2023-04-19 19:32:45 +02:00
|
|
|
@reboot bash-folders-video-optimizer --folder [folder to watch] >/dev/null 2>&1 &
|
2023-04-18 14:11:54 +02:00
|
|
|
```
|
|
|
|
|
2023-04-19 19:32:45 +02:00
|
|
|
---
|
|
|
|
|
2023-05-02 15:36:38 +02:00
|
|
|
## Battery hook
|
|
|
|
|
2023-05-02 16:09:06 +02:00
|
|
|
Folder with custom scripts to be launched in different battery states.
|
2023-05-02 15:36:38 +02:00
|
|
|
|
2023-05-02 16:09:06 +02:00
|
|
|
The filename of the scripts, or your custom scripts, must be:
|
2023-05-02 15:36:38 +02:00
|
|
|
|
|
|
|
- `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
|
|
|
|
|
|
|
|
|
|
|
|
``` sh
|
2023-05-03 19:42:05 +02:00
|
|
|
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 rm -f /usr/local/bin/bash-folders-battery-hook && sudo mv bash-folders-battery-hook /usr/local/bin && echo "🎉 Successfully installed! 🎉"
|
2023-05-02 15:36:38 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Test
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
bash-folders-battery-hook --help
|
|
|
|
```
|
|
|
|
|
|
|
|
### Run
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
bash-folders-battery-hook --folder [folder path]
|
|
|
|
```
|
|
|
|
|
|
|
|
Example.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
mkdir battery-scripts
|
|
|
|
|
|
|
|
bash-folders-battery-hook --folder battery-scripts
|
|
|
|
```
|
|
|
|
|
2023-05-03 19:55:55 +02:00
|
|
|
Inside the folder all the empty scripts will be created, which you will have to edit to include the instructions in Bash.
|
|
|
|
|
2023-05-02 15:36:38 +02:00
|
|
|
### Start at operating system startup
|
|
|
|
|
|
|
|
#### Option 1: Service
|
|
|
|
|
|
|
|
Create a file in `/etc/systemd/system/bash-folders-battery-hook.service` with the following content.
|
|
|
|
|
|
|
|
|
|
|
|
```ini
|
|
|
|
[Unit]
|
2023-05-02 16:09:06 +02:00
|
|
|
Description=Folder with custom scripts to be launched in different battery states.
|
2023-05-02 15:36:38 +02:00
|
|
|
|
|
|
|
[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.
|
|
|
|
|
|
|
|
```ini
|
|
|
|
[Unit]
|
2023-05-02 16:09:06 +02:00
|
|
|
Description=Folder with custom scripts to be launched in different battery states every minute.
|
2023-05-02 15:36:38 +02:00
|
|
|
|
|
|
|
[Timer]
|
|
|
|
OnCalendar=*-*-* *:*:00
|
|
|
|
Persistent=true
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
```
|
|
|
|
|
|
|
|
Recharge services.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
```
|
|
|
|
|
|
|
|
And activate it.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo systemctl enable bash-folders-battery-hook.timer
|
|
|
|
sudo systemctl start bash-folders-battery-hook.timer
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Option 2: Cron
|
|
|
|
|
|
|
|
Open.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
crontab -e
|
|
|
|
```
|
|
|
|
|
|
|
|
Add to document.
|
|
|
|
|
|
|
|
``` sh
|
2023-05-02 16:06:02 +02:00
|
|
|
* * * * * bash-folders-battery-hook --folder [folder path]
|
2023-05-02 15:36:38 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2023-05-05 13:17:03 +02:00
|
|
|
## Image to WebP
|
|
|
|
|
|
|
|
Folder that watches when new image (PNG or JPEG) are added and transform to WebP format.
|
|
|
|
|
|
|
|
### Requirements
|
|
|
|
|
|
|
|
- `webp`
|
|
|
|
|
|
|
|
Example in Debian.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo apt install webp
|
|
|
|
```
|
|
|
|
|
|
|
|
### Install
|
|
|
|
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
curl -o bash-folders-image-to-webp https://raw.githubusercontent.com/tanrax/bash-folders/main/bash-folders-image-to-webp.sh && chmod +x bash-folders-image-to-webp && sudo rm -f /usr/local/bin/bash-folders-image-to-webp && sudo mv bash-folders-image-to-webp /usr/local/bin && echo "🎉 Successfully installed! 🎉"
|
|
|
|
```
|
|
|
|
|
|
|
|
Test
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
bash-folders-image-to-webp --help
|
|
|
|
```
|
|
|
|
|
|
|
|
### Run
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
bash-folders-image-to-webp --folder [folder to watch]
|
|
|
|
```
|
|
|
|
|
|
|
|
Example.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
mkdir image-to-webp-converter
|
|
|
|
bash-folders-image-to-webp --folder image-to-webp-converter
|
|
|
|
```
|
|
|
|
|
|
|
|
And leave a image that you want to optimize in the folder `image-to-webp-converter`.
|
|
|
|
|
|
|
|
### Start at operating system startup
|
|
|
|
|
|
|
|
#### Option 1: Service
|
|
|
|
|
|
|
|
Create a file in `/etc/systemd/system/bash-folders-image-to-webp.service` with the following content.
|
|
|
|
|
|
|
|
|
|
|
|
```ini
|
|
|
|
[Unit]
|
|
|
|
Description=Folder that watches when new image (PNG or JPEG) are added and transform to WebP format.
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Restart=always
|
|
|
|
RestartSec=5
|
|
|
|
User=[user]
|
|
|
|
ExecStart=bash-folders-image-to-webp --folder [folder to watch]
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
|
|
|
Edit it to your needs.
|
|
|
|
|
|
|
|
Recharge services.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
```
|
|
|
|
|
|
|
|
And activate it.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
sudo systemctl enable bash-folders-image-to-webp
|
|
|
|
sudo systemctl start bash-folders-image-to-webp
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Option 2: Cron
|
|
|
|
|
|
|
|
Open.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
crontab -e
|
|
|
|
```
|
|
|
|
|
|
|
|
Add to document.
|
|
|
|
|
|
|
|
``` sh
|
|
|
|
@reboot bash-folders-image-to-webp --folder [folder to watch] >/dev/null 2>&1 &
|
|
|
|
```
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2023-04-04 09:13:39 +02:00
|
|
|
## Development
|
|
|
|
|
|
|
|
### Check syntax
|
|
|
|
|
|
|
|
```sh
|
|
|
|
shellcheck [script]
|
|
|
|
```
|