Reorganise scripts

This commit is contained in:
pfych 2024-08-16 22:49:20 +10:00
parent 5ebf7f9b5c
commit 4ae0656da4
18 changed files with 196 additions and 104 deletions

View File

@ -1,60 +0,0 @@
decimate() {
ffmpeg -i "$1" -map 0:v -vf mpdecimate,setpts=N/FRAME_RATE/TB "${1%.*}"-decimated.mp4
}
togif() {
ffmpeg -i "$1" \
-filter_complex "[0:v] fps=12,scale=480:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" \
out.gif
}
drive-by() {
for file in *.png; do
if convert "$file" -channel a -separate -format "%[fx:100*mean]%" info: | grep -qE "(99\.|100)"; then
convert "$file" "${file%.png}.jpg"
convert "$file" "${file%.png}.webp"
echo "Created jpg & webp"
else
convert "$file" -define png:include-chunk=none -quality 95 -depth 8 "$file"
convert "$file" "${file%.png}.webp"
echo "Compressed png & created webp"
fi
done
}
site-prep() {
mkdir -p lg/;
mkdir -p md/;
mkdir -p sm/;
convert "$1" \
-strip \
-quality 85% \
-interlace Plane \
-resize 1800 "lg/${1%.*}.jpg"
convert "$1" \
-strip \
-interlace Plane \
-gaussian-blur 0.05 \
-quality 85% \
-resize 720 "md/${1%.*}.jpg"
convert "$1" \
-strip \
-interlace Plane \
-scale 10% \
-blur 0x2.5 \
-resize 1000% \
-resize 180 "sm/${1%.*}.jpg"
echo "$1 is prepped"
}
flac-ipod() {
mkdir ./converted;
for file in **/*.flac; do
ffmpeg -i "$file" -c:a aac -b:a 256k -aac_pns 0 -movflags +faststart -vn "${file%.flac}.m4a"
mv "$file" "./converted";
done
}

View File

@ -0,0 +1,54 @@
#!/bin/bash
source /Users/noahheague/.config/scripts/util/secret.sh
export B2_ACCOUNT_ID=$(getSecret "/server/mac-mini-1/b2-account-id")
export B2_ACCOUNT_KEY=$(getSecret "/server/mac-mini-1/b2-account-key")
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "backup" \
-m "Restic Backup Started..."
# Reclone download external files
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "backup" \
-m "Pulling external files..."
/usr/local/bin/rclone copy Dropbox:Delta\ Emulator /Volumes/Homelab/30\ Archival/34\ Assorted/Delta\ Emulator
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "backup" \
-m "Pushing to remote..."
/usr/local/bin/restic \
--pack-size 128 \
-r b2:pfych-home-server-backup:/ \
backup /Volumes/Homelab/ \
--verbose=2 \
--json \
--password-command "getSecret '/server/mac-mini-1/restic-key'" \
--exclude "40 Programming/Docker/nginx-proxy-manager/data/nginx" \
--exclude "50 BitTorrent" \
--exclude "30 Archival/35 BMS" \
--exclude "30 Archival/32 Youtube/kkm" \
--exclude "Mastodon/public" \
--exclude "node_modules" \
--exclude ".fseventsd" \
--exclude ".Spotlight-V100" \
--exclude ".Trash-1000" \
--exclude ".DS_Store" \
--exclude ".DocumentRevisions-V100" \
--exclude ".TemporaryItems" \
--exclude ".Trashes" | jq 'select(.message_type | test("summary"))' > /tmp/restic-backup.json
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "backup" \
-m "Restic Backup Completed!"
TIME_TAKEN=$(gdate -d@"$(cat /tmp/restic-backup.json | jq '.total_duration')" -u +%H:%M:%S)
FILES_CHANGED=$(cat /tmp/restic-backup.json | jq '.files_changed')
DIRECTORIES_CHANGED=$(cat /tmp/restic-backup.json | jq '.dirs_changed')
DATA_ADDED=$(units -t -o "%.0f" "$(cat /tmp/restic-backup.json | jq '.data_added') bytes" megabytes)
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "backup" \
-m "Time Taken: $TIME_TAKEN\nFiles Changed: $FILES_CHANGED\nDirectories Changed: $DIRECTORIES_CHANGED\nData Added: ${DATA_ADDED}MB"

View File

@ -14,7 +14,7 @@ declare -a PRODUCT_IDS=(
'$9.00|twisted-licks-rich-chocolate-zero-added-sugar-sticks-4-pack-320ml-3778083|Licks Ice Cream'
)
/Users/noahheague/.config/scripts/webhook.sh \
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "coles" \
-m "Checking Prices..."
@ -31,12 +31,12 @@ do
if [[ "$OUTPUT" != "$EXPECTED_PRICE" ]]
then
/Users/noahheague/.config/scripts/webhook.sh \
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "coles" \
-m "$PRETTY_NAME is on sale! **$OUTPUT** (was $EXPECTED_PRICE)"
fi
done
/Users/noahheague/.config/scripts/webhook.sh \
/Users/noahheague/.config/scripts/util/webhook.sh \
-c "coles" \
-m "All prices checked!"

View File

@ -0,0 +1,65 @@
export AWS_PROFILE=default
DOMAIN="pfy.ch"
declare -a SUB_DOMAINS=("home" "git" "zip")
# Scripts
CURRENT_IP=`dig @resolver4.opendns.com myip.opendns.com +short`
HOSTED_ZONE_ID=$(
/usr/local/bin/aws route53 list-hosted-zones \
| /usr/local/bin/jq \
--arg domain "$DOMAIN." \
'.HostedZones
| map(select(.Name == $domain))
| .[] .Id' \
| sed 's/"//g'
)
for SUB_DOMAIN in "${SUB_DOMAINS[@]}"
do
RECORD_VALUE=$(
/usr/local/bin/aws route53 list-resource-record-sets \
--hosted-zone-id $HOSTED_ZONE_ID \
| /usr/local/bin/jq \
--arg fullDomain "$SUB_DOMAIN.$DOMAIN." \
'.ResourceRecordSets
| map(select(.Name == $fullDomain))
| .[] .ResourceRecords
| .[] .Value' \
| sed 's/"//g'
)
if test "$CURRENT_IP" != "$RECORD_VALUE"; then
CHANGE_REQUEST="
{
\"HostedZoneId\": \"$HOSTED_ZONE_ID\",
\"ChangeBatch\": {
\"Comment\": \"Dynamic DNS change\",
\"Changes\": [
{
\"Action\": \"UPSERT\",
\"ResourceRecordSet\": {
\"Name\": \"$SUB_DOMAIN.$DOMAIN\",
\"Type\": \"A\",
\"TTL\": 3600,
\"ResourceRecords\": [
{
\"Value\": \"$CURRENT_IP\"
}
]
}
}
]
}
}
"
echo "$CURRENT_IP does not match $RECORD_VALUE on $SUB_DOMAIN.$DOMAIN. Changing...";
/usr/local/bin/aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --cli-input-json "$CHANGE_REQUEST"
/Users/noahheague/.config/scripts/webhook.sh \
-c "dns" \
-m "$CURRENT_IP does not match $RECORD_VALUE on $SUB_DOMAIN.$DOMAIN"
else
echo "$CURRENT_IP matches $RECORD_VALUE on $SUBDOMAIN.$DOMAIN."
fi
done

View File

@ -1,10 +0,0 @@
#!/bin/bash
function rgfzf() {
FZF_SELECTION=$(rg -g '!*.{svg,js}' . | fzf)
FILE_NAME=$(echo "$FZF_SELECTION" | cut -d':' -f1)
CONTENT=$(echo "$FZF_SELECTION" | cut -d':' -f2-)
ESCAPED=$(echo "$CONTENT" | sed -e 's,/,\\/,g')
vim "$FILE_NAME" -c "/$ESCAPED"
}

17
.config/scripts/scripts.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# Easily set aws profiles using credentialys
source ~/.config/scripts/tool/aws-profile.sh
# Prep images for upload to pfy.ch cdn
source ~/.config/scripts/tool/site-prep.sh
# Quickly get domain details from dig
source ~/.config/scripts/tool/ezdig.sh
# Git utils and extensions
source ~/.config/scripts/tool/git.sh
# Aliases for common kill actions
source ~/.config/scripts/tool/kill.sh
# Generate thumbnails for videos
source ~/.config/scripts/tool/thumb.sh
# Text colour utility variables
source ~/.config/scripts/util/colours.sh

View File

@ -1,5 +1,3 @@
#!/bin/bash
function awsconfig {
AWS_PROFILE=$(cat ~/.aws/credentials \
| grep "\[" \

View File

@ -1,4 +1,3 @@
#Encrypt Files
function encrypt {
FILE_EXTENSION=$(echo $1 | cut -f 2,3 -d '.')
FILE_NAME=$(echo "$1" | cut -f 1 -d '.')
@ -7,7 +6,6 @@ function encrypt {
echo "$GREEN_TEXT\nSend the follow command via Slack alongside the file:$DEFAULT_TEXT\n\`openssl enc -d -aes-256-cbc -in ~/Downloads/$FILE_NAME.enc >> $FILE_NAME.$FILE_EXTENSION"
}
# Create a Salted UUID
function salted-uuid {
# Convert input into base64 string
INPUT_AS_BASE64=$(echo -n "$1" | openssl dgst -binary -sha256 | openssl base64)

View File

@ -1,5 +1,3 @@
#!/bin/zsh
function is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}

View File

@ -1,25 +1,3 @@
#!/bin/bash
function scratch () {
requestedDate=$(date +"%y-%m-%d")
vim ~/Documents/Scratchpad/$requestedDate.md
}
function wscratch () {
requestedDate=$(date +"%y-%m-%d")
if [ ! -e ~/Documents/Scratchpad-write/$requestedDate-write.md ]; then
touch ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "---" >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "title: " >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "summary: " >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "image: " >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "alt: " >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "attribution: " >> ~/Documents/Scratchpad-write/$requestedDate-write.md
echo "---" >> ~/Documents/Scratchpad-write/$requestedDate-write.md
fi
vim ~/Documents/Scratchpad-write/$requestedDate-write.md
}
function nscratch () {
requestedDate=$(date +"%y-%m-%d")
if [ ! -e ~/Documents/Scratchpad-now/$requestedDate-write.md ]; then

View File

@ -0,0 +1,28 @@
site-prep() {
mkdir -p lg/;
mkdir -p md/;
mkdir -p sm/;
convert "$1" \
-strip \
-quality 85% \
-interlace Plane \
-resize 1800 "lg/${1%.*}.jpg"
convert "$1" \
-strip \
-interlace Plane \
-gaussian-blur 0.05 \
-quality 85% \
-resize 720 "md/${1%.*}.jpg"
convert "$1" \
-strip \
-interlace Plane \
-scale 10% \
-blur 0x2.5 \
-resize 1000% \
-resize 180 "sm/${1%.*}.jpg"
echo "$1 is prepped"
}

View File

@ -1,7 +1,4 @@
#!/bin/bash
function thumb() {
echo "USING GPU!!!"
UUID=$(uuidgen)
GRID_X=2
GRID_Y=4

21
.config/scripts/util/colours.sh Executable file
View File

@ -0,0 +1,21 @@
export TERM=xterm-256color
export BLACK_TEXT="\033[30m"
export RED_TEXT="\033[31m"
export GREEN_TEXT="\033[32m"
export ORANGE_TEXT="\033[33m"
export BLUE_TEXT="\033[34m"
export MAGENTA_TEXT="\033[35m"
export CYAN_TEXT="\033[36m"
export LIGHT_GREY_TEXT="\033[37m"
export DEFAULT_TEXT="\033[39m"
export BLACK_BACKGROUND="\033[40m"
export RED_BACKGROUND="\033[41m"
export GREEN_BACKGROUND="\033[42m"
export ORANGE_BACKGROUND="\033[43m"
export BLUE_BACKGROUND="\033[44m"
export MAGENTA_BACKGROUND="\033[45m"
export CYAN_BACKGROUND="\033[46m"
export LIGHT_GREY_BACKGROUND="\033[47m"
export DEFAULT_BACKGROUND="\033[49m"

View File

@ -0,0 +1,8 @@
getSecret() {
aws ssm get-parameter \
--region us-east-1 \
--name "$1" \
--with-decryption \
--output json \
| jq -r ".Parameter.Value"
}