Rename my-scripts folder to scripts

This commit is contained in:
Matheus Albino
2023-11-06 03:16:17 -03:00
parent 09ea15eed7
commit abd9414b9f
21 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
#!/bin/bash
check_command_availability() {
if ! command -v "$1" &> /dev/null; then
echo "Error: '$1' command not found. Please install $1."
exit 1
fi
}
if [ -z "$1" ]; then
echo "Usage: $0 <image> [-s] [-o <output_file>]"
exit 1
fi
IMAGE="$1"
SORT_FLAG=""
OUTPUT_FILE=""
while [ "$#" -gt 0 ]; do
case "$1" in
-s) SORT_FLAG="-s"; shift ;;
-o) OUTPUT_FILE="$2"; shift 2 ;;
*) shift ;;
esac
done
# Check command availability
check_command_availability skopeo
check_command_availability jq
# Store the result of skopeo command
skopeo_result=$(skopeo inspect docker://docker.io/${IMAGE} | jq -r '.RepoTags[]')
# Determine if sorting is needed
sort_command="cat"
if [ "$SORT_FLAG" = "-s" ]; then
sort_command="sort"
fi
# Pipe the result through the sort command (conditionally)
sorted_result=$(echo "$skopeo_result" | $sort_command)
# Determine if output file is needed
if [ -z "$OUTPUT_FILE" ]; then
echo "$sorted_result"
else
echo "$sorted_result" > "$OUTPUT_FILE"
fi

View File

@@ -0,0 +1,10 @@
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_file>"
exit 1
fi
input_file="$1"
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$input_file"

128
scripts/shell/ffmpeg-helper.sh Executable file
View File

@@ -0,0 +1,128 @@
#!/bin/bash
show_help() {
echo "Usage: $0 [--input|-i input_file] [--crop|-c width:height] [--trim-start start] [--trim-end end] [--crf crf_value] [--fps new_fps] [--scale640] [--merge-audio] [--remove-audio] --output|-o output_file"
echo "Options:"
echo " --input|-i Specify the input video file (required)."
echo " --crop|-c Specify the width:height for video cropping."
echo " --trim-start Specify the start timestamp for video trimming."
echo " --trim-end Specify the end timestamp for video trimming."
echo " --crf Specify the CRF value for video compressing."
echo " --fps Specify the new frames per second for the video."
echo " --scale640 Scale the video to 640x320."
echo " --merge-audio Merge all audio tracks into the main track."
echo " --remove-audio Suppress all audio and remove audio tracks."
echo " --output|-o Specify the output filename (required)."
}
remove_audio() {
input_file="$1"
output_file="$2"
ffmpeg -i "$input_file" -an "$output_file"
}
if ! command -v ffmpeg &> /dev/null; then
echo "Error: 'ffmpeg' command not found. Please install ffmpeg."
exit 1
fi
input_file=""
crop=""
trim_start=""
trim_end=""
crf=""
new_fps=""
scale640=false
merge_audio=false
remove_audio=false
output_file=""
while [ "$#" -gt 0 ]; do
case "$1" in
--help|-h) show_help; exit ;;
--input|-i) input_file="$2"; shift 2 ;;
--crop|-c) crop="$2"; shift 2 ;;
--trim-start) trim_start="$2"; shift 2 ;;
--trim-end) trim_end="$2"; shift 2 ;;
--crf) crf="$2"; shift 2 ;;
--fps) new_fps="$2"; shift 2 ;;
--scale640) scale640=true; shift ;;
--merge-audio) merge_audio=true; shift ;;
--remove-audio) remove_audio=true; shift;;
--output|-o) output_file="$2"; shift 2 ;;
*) shift ;;
esac
done
if [ -z "$input_file" ]; then
echo "Error: Input filename (--input or -i) is required."
exit 1
fi
if [ -z "$output_file" ]; then
echo "Error: Output filename (--output or -o) is required."
exit 1
fi
if [ -z "$crop" ] && [ -z "$trim_start" ] && [ -z "$trim_end" ] && [ -z "$crf" ] && [ -z "$new_fps" ] && [ "$merge_audio" = false ] && [ "$scale640" = false ] && [ "$remove_audio" = false ]; then
echo "Error: At least one optional parameter is required."
exit 1
fi
if [ -n "$trim_start" ] && [ -z "$trim_end" ]; then
echo "Error: If using --trim-start, you must also specify --trim-end."
exit 1
fi
if [ -n "$trim_end" ] && [ -z "$trim_start" ]; then
echo "Error: If using --trim-end, you must also specify --trim-start."
exit 1
fi
if [ -n "$crop" ] && [ "$scale640" = true ]; then
echo "Error: Cannot use both --crop and --scale640 together."
exit 1
fi
if [ "$merge_audio" = true ] && [ "$remove_audio" = true ]; then
echo "Error: Cannot use both --merge-audio and --remove-audio together."
exit 1
fi
ffmpeg_command="ffmpeg -i \"$input_file\""
if [ "$remove_audio" = true ]; then
ffmpeg_command+=" -an"
fi
if [ -n "$crop" ]; then
ffmpeg_command+=" -vf crop=$crop"
fi
if [ -n "$trim_start" ] && [ -n "$trim_end" ]; then
ffmpeg_command+=" -ss $trim_start -to $trim_end"
fi
if [ -n "$crf" ]; then
ffmpeg_command+=" -c:v libx264 -crf $crf"
fi
if [ -n "$new_fps" ]; then
ffmpeg_command+=" -r $new_fps"
fi
if [ "$scale640" = true ]; then
ffmpeg_command+=" -vf scale=640:320"
fi
if [ "$merge_audio" = true ]; then
num_audio_streams=$(ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 "$input_file" | wc -l)
ffmpeg_command+=" -filter_complex amerge=inputs=$num_audio_streams"
fi
ffmpeg_command+=" \"$output_file\""
echo "Running ffmpeg command:"
echo "$ffmpeg_command"
eval "$ffmpeg_command"

