commit d533e24483de66da6b5efed7aa67a04d41bfcfb2
parent 86132a1819e64a16086bbec1e31bf1e800241d80
Author: Matthew Carlson <matt@mcarlson.xyz>
Date: Tue, 7 Sep 2021 02:47:49 -0400
added some new scripts; slight modifications
Diffstat:
9 files changed, 135 insertions(+), 6 deletions(-)
diff --git a/.config/git/config b/.config/git/config
@@ -4,3 +4,6 @@
signingkey = 9CC4E75365C16465FFE752C94DDBF97211D4EA31
[commit]
gpgsign = true
+[filter "gitignore"]
+ clean = "sed '/#gitignore$/'d"
+ smudge = cat
diff --git a/.config/mpv/mpv.conf b/.config/mpv/mpv.conf
@@ -58,5 +58,5 @@ hr-seek-framedrop = 'no'
interpolation = 'yes'
profile = 'gpu-hq'
scale-antiring = 0.0
-video-sync = 'auto'
+video-sync = 'audio'
vo = 'gpu'
diff --git a/.local/bin/backup.sh b/.local/bin/backup.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# backup
+
+BACKUP_DIR='/mnt/backup'
+LOG='/var/log/backup.log'
+
+stamp="$(date +%Y-%m-%d\ %I:%M\ %p)"
+
+if df | grep -q "${BACKUP_DIR}"; then
+ [ ! -e "${LOG}" ] && touch "${LOG}"
+ # shellcheck disable=SC3009
+ rsync -aAXHv --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / "${BACKUP_DIR}"
+ printf '%s\n' "${stamp} - System backup complete." >> "${LOG}"
+else printf '%s\n' "${stamp} - ${BACKUP_DIR} is not a mount point. Not backing up system." >> "${LOG}"
+fi
diff --git a/.local/bin/bar/time.sh b/.local/bin/bar/time.sh
@@ -11,7 +11,7 @@ main() {
[ ${#} -eq 0 ] && bar
# bar usage
- case ${BLOCK_BUTTON} in esac
+ case ${BLOCK_BUTTON} in 1) env HERBE_ID=/0 herbe "$(date +%I:%M:%S\ %p)" ;; esac
}
main "${@}"
diff --git a/.local/bin/bar/vol.sh b/.local/bin/bar/vol.sh
@@ -68,10 +68,10 @@ main() {
while getopts 'ot' opt; do
case "${opt}" in
# open mixer
- o) open && return ;;
+ o) open; return ;;
# toggle if t flag used
- t) toggle && return ;;
- *) return ;;
+ t) toggle; return ;;
+ *) return ;;
esac
done
diff --git a/.local/bin/pass.sh b/.local/bin/pass.sh
@@ -7,7 +7,8 @@ NEWLINE='
'
get_credential() {
- credential="$(printf '%s\n' "${credentials}" | grep "\<${1}\>" | awk -F ':' '{ print $2 }')"
+ # awk statement takes everything after the first colon
+ credential="$(printf '%s\n' "${credentials}" | grep "\<${1}\>" | awk -F ':' '{ st = index($0, ":"); print substr($0, st + 1) }')"
credential="${credential%\'}"
credential="${credential#\'}"
}
diff --git a/.local/bin/touchpad.sh b/.local/bin/touchpad.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# touchpad
+
+main() {
+ # get touchpad using xinput
+ # xinput will show list of input devices with id (we want id)
+ # we can then use xinput list-props <ID> to see if device enabled
+ tp="$(xinput | grep -i '^.*touchpad.*id=[0-9][0-9]*.*$' | awk '{ for (i = 1; i <= NF; i++) { if ($i ~ /^.*id=[0-9][0-9]*.*$/) { print $i } } }' | tr -d -c 0-9)"
+ flag="$(xinput list-props "${tp}" | grep -i '^.*device enabled.*$' | awk '{ for (i = 1; i <= NF; i++) { if ($i ~ /^\s*[0-1]\s*$/) { print $i } } }')"
+
+ # toggle touchpad also with xinput
+ {
+ if [ "${flag}" -eq 1 ]; then xinput --disable "${tp}" && herbe 'Touchpad disabled'
+ else xinput --enable "${tp}" && herbe 'Touchpad enabled'
+ fi
+ } &
+}
+
+main "${@}"
diff --git a/.local/bin/trim.sh b/.local/bin/trim.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# trim
+
+# get dir in which the script was executed
+DIR="$(dirname "${0}")"
+
+# amount of time to trim files by
+TRIM_BY=${2}
+
+main() {
+ # loop over all files of certain type
+ for f in "${DIR}"/*."${1}"; do
+ # get base and ext
+ base="${f%.*}"
+ ext="${f##*.}"
+
+ # get file duration in minutes and seconds
+ time="$(ffmpeg -i "${f}" 2>&1 | grep 'Duration:' | awk -F ',' '{print $1}' | cut -f 1 -d '.' | awk -F ':' '{print $3 " " $4}')"
+ min=$(printf '%s\n' "${time}" | awk '{print $1}')
+ sec=$(printf '%s\n' "${time}" | awk '{print $2}')
+
+ # convert minutes to seconds
+ min_to_sec=$((min * 60))
+
+ # length in pure seconds
+ length=$((min_to_sec + sec))
+
+ # length after trim
+ final_length=$((length - TRIM_BY))
+
+ printf '%s\n' "Trimming ${base}.${ext} by ${TRIM_BY} seconds..."
+
+ # agree to trim file
+ yes | ffmpeg -i "${f}" -ss 00 -t "${final_length}" -c copy "${base}-new.${ext}" 2>/dev/null
+
+ # create backup just in case
+ mv "${f}" "${f}.bak" && mv "${base}-new.${ext}" "${base}.${ext}"
+ done
+}
+
+main "${@}"
diff --git a/.local/bin/vultr.sh b/.local/bin/vultr.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# vultr
+
+# disable double quote warning
+# shellcheck disable=2086
+
+get_ids() { awk -F ',' '{ for (i = 1; i <= NF; i++) if ($i ~ /"id"/) print $i }' | awk -F ':' '{ for (i = 1; i <= NF; i++) if ($i ~ /-/) print $i }' | tr -d \" ; }
+
+# DO NOT SHARE THIS
+VULTR_API_KEY='RETRACTED'
+
+
+INSTANCE='mcarlson.xyz'
+
+INSTANCE_ID="$(curl 'https://api.vultr.com/v2/instances' \
+ -X GET \
+ -H "Authorization: Bearer ${VULTR_API_KEY}" \
+ | get_ids)"
+
+snapshot_ids="$(curl 'https://api.vultr.com/v2/snapshots' \
+ -X GET \
+ -H "Authorization: Bearer ${VULTR_API_KEY}" \
+ | get_ids)"
+
+# Get oldest snapshot ID -- will be first in list
+set -- ${snapshot_ids}
+oldest_snapshot_id="${1}"
+
+# Vultr only allows eleven(?) snapshots at this moment
+SNAPSHOT_LIMIT=11
+snapshot_count=$(printf '%s\n' "${snapshot_ids}" | wc -w)
+
+# Delete oldest snapshot if limit if reached
+if [ "${snapshot_count}" -eq "${SNAPSHOT_LIMIT}" ]; then
+ curl "https://api.vultr.com/v2/snapshots/${oldest_snapshot_id}" -X DELETE -H "Authorization: Bearer ${VULTR_API_KEY}" || exit 1;
+fi
+
+# Create new snapshot for instance
+curl 'https://api.vultr.com/v2/snapshots' \
+ -X POST \
+ -H "Authorization: Bearer ${VULTR_API_KEY}" \
+ -H 'Content-Type: application/json' \
+ --data '{
+ "instance_id":"'${INSTANCE_ID}'",
+ "description":"Snapshot of '${INSTANCE}'"
+ }'