mirror of
https://github.com/tanrax/bash-folders.git
synced 2024-12-22 18:25:35 +01:00
Update bash script
This commit is contained in:
parent
c7ee202c89
commit
84bba67307
@ -28,7 +28,7 @@ sudo apt install ffmpeg
|
|||||||
|
|
||||||
|
|
||||||
``` sh
|
``` sh
|
||||||
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! 🎉"
|
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! 🎉"
|
||||||
```
|
```
|
||||||
|
|
||||||
Test
|
Test
|
||||||
@ -122,7 +122,7 @@ They must have **execution permissions**. If any of them do not exist, they will
|
|||||||
|
|
||||||
|
|
||||||
``` sh
|
``` sh
|
||||||
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! 🎉"
|
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! 🎉"
|
||||||
```
|
```
|
||||||
|
|
||||||
Test
|
Test
|
||||||
|
@ -9,21 +9,6 @@
|
|||||||
# START
|
# START
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# VARIABLES
|
|
||||||
PROGNAME=$(basename "$0")
|
|
||||||
FOLDER_ORIGIN="$2"
|
|
||||||
LOW_BATTERY=15
|
|
||||||
HIGH_BATTERY=85
|
|
||||||
DISCHARGING_SCRIPT="discharging"
|
|
||||||
PATH_DISCHARGING_SCRIPT="$FOLDER_ORIGIN/$DISCHARGING_SCRIPT"
|
|
||||||
CHARGING_SCRIPT="charging"
|
|
||||||
PATH_CHARGING_SCRIPT="$FOLDER_ORIGIN/$CHARGING_SCRIPT"
|
|
||||||
LOW_SCRIPT="low"
|
|
||||||
PATH_LOW_SCRIPT="$FOLDER_ORIGIN/$LOW_SCRIPT"
|
|
||||||
HIGH_SCRIPT="high"
|
|
||||||
PATH_HIGH_SCRIPT="$FOLDER_ORIGIN/$HIGH_SCRIPT"
|
|
||||||
FULL_SCRIPT="full"
|
|
||||||
PATH_FULL_SCRIPT="$FOLDER_ORIGIN/$FULL_SCRIPT"
|
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
|
|
||||||
@ -63,65 +48,65 @@ capacity() {
|
|||||||
|
|
||||||
run_discharging() {
|
run_discharging() {
|
||||||
# Check if discharging script exists
|
# Check if discharging script exists
|
||||||
if [ ! -f $PATH_DISCHARGING_SCRIPT ]; then
|
if [ ! -f "$PATH_DISCHARGING_SCRIPT" ]; then
|
||||||
# If not, create it
|
# If not, create it
|
||||||
touch $PATH_DISCHARGING_SCRIPT
|
touch "$PATH_DISCHARGING_SCRIPT"
|
||||||
chmod +x $PATH_DISCHARGING_SCRIPT
|
chmod +x "$PATH_DISCHARGING_SCRIPT"
|
||||||
fi
|
fi
|
||||||
# If status is discharging, run discharging script
|
# If status is discharging, run discharging script
|
||||||
if [ $(status) = "Discharging" ]; then
|
if [ "$(status)" = "Discharging" ]; then
|
||||||
$PATH_DISCHARGING_SCRIPT
|
$PATH_DISCHARGING_SCRIPT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_charging() {
|
run_charging() {
|
||||||
# Check if charging script exists
|
# Check if charging script exists
|
||||||
if [ ! -f $PATH_CHARGING_SCRIPT ]; then
|
if [ ! -f "$PATH_CHARGING_SCRIPT" ]; then
|
||||||
# If not, create it
|
# If not, create it
|
||||||
touch $PATH_CHARGING_SCRIPT
|
touch "$PATH_CHARGING_SCRIPT"
|
||||||
chmod +x $PATH_CHARGING_SCRIPT
|
chmod +x "$PATH_CHARGING_SCRIPT"
|
||||||
fi
|
fi
|
||||||
# If status is charging, run charging script
|
# If status is charging, run charging script
|
||||||
if [ $(status) = "Charging" ]; then
|
if [ "$(status)" = "Charging" ]; then
|
||||||
$PATH_CHARGING_SCRIPT
|
$PATH_CHARGING_SCRIPT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_low() {
|
run_low() {
|
||||||
# Check if low script exists
|
# Check if low script exists
|
||||||
if [ ! -f $PATH_LOW_SCRIPT ]; then
|
if [ ! -f "$PATH_LOW_SCRIPT" ]; then
|
||||||
# If not, create it
|
# If not, create it
|
||||||
touch $PATH_LOW_SCRIPT
|
touch "$PATH_LOW_SCRIPT"
|
||||||
chmod +x $PATH_LOW_SCRIPT
|
chmod +x "$PATH_LOW_SCRIPT"
|
||||||
fi
|
fi
|
||||||
# If status is discharging and battery is low, run low script
|
# If status is discharging and battery is low, run low script
|
||||||
if [ $(status) = "Discharging" ] && [ $(capacity) -le $LOW_BATTERY ]; then
|
if [ "$(status)" = "Discharging" ] && [ "$(capacity)" -le "$LOW_BATTERY" ]; then
|
||||||
$PATH_LOW_SCRIPT
|
$PATH_LOW_SCRIPT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_high() {
|
run_high() {
|
||||||
# Check if high script exists
|
# Check if high script exists
|
||||||
if [ ! -f $PATH_HIGH_SCRIPT ]; then
|
if [ ! -f "$PATH_HIGH_SCRIPT" ]; then
|
||||||
# If not, create it
|
# If not, create it
|
||||||
touch $PATH_HIGH_SCRIPT
|
touch "$PATH_HIGH_SCRIPT"
|
||||||
chmod +x $PATH_HIGH_SCRIPT
|
chmod +x "$PATH_HIGH_SCRIPT"
|
||||||
fi
|
fi
|
||||||
# If status is charging and battery is high, run high script
|
# If status is charging and battery is high, run high script
|
||||||
if [ $(status) = "Charging" ] && [ $(capacity) -ge $HIGH_BATTERY ]; then
|
if [ "$(status)" = "Charging" ] && [ "$(capacity)" -ge "$HIGH_BATTERY" ]; then
|
||||||
$PATH_HIGH_SCRIPT
|
$PATH_HIGH_SCRIPT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_full() {
|
run_full() {
|
||||||
# Check if full script exists
|
# Check if full script exists
|
||||||
if [ ! -f $PATH_FULL_SCRIPT ]; then
|
if [ ! -f "$PATH_FULL_SCRIPT" ]; then
|
||||||
# If not, create it
|
# If not, create it
|
||||||
touch $PATH_FULL_SCRIPT
|
touch "$PATH_FULL_SCRIPT"
|
||||||
chmod +x $PATH_FULL_SCRIPT
|
chmod +x "$PATH_FULL_SCRIPT"
|
||||||
fi
|
fi
|
||||||
# If status is charging and battery is full, run full script
|
# If status is charging and battery is full, run full script
|
||||||
if [ $(status) = "Full" ]; then
|
if [ "$(status)" = "Full" ]; then
|
||||||
$PATH_FULL_SCRIPT
|
$PATH_FULL_SCRIPT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -136,36 +121,53 @@ start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# CONTROLE ARGUMENTS
|
# CONTROLE ARGUMENTS
|
||||||
isArg=""
|
|
||||||
|
|
||||||
while [ $# -gt 0 ] ; do
|
# Parse command line arguments
|
||||||
case "$1" in
|
while [[ $# -gt 0 ]]
|
||||||
--help)
|
do
|
||||||
usage
|
key="$1"
|
||||||
;;
|
case $key in
|
||||||
--folder)
|
--folder)
|
||||||
isArg="1"
|
FOLDER_ORIGIN="$2"
|
||||||
if [ $# -eq 2 ]; then
|
shift # past argument
|
||||||
start
|
shift # past value
|
||||||
else
|
|
||||||
usage "You need to specify the path of different scripts are located."
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
--low)
|
--low)
|
||||||
if [ $# -eq 2 ]; then
|
LOW_BATTERY="$2"
|
||||||
LOW_BATTERY=$2
|
shift # past argument
|
||||||
fi
|
shift # past value
|
||||||
;;
|
;;
|
||||||
--high)
|
--high)
|
||||||
if [ $# -eq 2 ]; then
|
HIGH_BATTERY="$2"
|
||||||
HIGH_BATTERY=$2
|
shift # past argument
|
||||||
fi
|
shift # past value
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
usage "Unknown option: $1"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z $isArg ] ; then
|
|
||||||
usage "Not enough arguments"
|
# VARIABLES
|
||||||
|
PROGNAME=$(basename "$0")
|
||||||
|
LOW_BATTERY=15
|
||||||
|
HIGH_BATTERY=85
|
||||||
|
DISCHARGING_SCRIPT="discharging"
|
||||||
|
PATH_DISCHARGING_SCRIPT="$FOLDER_ORIGIN/$DISCHARGING_SCRIPT"
|
||||||
|
CHARGING_SCRIPT="charging"
|
||||||
|
PATH_CHARGING_SCRIPT="$FOLDER_ORIGIN/$CHARGING_SCRIPT"
|
||||||
|
LOW_SCRIPT="low"
|
||||||
|
PATH_LOW_SCRIPT="$FOLDER_ORIGIN/$LOW_SCRIPT"
|
||||||
|
HIGH_SCRIPT="high"
|
||||||
|
PATH_HIGH_SCRIPT="$FOLDER_ORIGIN/$HIGH_SCRIPT"
|
||||||
|
FULL_SCRIPT="full"
|
||||||
|
PATH_FULL_SCRIPT="$FOLDER_ORIGIN/$FULL_SCRIPT"
|
||||||
|
|
||||||
|
# Check if the required --folder flag is provided
|
||||||
|
if [ -z "$FOLDER_ORIGIN" ]; then
|
||||||
|
echo "Error: The --folder flag is required."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
start
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user