View File

@@ -0,0 +1,47 @@
#!/bin/bash
# Initialize variables for output files
success_log="success_log.txt"
failure_log="failure_log.txt"
# Parse command line arguments
while getopts "f:c:" opt; do
case $opt in
f)
queue_file="$OPTARG"
;;
c)
command="$OPTARG"
;;
\?)
echo "Usage: $0 -f <queue_file> -c <command>"
exit 1
;;
esac
done
# Check if both parameters are provided
if [ -z "$queue_file" ] || [ -z "$command" ]; then
echo "Usage: $0 -f <queue_file> -c <command>"
exit 1
fi
# Check if the queue file exists
if [ ! -f "$queue_file" ]; then
echo "Queue file not found: $queue_file"
exit 1
fi
# Process the queue
while IFS= read -r line; do
# Execute the command with the line as an argument
$command "$line"
# Check the exit status of the command
if [ $? -eq 0 ]; then
echo "Command: $command $line - SUCCESS" >> "$success_log"
else
echo "Command: $command $line - FAILURE" >> "$failure_log"
fi
done < "$queue_file"
echo "Script completed. Successful commands logged in $success_log. Failed commands logged in $failure_log."

View File

@@ -0,0 +1 @@
gallery-dl -o conversations=1 --filter "author['name']==locals().get('reply_to')" $1

View File

