scripts

Random scripts
git clone git://git.margiolis.net/scripts.git
Log | Files | Refs | README

commit 0889c426505b2a5c95a2c1c41bb5112100ca5e34
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun,  3 Apr 2022 01:34:50 +0300

initial commit

Diffstat:
AMakefile | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
AREADME | 1+
Aausplit | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautocomp | 4++++
Abatnfy | 10++++++++++
Adoccomp | 26++++++++++++++++++++++++++
Adocprev | 14++++++++++++++
Aextr | 34++++++++++++++++++++++++++++++++++
Afontupd | 11+++++++++++
Airssi_torconf | 16++++++++++++++++
Anamefmt | 6++++++
Anewsboat_bookmark | 3+++
Apassget | 4++++
Apush | 6++++++
Arssread | 4++++
Ascreencast | 8++++++++
Ase | 3+++
Asetscreens | 13+++++++++++++
Asysact | 11+++++++++++
Atag | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aunix | 26++++++++++++++++++++++++++
Aupd | 34++++++++++++++++++++++++++++++++++
Avdq | 18++++++++++++++++++
Avds | 14++++++++++++++
Avmstart | 46++++++++++++++++++++++++++++++++++++++++++++++
Avmstop | 24++++++++++++++++++++++++
Awalset | 6++++++
Awttr | 3+++
28 files changed, 535 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,53 @@ +.POSIX: + +SCRIPTS = ausplit \ + autocomp \ + batnfy \ + doccomp \ + docprev \ + extr \ + fontupd \ + irssi_torconf \ + namefmt \ + newsboat_bookmark \ + passget \ + push \ + rssread \ + screencast \ + se \ + setscreens \ + sysact \ + tag \ + unix \ + upd \ + vdq \ + vds \ + vmstart \ + vmstop \ + walset \ + wttr + +PREFIX = /usr/local + +all: ${SCRIPTS} + chmod +x ${SCRIPTS} + +dist: + mkdir -p ${DIST} + cp -R ${SCRIPTS} ${DIST} + tar -cf ${DIST}.tar ${DIST} + gzip ${DIST}.tar + rm -rf ${DIST} + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f ${SCRIPTS} ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/${SCRIPTS} + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/${SCRIPTS} + +clean: + rm -f ${DIST}.tar.gz + +.PHONY: all clean dist install uninstall diff --git a/README b/README @@ -0,0 +1 @@ +# make install diff --git a/ausplit b/ausplit @@ -0,0 +1,74 @@ +#!/bin/sh + +# ffmpeg and my `tag` script required. +main() +{ + test ${#} -ne 2 && usage + + auin="${1}" + local tfile="${2}" + total="$(wc -l < "${tfile}")" + # The extension must exist in `tag`. + ext="${1#*.}" + + xread "Album/book title: " album + xread "Artist/author: " author + xread "Publication year: " year + + namefmt="$(fmt_name "${album}")" + mkdir -p "${namefmt}" || exit 1 + + while read -r line; do + end="$(echo "${line}" | cut -d' ' -f1)" + test -n "${start}" && split_file + title="$(echo "${line}" | cut -d' ' -f 2-)" + titlefmt="$(fmt_name "${title}")" + track="$((track+1))" + start="${end}" + done < "${tfile}" + + # The last track must be done outside the loop. + split_file +} + +usage() +{ + echo "usage: ${0##*/} audio timecode_file" 1>&2 && exit 1 +} + +xread() +{ + printf "%s" "${1}" && read -r ${2} +} + +fmt_name() +{ + echo "${1}" | iconv -cf UTF-8 -t ASCII//TRANSLIT | + tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | + sed "s/-\+/-/g;s/\(^-\|-\$\)//g" +} + +split_file() +{ + echo "From ${start} to ${end}; ${track} ${title}" + echo "Splitting \"${title}\"..." + ofile="${namefmt}/$(printf "%.2d" "${track}")-${titlefmt}.${ext}" + ffmpeg \ + -nostdin -y -loglevel -8 \ + -i "${auin}" \ + -ss "${start}" \ + `test ${track} -eq ${total} || echo "-to ${end}"` \ + -vn -c copy \ + "${ofile}" && + echo "Tagging \"${title}\"..." && + tag \ + -a "${author}" \ + -A "${album}" \ + -t "${title}" \ + -n "${track}" \ + -N "${total}" \ + -d "${year}" \ + "${ofile}" +} + +main "${@}" diff --git a/autocomp b/autocomp @@ -0,0 +1,4 @@ +#!/bin/sh + +pkill -f "entr -n doccomp" +echo "${1}" | entr -n doccomp "${1}" diff --git a/batnfy b/batnfy @@ -0,0 +1,10 @@ +#!/bin/sh + +export DISPLAY=":0.0" # cron cannot open the display without this. +perc=$(sysctl -n hw.acpi.battery.life) +charg=$(sysctl -n hw.acpi.battery.state) +if [ ${perc} -le 10 ] && [ ${charg} -ne 2 ]; then + echo "Low battery" | nfy +elif [ ${perc} -ge 99 ] && [ ${charg} -eq 2 ]; then + echo "Battery fully charged" | nfy +fi diff --git a/doccomp b/doccomp @@ -0,0 +1,26 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} file" 1>&2 && exit 1 +} + +file_exists() +{ + test ! -f "${file}" && echo "${0##*/}: ${file}: file not found" 1>&2 && exit 1 +} + +test ${#} -eq 0 && usage + +file="$(readlink -f "${1}")" +dir="${file%/*}" +base="${file%.*}" +ext="${file##*.}" + +file_exists +cd "${dir}" || exit 1 + +case "${ext}" in + md) pandoc ${file} --pdf-engine=xelatex -V mainfont=Arial -o "${base}.pdf" ;; + tex) pdflatex ${file} && rm -f *.aux *.log *.out *.bcf *.run.xml *.bbl *.blg *-blx.bib ;; +esac diff --git a/docprev b/docprev @@ -0,0 +1,14 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} file" 1>&2 && exit 1 +} + +test ${#} -eq 0 && usage +base="${1%.*}" + +case "${1}" in + *.html) setsid -f "${BROWSER}" "${base}.html" ;; + *.tex) setsid -f xdg-open "${base}.pdf" ;; +esac diff --git a/extr b/extr @@ -0,0 +1,34 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} [-d dir] file" 1>&2 && exit 1 +} + +while getopts d: arg; do +case "${arg}" in + d) dir="${OPTARG}" ;; + *) usage ;; +esac +done +shift "$(expr ${OPTIND} - 1)" + +archive="$(readlink -f ${1})" +test -z "${archive}" && usage +test -n "${dir}" && mkdir -p "${dir}" && cd "${dir}" + +case "${archive}" in + *.tar.bz2|*.tbz2) tar xvjf "${archive}" ;; + *.tar.xz) tar -xf "${archive}" ;; + *.tar.gz|*.tgz) tar xvzf "${archive}" ;; + *.lzma) unlzma "${archive}" ;; + *.bz2) bunzip2 "${archive}" ;; + *.rar) unrar x -ad "${archive}" ;; + *.gz) gunzip "${archive}" ;; + *.tar) tar xvf "${archive}" ;; + *.zip) unzip "${archive}" ;; + *.Z) uncompress "${archive}" ;; + *.7z) 7z x "${archive}" ;; + *.xz) unxz "${archive}" ;; + *) echo "i don't know how to extract this" 1>&2 ;; +esac diff --git a/fontupd b/fontupd @@ -0,0 +1,11 @@ +#!/bin/sh + +dir=${HOME}/.fonts + +mkdir -p ${dir} +chmod 755 ${dir} +cd ${dir} +chmod 644 * +mkfontdir +xset fp+ ${dir} +xset fp rehash diff --git a/irssi_torconf b/irssi_torconf @@ -0,0 +1,16 @@ +#!/bin/sh + +echo "mapaddress 10.40.40.40 libera75jm6of4wxpxt4aynol3xjmbtxgfyjpu34ss4d7r7q2v5zrpyd.onion" >> /usr/local/etc/tor/torrc +service tor restart +mkdir -p ~/.irssi/certs && cd ~/.irssi/certs +openssl req -x509 -sha256 -new -newkey rsa:4096 -days 1000 -nodes -out libera.crt -keyout libera.key +cat libera.crt libera.key > ~/.irssi/certs/libera.pem +chmod 600 libera.pem +rm libera.key libera.crt +printf "/msg NickServ CERT ADD " +openssl x509 -in ~/.irssi/certs/libera.pem -outform der | sha1 | cut -d' ' -f1 +echo "/network add -sasl_username cmrg -sasl_password cmrgsasl -sasl_mechanism EXTERNAL LiberaTor" +echo "/server add -ssl -ssl_cert ~/.irssi/certs/libera.pem -net LiberaTor 10.40.40.40 6697" +echo "/ignore * CTCPS" +echo "/save" +echo "/quit" diff --git a/namefmt b/namefmt @@ -0,0 +1,6 @@ +#!/bin/sh + +# FIXME: give path/s from command line +for file in $(find .); do + mv ${file} $(echo ${file} | tr '-' '_') +done diff --git a/newsboat_bookmark b/newsboat_bookmark @@ -0,0 +1,3 @@ +#!/bin/sh + +printf "%s\t%s\n" "$1" "$2" | expand -t8 >> "${HOME}/shit/playlist" diff --git a/passget b/passget @@ -0,0 +1,4 @@ +#!/bin/sh + +pass "$(pass | sed 1d | awk '{print $2}' | dmenu -l 30)" | +xargs echo -n | xclip -sel clip diff --git a/push b/push @@ -0,0 +1,6 @@ +#!/bin/sh + +branch=$(git branch --show-current) +for remote in $(git remote); do + git push ${remote} ${branch} +done diff --git a/rssread b/rssread @@ -0,0 +1,4 @@ +#!/bin/sh + +sfeed_update +sfeed_curses ${HOME}/.sfeed/feeds/* diff --git a/screencast b/screencast @@ -0,0 +1,8 @@ +#!/bin/sh + +ffmpeg -y \ + -f x11grab \ + -s $(xrandr | grep "connected primary" | awk '{print $4}' | sed 's/+0+0//') \ + -i :0.0 \ + -c:v libx264 -r 30 -c:a mp3 ${1} + #-f oss -i default \ diff --git a/se b/se @@ -0,0 +1,3 @@ +#!/bin/sh + +du -a /home/christos/src/scripts | awk '{print $2}' | fzf | xargs -r ${EDITOR} diff --git a/setscreens b/setscreens @@ -0,0 +1,13 @@ +#!/bin/sh +xrandr \ + --output DVI-I-0 \ + --mode 1280x1024 \ + --pos 1920x56 \ + --rotate normal \ + --output HDMI-0 \ + --off \ + --output DVI-D-0 \ + --primary \ + --mode 1920x1080 \ + --pos 0x0 \ + --rotate normal diff --git a/sysact b/sysact @@ -0,0 +1,11 @@ +#!/bin/sh + +cmds="\ +lock slock +leave_dwm kill -TERM $(pidof -s dwm) +renew_dwm kill -HUP $(pidof -s dwm) +reboot ${reb:-doas reboot} +shutdown ${shut:-doas shutdown -p now}" + +choice="$(echo "${cmds}" | cut -d ' ' -f 1 | dmenu)" || exit 1 +`echo "${cmds}" | grep "^${choice}" | cut -d ' ' -f2-` diff --git a/tag b/tag @@ -0,0 +1,63 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} [-a artist] [-A album_title] [-c comment]" 1>&2 + echo " [-d year] [-g genre] [-n trackno] [-N totalno]" 1>&2 + echo " [-t song_title] file" 1>&2 + exit 1 +} + +xread() +{ + printf "%s" "${1}" && read -r ${2} +} + +while getopts "a:t:A:n:N:d:g:c:f:" arg; do +case "${arg}" in + a) artist="${OPTARG}" ;; + t) title="${OPTARG}" ;; + A) album="${OPTARG}" ;; + n) track="${OPTARG}" ;; + N) total="${OPTARG}" ;; + d) date="${OPTARG}" ;; + g) genre="${OPTARG}" ;; + c) comment="${OPTARG}" ;; + f) file="${OPTARG}" ;; + *) usage ;; +esac +done +shift $((OPTIND - 1)) + +file="${1}" +test ! -f "${file}" && echo "${0##*/}: file not found" && usage + +test -z "${title}" && xread "Title: " title +test -z "${artist}" && xread "Artist: " artist +test -z "${album}" && xread "Album: " album +test -z "${track}" && xread "Track number: " track + +info="Title=${title} +Artist=${artist} +Album=${album} +Track=${track} +Total=${total} +Date=${date} +Genre=${genre} +Comment=${comment}" + +echo "${info}" + +case "${file}" in + *.ogg) echo "${info}" | vorbiscomment -w "${file}" ;; + *.opus) echo "${info}" | opustags -i -S "${file}" ;; + *.mp3) eyeD3 -Q --remove-all \ + -a "${artist}" \ + -A "${album}" \ + -t "${title}" \ + -n "${track}" \ + -N "${total}" \ + -Y "${date}" \ + "${file}" ;; + *) echo "${0##*/}: file type not implemented yet" ;; +esac diff --git a/unix b/unix @@ -0,0 +1,26 @@ +#!/bin/sh + +#original artwork by http://www.sanderfocus.nl/#/portfolio/tech-heroes +#converted to shell by #nixers @ irc.unix.chat + +cat << 'eof' + ,_ ,_==▄▂ + , ▂▃▄▄▅▅▅▂▅¾. / / + ▄▆<´ "»▓▓▓%\ / / / / + ,▅7" ´>▓▓▓% / / > / >/% + ▐¶▓ ,»▓▓¾´ /> %/%// / / + ▓▃▅▅▅▃,,▄▅▅▅Æ\// ///>// />/ / + V║«¼.;→ ║<«.,`=// />//%/% / / + //╠<´ -²,)(▓~"-╝/¾/ %/>/ /> + / / / ▐% -./▄▃▄▅▐, /7//;//% / / + / ////`▌▐ %zWv xX▓▇▌//&;% / / + / / / %//%/¾½´▌▃▄▄▄▄▃▃▐¶\/& / + </ /</%//`▓!%▓%╣[38;5;255;╣WY<Y)y&/`\ + / / %/%//</%//\i7; ╠N>)VY>7; \_ UNIX IS VERY SIMPLE IT JUST NEEDS A + / /</ //<///<_/%\▓ V%W%£)XY _/%‾\_, GENIUS TO UNDERSTAND ITS SIMPLICITY + / / //%/_,=--^/%/%%\¾%¶%%} /%%%%%%;\, + %/< /_/ %%%%%;X%%\%%;, _/%%%;, \ + / / %%%%%%;, \%%l%%;// _/%;, dmr + / %%%;, <;\-=-/ / + ;, l +eof diff --git a/upd b/upd @@ -0,0 +1,34 @@ +#!/bin/sh + +# FIXME: trim random symbols +case $1 in + www) src="${HOME}/src/margiolis.net/" + dst="master@margiolis.net:/var/www/htdocs/margiolis.net" + ;; + ftp) src="${2}" + dst="master@margiolis.net:/var/www/htdocs/ftp.margiolis.net/${3}" + ;; + vps) src="${2}" + dst="master@margiolis.net:${3}" + ;; + lap) src="${2}" + dst="tpad:${3}" + ;; + desk) src="${2}" + dst="pleb:${3}" + ;; + old) src="${2}" + dst="old:${3}" + ;; + foo) src="${2}" + dst="foo:${3}" + ;; + # add disk, storage, all + *) echo "usage: ${0##*/} {www | ftp | vps | lap | desk | old | foo} src dst" 1>&2 && exit 1 ;; +esac +test -z "${src}" && echo "${0##*/}: src is empty" 1>&2 && exit 1 +test -z "${dst}" && echo "${0##*/}: dest is empty" 1>&2 && exit 1 + +# add directory error check +read -erp "${0##*/}: transfer '${src}' to '${dst}' (y/N)? " act +test "${act}" = "y" && rsync -Purv --delete-after "${src}" "${dst}" diff --git a/vdq b/vdq @@ -0,0 +1,18 @@ +#!/bin/sh + +QUEUE="${HOME}/shit/queue" +while getopts a:dfv arg; do +case "${arg}" in + a) echo "${OPTARG}" >> ${QUEUE} + exit 0 ;; + d) rm ${QUEUE} + exit 0 ;; + f) echo ${QUEUE} + exit 0 ;; + v) cat ${QUEUE} | dmenu -l 30 + exit 0 ;; + *) echo "usage: ${0##*/} [-dfv] [-a url]" 1>&2 + exit 1 ;; +esac +done +cat ${QUEUE} | awk '{print $1}' | xargs mpv diff --git a/vds b/vds @@ -0,0 +1,14 @@ +#!/bin/sh + +PLAYLIST="${HOME}/shit/playlist" +QUEUE="$(vdq -f)" +while getopts p:q arg; do +case "${arg}" in + p) PLAYLIST="${OPTARG}" ;; + q) vdq -a "$(cat ${PLAYLIST} | dmenu -l 30)" + exit 0 ;; + *) echo "usage: ${0##*/} [-q] [-p playlist]" 1>&2 + exit 1 ;; +esac +done +cat ${PLAYLIST} | dmenu -l 30 | awk '{print $1}' | xargs mpv diff --git a/vmstart b/vmstart @@ -0,0 +1,46 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} [-u] [-c cpu] [-C com] [-d disk] [-i img] [-m mem] [-t tap] name" 1>&2 + exit 1 +} + +cpu="2" +mem="2G" +disk="disk.img" +tap="tap0" + +# TODO: opt: disname, lpc, xhci +while getopts c:C:d:i:m:t:u arg; do +case "${arg}" in + c) cpu="${OPTARG}" ;; + C) com="${OPTARG}" ;; + d) disksiz="${OPTARG}" ;; + i) img="${OPTARG}" ;; + m) mem="${OPTARG}" ;; + t) tap="${OPTARG}" ;; + u) uefi="-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd" ;; + *) usage ;; +esac +done +shift $((OPTIND - 1)) + +name="${1}" +test -z "${name}" && usage + +test -n "${disksiz}" && truncate -s "${disksiz}" ${disk} +ifconfig "${tap}" up + +bhyve -c ${cpu} -m ${mem} -wH \ + -s 0,hostbridge \ + `test -n "${img}" && echo "-s 3,ahci-cd,${img}"` \ + -s 4,ahci-hd,${disk} \ + -s 5,virtio-net,${tap} \ + -s 29,fbuf,tcp=0.0.0.0:5900,w=800,h=600,wait \ + -s 30,xhci,tablet \ + -s 31,lpc \ + `test -n "${com}" && echo "-l com1,${com}"` \ + `test -n "${uefi}" && echo ${uefi}` \ + ${name} + diff --git a/vmstop b/vmstop @@ -0,0 +1,24 @@ +#!/bin/sh + +usage() +{ + echo "usage: ${0##*/} [-t tap] name" 1>&2 + exit 1 +} + +tap="tap0" + +while getopts t: arg; do +case "${arg}" in + t) tap="${OPTARG}" ;; + *) usage ;; +esac +done +shift $((OPTIND - 1)) + +name="${1}" +test -z "${name}" && usage + +ifconfig ${tap} down +bhyvectl --force-poweroff --vm=${name} +bhyvectl --destroy --vm=${name} diff --git a/walset b/walset @@ -0,0 +1,6 @@ +#!/bin/sh + +bgloc="${HOME}/.local/share/bg" +test -f "${1}" && ln -sf "$(readlink -f "${1}")" "${bgloc}" && +echo "Changing wallpaper to ${bgloc}" | nfy +xwallpaper --zoom "$(readlink -f "${bgloc}")" >/dev/null diff --git a/wttr b/wttr @@ -0,0 +1,3 @@ +#!/bin/sh + +curl https://wttr.in/Athens+Greece | less -R