Move .scripts -> .local/bin

This commit is contained in:
Riyyi
2021-02-25 20:16:07 +01:00
parent 3ac7d9f601
commit ba10984084
40 changed files with 93 additions and 94 deletions
+95
View File
@@ -0,0 +1,95 @@
#!/bin/sh
BACKUP_COUNT_MAX=5
# Backup individual files
FILES="
/etc/netctl/eth0-dhcp
"
# Backup all files from folder
FOLDER_FILES="
/etc/netctl
"
# Backup complete folder (recursively)
FOLDERS="
/etc/netctl
"
# Database credentials
USER="username"
PASSWORD="password"
HOST="127.0.0.1"
# Database names
DATABASES="
example
example2
"
# ------------------------------------ #
### Remove / create backup directories ###
if [ "$(dirname "$0")" != "." ]; then
echo "Please run this script from the directory it resides."
exit 1
fi
# All directories
BACKUP_FILES="$(find . -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -r)"
# Current amount of backups
BACKUP_COUNT=$(echo "$BACKUP_FILES" | wc -l)
# Remove the oldest backup folders
if [ "$BACKUP_COUNT" -ge $BACKUP_COUNT_MAX ]; then
BACKUPS_OLDEST="$(echo "$BACKUP_FILES" | sed -nE "
1,${BACKUP_COUNT_MAX}d;
s/^([0-9]{2}|-|_|:){12}$/\0/p
")"
printf "%s\n%s\n" "Removing directories:" "$BACKUPS_OLDEST"
rm -rf $BACKUPS_OLDEST
fi
# Execution location
DIR="$(pwd)"
# Create new backup folder
BACKUP_NAME="$(date +%Y-%m-%d_%H:%M:%S)"
mkdir "$DIR/$BACKUP_NAME"
### Start backup procedure ###
# Individual files
for FILE in $FILES; do
mkdir -p "$DIR/$BACKUP_NAME/$(dirname "$FILE")"
cp -a "$FILE" "$DIR/$BACKUP_NAME/$FILE"
done
# All files inside folder
for FOLDER_FILE in $FOLDER_FILES; do
mkdir -p "$DIR/$BACKUP_NAME/$FOLDER_FILE"
# Usind find -> read ensures filename space support
find "$FOLDER_FILE" -maxdepth 1 -type f | while read -r FILE; do
cp "$FILE" "$DIR/$BACKUP_NAME/$FILE"
done
done
# Complete folder
for FOLDER in $FOLDERS; do
mkdir -p "$DIR/$BACKUP_NAME/$FOLDER"
cp -r "$FOLDER" "$DIR/$BACKUP_NAME/$(dirname "$FOLDER")"
done
# Set default file permissions
umask 177
# MYSQL Dump
for DATABASE in $DATABASES; do
# mysqldump --user=$USER --protocol=socket -S /var/run/mysqld/mysqld.sock "$DATABASE" \
mysqldump --user=$USER --password=$PASSWORD --host=$HOST "$DATABASE" \
> "$DIR/$BACKUP_NAME/$DATABASE-$BACKUP_NAME.sql"
done
+62
View File
@@ -0,0 +1,62 @@
#!/bin/sh
# Dependencies:
# castnow-git
# mkvtoolnix-cli
# jq
FILE_NAME="$1"
TRACKS="$(mkvmerge -J "$FILE_NAME" | jq -c '
.tracks[] |
select(.type == "subtitles") |
{
id:.id,
codec_id:.properties.codec_id,
language:.properties.language,
track_name:.properties.track_name
}')"
if [ -n "$2" ]; then
SELECTION=$2
else
echo "$TRACKS"
echo -n "Choose a subtitle ID: "
read -r SELECTION
fi
if [ -z "$(echo $SELECTION | sed -nr 's/^([0-9]+)$/\1/p')" ]; then
echo "Please select a number"
exit
fi
for TRACK in $TRACKS; do
TRACK_ID=$(echo $TRACK | sed -nr 's/.*"id":([0-9]+),.*/\1/p')
if [ $TRACK_ID != $SELECTION ]; then
continue
fi
CODEC_ID="$(echo $TRACK | \
sed -nr 's/.*"codec_id":"(S_[A-Z]+\/?[A-Z]*[0-9]*)",.*/\1/p')"
if [ "$CODEC_ID" = "S_TEXT/UTF8" ]; then
EXT="srt"
elif [ "$CODEC_ID" = "S_TEXT/ASS" ]; then
EXT="ssa"
elif [ "$CODEC_ID" = "S_TEXT/USF" ]; then
EXT="usf"
elif [ "$CODEC_ID" = "S_VOBSUB" ]; then
EXT="sub"
elif [ "$CODEC_ID" = "S_HDMV/PGS" ]; then
EXT="sup"
fi
echo "Extracting subtitle.."
mkvextract tracks "$FILE_NAME" $TRACK_ID:/tmp/sub."$EXT" 2>&1 >/dev/null
echo "Converting subtitle.."
ffmpeg -y -i /tmp/sub."$EXT" /tmp/sub.vtt 2>/dev/null
echo "Playing file.."
castnow "$FILE_NAME" --subtitles /tmp/sub.vtt --subtitle-scale 1.2 --subtitle-color FFFFFFFF
done
+58
View File
@@ -0,0 +1,58 @@
#!/bin/sh
MAIN_DISPLAY="eDP-1"
MAIN_MODE="--mode 3000x2000_48.00 --primary"
popup() {
echo "$1" | rofi -dmenu -i -p "$2" \
-color-window "#524040, #dc7a43, #fff" \
-color-normal "#524040, #fff, #524040, #fff, #707880" \
-no-fixed-num-lines
}
multiDisplay() {
case "$(echo "$CONNECTED" | wc -l)" in
1) setSingle ;;
2) setDual ;;
*) setMulti ;;
esac
}
setSingle() {
[ "$CHOOSE" = "$MAIN_DISPLAY" ] && MODE="$MAIN_MODE" || MODE="--auto"
# Disconnect all other displays
eval xrandr --output "$CHOOSE" "$MODE" \
"$(echo "$CONNECTED" | grep -vx "$CHOOSE" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ')"
}
setDual() {
PRIMARY=$(popup "$CONNECTED" "Select primary display")
[ "$PRIMARY" = "$MAIN_DISPLAY" ] && MODE="$MAIN_MODE" || MODE="--auto"
SECONDARY=$(echo "$CONNECTED" | grep -vx "$PRIMARY")
SIDE=$(popup "$(printf "right\nleft")" "On which side of $PRIMARY should $SECONDARY be?")
eval xrandr --output "$PRIMARY" "$MODE" --output "$SECONDARY" --"$SIDE"-of "$PRIMARY" --auto
}
setMulti() {
# @Todo
echo "Todo"
}
# Get all connected displays
CONNECTED=$(xrandr -q | grep " connected" | awk '{print $1}')
# Add Multi-monitor and Manual selection to the selectable options
SELECTION="$(printf "%s\nMulti-monitor\nManual selection" "$CONNECTED")"
# Get user selection
CHOOSE="$(popup "$SELECTION" "Select display arangement")" &&
case "$CHOOSE" in
"Manual selection") arandr 2> /dev/null ; exit ;;
"Multi-monitor") multiDisplay ;;
*) setSingle ;;
esac
# Reload background
$HOME/.local/bin/wm/wallpaper.sh