diff options
| author | ivan-boikov <ik.boikov@protonmail.com> | 2021-01-23 11:29:57 +0100 |
|---|---|---|
| committer | ivan-boikov <ik.boikov@protonmail.com> | 2021-01-23 11:29:57 +0100 |
| commit | 25c63760eb0c995543c9151b446092d17325c562 (patch) | |
| tree | 1cbb7b5155a3f3b0f9ad204d40fee13925a22dbb /scripts | |
| parent | e001653460c1343512d940260046704d2387c102 (diff) | |
Initial commit
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/.local/bin/borg-backup | 66 | ||||
| -rwxr-xr-x | scripts/.local/bin/chsink | 3 | ||||
| -rwxr-xr-x | scripts/.local/bin/dmount | 69 | ||||
| -rwxr-xr-x | scripts/.local/bin/dumount | 45 | ||||
| -rwxr-xr-x | scripts/.local/bin/psfrag | 65 | ||||
| -rwxr-xr-x | scripts/.local/bin/setsink | 35 | ||||
| -rwxr-xr-x | scripts/.local/bin/setttl | 1 | ||||
| -rwxr-xr-x | scripts/.local/bin/tabletosu | 4 | ||||
| -rwxr-xr-x | scripts/.local/bin/tabletpad | 10 | ||||
| -rwxr-xr-x | scripts/.local/bin/tabletreset | 2 | ||||
| -rwxr-xr-x | scripts/.local/bin/tabletscale | 41 | ||||
| -rwxr-xr-x | scripts/.local/bin/to60fps | 46 |
12 files changed, 387 insertions, 0 deletions
diff --git a/scripts/.local/bin/borg-backup b/scripts/.local/bin/borg-backup new file mode 100755 index 0000000..751b78d --- /dev/null +++ b/scripts/.local/bin/borg-backup @@ -0,0 +1,66 @@ +#!/bin/sh +# Setting this, so the repo does not need to be given on the commandline: +export BORG_REPO=ssh://pi@192.168.3.1/media/nas/borgbackup +# See the section "Passphrase notes" for more infos. +#export BORG_PASSPHRASE='XYZl0ngandsecurepa_55_phrasea&&123' +export BORG_PASSCOMMAND="cat $HOME/.borg-backup-passphrase" +# some helpers and error handling: +info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } +trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM +info "Starting backup" + +# Backup the most important directories into an archive named after +# the machine this script is currently running on: + +borg create \ + --progress \ + --filter AME \ + --list \ + --stats \ + --show-rc \ + --compression zlib,9 \ + --exclude-caches \ + --exclude='*build*' \ + --exclude='*svn*' \ + --exclude='*temp*' \ + --exclude='*tmp*' \ + --exclude='*git*' \ + --exclude='*log*' \ + --exclude='*old*' \ + --exclude='*bak*' \ + \ + ::'{hostname}-{now}' \ + TODO-ADD-SOME-PATHS + +backup_exit=$? + +info "Pruning repository" + +# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly +# archives of THIS machine. The '{hostname}-' prefix is very important to +# limit prune's operation to this machine's archives and not apply to +# other machines' archives also: + +borg prune \ + --list \ + --prefix '{hostname}-' \ + --show-rc \ + --keep-daily 7 \ + --keep-weekly 4 \ + --keep-monthly 6 \ + +prune_exit=$? + +# use highest exit code as global exit code + +global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) + +if [ ${global_exit} -eq 0 ]; then + info "Backup and Prune finished successfully" +elif [ ${global_exit} -eq 1 ]; then + info "Backup and/or Prune finished with warnings" +else + info "Backup and/or Prune finished with errors" +fi + +exit ${global_exit} diff --git a/scripts/.local/bin/chsink b/scripts/.local/bin/chsink new file mode 100755 index 0000000..36b5641 --- /dev/null +++ b/scripts/.local/bin/chsink @@ -0,0 +1,3 @@ +#!/bin/sh +pactl list sinks short | awk '{print $2}' | dmenu -l 100 | setsink + diff --git a/scripts/.local/bin/dmount b/scripts/.local/bin/dmount new file mode 100755 index 0000000..8ce369d --- /dev/null +++ b/scripts/.local/bin/dmount @@ -0,0 +1,69 @@ +#!/bin/sh + +# Gives a dmenu prompt to mount unmounted drives and Android phones. If +# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll +# be prompted to give a mountpoint from already existsing directories. If you +# input a novel directory, it will prompt you to create that directory. + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -l 30 -i -p "Type in mount point.")" || exit 1 + [ "$mp" = "" ] && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + devhint=$(lsblk -rpo "name,model" | grep dev | awk '$2!=""{printf "%s (%s)\n",$1,$2}') + chosen="$(echo "$usbdrives\n\nDevices (do not select these):\n$devhint" | dmenu -l 30 -i -p "Mount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt -maxdepth 2 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "💻 USB mounting" "$chosen mounted to $mp." + } + +mountandroid() { \ + chosen="$(echo "$anddrives" | dmenu -l 30 -i -p "Which Android device?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1 $2}' | cut -d, -f1-2)" + echo $chosen + getmount "/mnt -maxdepth 2 -type d" + jmtpfs -device="$chosen" "$mp" + echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + jmtpfs -device="$chosen" "$mp" + notify-send "🤖 Android Mounting" "Android device mounted to $mp." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 + case $choice in + USB) mountusb ;; + Android) mountandroid ;; + esac + } + +anddrives=$(jmtpfs -l 2>/dev/null) +usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" + +if [ -z "$usbdrives" ]; then + [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit + echo "Android device(s) detected." + mountandroid +else + if [ -z "$anddrives" ]; then + echo "USB drive(s) detected." + mountusb + else + echo "Mountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/scripts/.local/bin/dumount b/scripts/.local/bin/dumount new file mode 100755 index 0000000..ff28fe0 --- /dev/null +++ b/scripts/.local/bin/dumount @@ -0,0 +1,45 @@ + +#!/bin/sh + +# A dmenu prompt to unmount drives. +# Provides you with mounted partitions, select one to unmount. +# Drives mounted at /, /boot and /home will not be options to unmount. + +unmountusb() { + [ -z "$drives" ] && exit + chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + [ -z "$chosen" ] && exit + sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." + } + +unmountandroid() { \ + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 + [ -z "$chosen" ] && exit + sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 + case "$choice" in + USB) unmountusb ;; + Android) unmountandroid ;; + esac + } + +drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') + +if ! grep simple-mtpfs /etc/mtab; then + [ -z "$drives" ] && echo "No drives to unmount." && exit + echo "Unmountable USB drive detected." + unmountusb +else + if [ -z "$drives" ] + then + echo "Unmountable Android device detected." + unmountandroid + else + echo "Unmountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/scripts/.local/bin/psfrag b/scripts/.local/bin/psfrag new file mode 100755 index 0000000..67adebd --- /dev/null +++ b/scripts/.local/bin/psfrag @@ -0,0 +1,65 @@ +#!/bin/bash + +#default args for my card, most likely not enough for some cards +#user is expected to input values anyway +FRAGMENTS=${1:-1} +FRAGMENT_SIZE=${2:-1000} + +echo "Fragments x fragment size:" $FRAGMENTS "x" $FRAGMENT_SIZE + +ACTIVE_CARD_NAME=$(pactl list sinks short | grep RUNNING | cut -f 2 | sed "s/\.[^.]*$//g" | sed "s/^[^.]*\.//g") +MODULE=$(pactl list modules short | grep "$ACTIVE_CARD_NAME") + +ID=$(echo "$MODULE" | cut -f 1) +ARGS=$(echo "$MODULE" | cut -f3-) + +if [ -z $ACTIVE_CARD_NAME ]; then + echo "Failed to get active sink. Play some music?" + exit 1 +fi + +echo "Active sink name:" $ACTIVE_CARD_NAME +echo "Module ID:" $ID + + +echo "tsched" +if [[ $ARGS == *"tsched"* ]]; then + echo " found, replacing to 0" + ARGS=$(sed "s/tsched=\S*/tsched=0/g" <<< "$ARGS") +else + echo " not found, adding 0" + ARGS="$ARGS tsched=0" +fi + + +echo "fixed_latency_range" +if [[ $ARGS == *"fixed_latency_range"* ]]; then + echo " found, replacing with yes" + ARGS=$(sed "s/fixed_latency_range=\S*/fixed_latency_range=yes/g" <<< "$ARGS") +else + echo " not found, adding yes" + ARGS="$ARGS fixed_latency_range=yes" +fi + + +echo "fragments" +if [[ $ARGS == *"fragments"* ]]; then + echo " found, replacing with" $FRAGMENTS + ARGS=$(sed "s/fragments=\S*/fragments=$FRAGMENTS/g" <<< "$ARGS") +else + echo " not found, adding" $FRAGMENTS + ARGS="$ARGS fragments=1" +fi + + +echo "fragment_size" +if [[ $ARGS == *"fragment_size"* ]]; then + echo " found, replacing with" $FRAGMENT_SIZE + ARGS=$(sed "s/fragment_size=\S*/fragment_size=$FRAGMENT_SIZE/g" <<< "$ARGS") +else + echo " not found, adding" $FRAGMENT_SIZE + ARGS="$ARGS fragment_size=$FRAGMENT_SIZE" +fi + +pactl unload-module "$ID" +pactl load-module module-alsa-card "$ARGS" diff --git a/scripts/.local/bin/setsink b/scripts/.local/bin/setsink new file mode 100755 index 0000000..793cfbf --- /dev/null +++ b/scripts/.local/bin/setsink @@ -0,0 +1,35 @@ +#!/bin/zsh + +export DISPLAY=:0.0 + +devname=$(cat -) +if [[ -z "$devname" ]]; then + echo "No device passed" + return +fi + +device=$(pactl list sinks short | grep $devname) +devid=$(echo $device | awk '{print $1}') +curdevid=$(pactl list sinks short | grep RUNNING | awk '{print $1}') + +echo "Swapping to device $device" +echo "Device ID $devid" +echo "Device name $devname" +echo "Current device ID $curdevid" +notify-send "Swapping to $devname" + +pacmd set-default-sink $devid +if [[ -n "$curdevid" ]]; then + pacmd suspend-sink $curdevid 1 +fi +pacmd suspend-sink $devid 0 + +#move all audio streams to the new sink +pactl list short sink-inputs | while read stream; do + streamId=$(echo $stream | awk '{print $1}') + echo 'Moving stream' $stream 'with id' $streamId + pacmd move-sink-input "$streamId" "$devid" +done + + + diff --git a/scripts/.local/bin/setttl b/scripts/.local/bin/setttl new file mode 100755 index 0000000..9951aa2 --- /dev/null +++ b/scripts/.local/bin/setttl @@ -0,0 +1 @@ +sudo sysctl net.ipv4.ip_default_ttl=$1 diff --git a/scripts/.local/bin/tabletosu b/scripts/.local/bin/tabletosu new file mode 100755 index 0000000..ef9e319 --- /dev/null +++ b/scripts/.local/bin/tabletosu @@ -0,0 +1,4 @@ +#!/bin/bash +notify-send 'Tablet: osu!' +#tabletscale 1280 718 4 87 54 0 10 +tabletscale 1366 768 4 100 50 0 0 diff --git a/scripts/.local/bin/tabletpad b/scripts/.local/bin/tabletpad new file mode 100755 index 0000000..a056d19 --- /dev/null +++ b/scripts/.local/bin/tabletpad @@ -0,0 +1,10 @@ +pad=$(xsetwacom list | grep pad | cut -f 1 | xargs) + +xsetwacom --set "$pad" Button 1 "key +shift +alt p -alt -shift" +xsetwacom --set "$pad" Button 2 "key +shift +alt a -alt -shift" +xsetwacom --set "$pad" Button 3 12 +xsetwacom --set "$pad" Button 8 13 +xsetwacom --set "$pad" Button 9 14 +xsetwacom --set "$pad" Button 10 "key +shift +alt l -alt -shift" +xsetwacom --set "$pad" Button 11 "key +shift +alt s -alt -shift" +xsetwacom --set "$pad" Button 12 "key +ctrl z -ctrl" diff --git a/scripts/.local/bin/tabletreset b/scripts/.local/bin/tabletreset new file mode 100755 index 0000000..3f68711 --- /dev/null +++ b/scripts/.local/bin/tabletreset @@ -0,0 +1,2 @@ +notify-send 'Tablet: reset' +tabletscale 1920 1080 1 87 54 0 0 diff --git a/scripts/.local/bin/tabletscale b/scripts/.local/bin/tabletscale new file mode 100755 index 0000000..c405048 --- /dev/null +++ b/scripts/.local/bin/tabletscale @@ -0,0 +1,41 @@ +#!/bin/bash + +args=("$@") + +#echo Number of arguments: $# + +tablet=$(xsetwacom list | grep stylus | cut -f 1 | xargs) + +Wx=${args[0]} +Wy=${args[1]} +alpha=${args[2]} +Sx=${args[3]} +Sy=${args[4]} +skewX=${args[5]} +skewY=${args[6]} + +xsetwacom --set "$tablet" ResetArea +Nx=$(xsetwacom get "$tablet" Area | cut -f 3 -d ' ') +Ny=$(xsetwacom get "$tablet" Area | cut -f 4 -d ' ') + +resX=$(xdpyinfo | awk '/dimensions/{print $2}' | cut -f 1 -d 'x') +resY=$(xdpyinfo | awk '/dimensions/{print $2}' | cut -f 2 -d 'x') + +#dual display hack +#resX=$(($resX/2)) + +Nxx=$(($Nx/$alpha)) +Nyy=$(($Sx*$Ny*$Wy/$alpha/$Sy/$Wx)) + +dx=$((($resX-$Wx)/2 + $skewX)) +dy=$((($resY-$Wy)/2 + $skewY)) + +#echo $tablet +#echo Area 0 0 $Nxx $Nyy +#echo MapToOutput ${Wx} ${Wy} ${dx} ${dy} + +#xsetwacom --set "${tablet}" Area 0 0 $Nxx $Nyy +xsetwacom --set "${tablet}" Area $((($Nx-$Nxx)/2)) 0 $((($Nx+$Nxx)/2)) $Nyy +#xsetwacom --set "${tablet}" Area 0 $(($Ny-$Nyy)) $Nxx $Ny +xsetwacom --set "${tablet}" MapToOutput ${Wx}x${Wy}+$dx+$dy + diff --git a/scripts/.local/bin/to60fps b/scripts/.local/bin/to60fps new file mode 100755 index 0000000..68b806c --- /dev/null +++ b/scripts/.local/bin/to60fps @@ -0,0 +1,46 @@ +#input file full name +iffname=$1 +ifname=${iffname%.*} +ifext=${iffname##*.} + +#temporary file full name +tffname=$ifname.temp.mkv + +#output file full name +offname=$ifname-60fps.mp4 + +quality=$2 #23..12, less is more quality + +threads=$3 + +#echo $iffname $ifname $ifext +#echo $tffname +#echo $offname + +mpv \ + "$iffname" \ + --o="$tffname" \ + --no-audio \ + --no-sub \ + --no-sub-auto \ + --input-ipc-server=/tmp/mpvencodesocket \ + --input-media-keys=no \ + --no-msg-color \ + --vf=vapoursynth:/home/ivan/.local/share/SVP4/scripts/ffff.py:4:6 \ + --of=matroska \ + --ovc=libx264 \ + --ovcopts=crf=$quality,preset=slow,threads=$threads + +ffmpeg \ + -y \ + -i "$iffname" \ + -i "$tffname" \ + -map 1:v \ + -map 0:a? \ + -map 0:s? \ + -vcodec copy \ + -acodec copy \ + -scodec copy \ + "$offname" + +rm "$tffname" |