@@ -0,0 +1,76 @@
#!/bin/bash
# Step 1: Get HTML content of the page
html_content=$(curl -s https://zaiste.net/posts/shell-commands-rust/)
# Step 2: Extract href attribute values of "GitHub" links
github_links=$(echo "$html_content" | grep -oE '<a [^>]+>GitHub<\/a>' | grep -oE 'href="[^"]+"' | sed 's/href="//;s/"$//')
# Step 3: Transform URLs
transformed_urls=()
for link in $github_links; do
if [[ "$link" != *"github"* ]]; then
continue
fi
transformed_url=$(echo "$link" | sed 's/github.com/raw.githubusercontent.com/;s#/$##')
transformed_urls+=("$transformed_url/master/Cargo.toml")
done
echo "Transformed URLs:"
for url in "${transformed_urls[@]}"; do
echo "$url"
done
# Step 4: Test URLs and gather results
existing_urls=()
non_existing_urls=()
for url in "${transformed_urls[@]}"; do
response=$(curl -s --head -w %{http_code} "$url" -o /dev/null)
if [ "$response" -eq 200 ]; then
existing_urls+=("$url")
else
non_existing_urls+=("$url")
fi
done
# Step 5 and 6: Search for "name" property and categorize URLs
successful_search=()
unsuccessful_search=()
for url in "${existing_urls[@]}"; do
html_content=$(curl -s "$url")
if grep -qE "\[package\]" <<< "$html_content"; then
# name_line=$(grep -A 1 "\[package\]" <<< "$html_content" | grep -E '^name = "[^"]+"' | sed 's/name = "//;s/"$//')
name_line=$(awk -F'"' '/^\[package\]/ { in_package = 1 } in_package && /name =/ { print $2; exit }' <<< "$html_content")
echo "name_line: ${name_line}"
if [[ "$name_line" != "[package]" ]]; then
successful_search+=("$url $name_line")
else
unsuccessful_search+=("$url")
fi
fi
done
# Step 7: Print results
echo -e "\n\n\nExisting URLs:"
for url in "${existing_urls[@]}"; do
echo "$url"
done
echo -e "\n\n\nNon-existing URLs:"
for url in "${non_existing_urls[@]}"; do
echo "$url"
done
# echo -e "\n\n\nSuccessful search for 'name' property:"
echo -ne "\n\n\ncargo install"
for result in "${successful_search[@]}"; do
# url=$(echo "$result" | cut -d' ' -f1)
name=$(echo "$result" | cut -d' ' -f2)
echo -n " $name"
done
# echo -e "\n\n\nUnsuccessful search for 'name' property:"
# for url in "${unsuccessful_search[@]}"; do
# echo "$url"
# done

13
scripts/shell/klogs.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
#
# Check if an argument was provided
if [ $# -eq 0 ]; then
echo "Usage: ./script.sh <deployment-name>"
exit 1
fi
# Get the deployment name from the first argument
deployment_name=$1
# Run the kubectl command
kubectl -n$K_DEFAULT_NAMESPACE logs --selector app.kubernetes.io/instance=$deployment_name --follow

9
scripts/shell/rclone-syncs.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
SYNCS_PATH=/mnt/e/Windows/Documents/Sync
rclone sync -P google-drive-zakdragonbites: $SYNCS_PATH/google-drive
rclone sync -P $SYNCS_PATH/google-drive google-drive-zakdragonbites:
# rclone sync -P $SYNCS_PATH/nextcloud-renner nextcloud-renner:
# rclone sync -P nextcloud-renner: $SYNCS_PATH/nextcloud-renner

12
scripts/shell/run-docker-wsl.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
# docker
DOCKER_DISTRO="Arch"
DOCKER_DIR=/mnt/wsl/shared-docker
DOCKER_SOCK="$DOCKER_DIR/docker.sock"
export DOCKER_HOST="unix://$DOCKER_SOCK"
# if [ ! -S "$DOCKER_SOCK" ]; then
# mkdir -pm o=,ug=rwx "$DOCKER_DIR"
# chgrp docker "$DOCKER_DIR"
# /mnt/c/Windows/System32/wsl.exe -d $DOCKER_DISTRO sh -c "nohup sudo -b dockerd < /dev/null > $DOCKER_DIR/dockerd.log 2>&1"
# fi

40
scripts/shell/swatch.sh Executable file
View File

@@ -0,0 +1,40 @@
# https://gist.github.com/ablacklama/550420c597f9599cf804d57dd6aad131
swatch_usage() {
cat <<EOF >&2
NAME
swatch - execute a program periodically with "watch". Supports aliases.
SYNOPSIS
swatch [options] command
OPTIONS
-n, --interval seconds (default: 1)
Specify update interval. The command will not allow quicker than
0.1 second interval.
EOF
}
if [ $# -eq 0 ]; then
swatch_usage
return 1
fi
seconds=1
case "$1" in
-n)
seconds="$2"
args=${*:3}
;;
-h)
swatch_usage
return 1
;;
*)
seconds=1
args=${*:1}
;;
esac
watch --color -n "$seconds" --exec bash -ic "$args || true"

46
scripts/shell/swatchz.sh Executable file
View File

@@ -0,0 +1,46 @@
swatch_usage() {
cat <<EOF >&2
NAME
swatch - execute a program periodically with "watch". Supports aliases.
SYNOPSIS
swatch [options] command
OPTIONS
-n, --interval seconds (default: 1)
Specify update interval. The command will not allow quicker than
0.1 second interval.
EOF
}
if [ $# -eq 0 ]; then
swatch_usage
exit 1
fi
seconds=1
shell="$SHELL"
while [ $# -gt 0 ]; do
case "$1" in
-n)
seconds="$2"
args="${@:3}"
shift 3
;;
-h)
swatch_usage
exit 1
;;
*)
args="${@:1}"
break
;;
esac
done
# Get the base name of the shell executable
shell_basename=$(basename "$shell")
watch --color -n "$seconds" --exec "$shell" -ic "$args || true"