scripts

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

commit 26f03ba79f0dfaa4d4f99974860f7764de6110a4
parent 1fb9afd0070544b5c3c09afa368013de7c1c151b
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed, 11 Jan 2023 18:41:20 +0200

fixed jail and tag scripts

Diffstat:
MMakefile | 3+--
Mbatnfy | 4+++-
Mbookmark | 6+++++-
Ddeljail | 7-------
Mdoccomp | 5++++-
Dmkjail | 9---------
Mscreencast | 12++++++------
Mse | 3++-
Msetscreens | 1+
Asjail | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtag | 42+++++++++++++++++-------------------------
Mvds | 1+
Mwalset | 1+
13 files changed, 130 insertions(+), 53 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,13 +5,11 @@ TARGS = ausplit \ backup \ batnfy \ bookmark \ - deljail \ doccomp \ docprev \ extr \ fontupd \ irssi_torconf \ - mkjail \ mntdroid \ namefmt \ passget \ @@ -20,6 +18,7 @@ TARGS = ausplit \ screencast \ se \ setscreens \ + sjail \ sysact \ tag \ unix \ diff --git a/batnfy b/batnfy @@ -1,8 +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) + +export DISPLAY=":0.0" # cron cannot open the display without this. + if [ ${perc} -le 10 ] && [ ${charg} -ne 2 ]; then echo "Low battery" | nfy elif [ ${perc} -ge 99 ] && [ ${charg} -eq 2 ]; then diff --git a/bookmark b/bookmark @@ -10,6 +10,8 @@ bmk_getfile() while [ -d ${bmkfile} ]; do bmkfile="$( find ${bmkfile} -maxdepth 1 | + sed 1d | + sort | dmenu -i -l 10 -p "Choose a file" )" || exit 1 done @@ -52,4 +54,6 @@ esac done bmk_getfile -cat ${bmkfile} | dmenu -i -l 50 | awk '{print $1}' | xargs -r xdotool type + +cat ${bmkfile} | dmenu -i -l 50 | awk '{print $1}' | +xargs -r xdotool type --delay 0 diff --git a/deljail b/deljail @@ -1,7 +0,0 @@ -#!/bin/sh - -test $# -ne 1 && echo "usage: ${0##*/} jail" && exit 1 - -service jail stop ${1} -chflags -R noschg /usr/local/jail/${1} -rm -rf /usr/local/jail/${1} diff --git a/doccomp b/doccomp @@ -21,7 +21,10 @@ file_exists cd "${dir}" || exit 1 case "${ext}" in - md) pandoc ${file} --pdf-engine=xelatex -V mainfont=Arial -o "${base}.pdf" ;; + 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/mkjail b/mkjail @@ -1,9 +0,0 @@ -#!/bin/sh - -test $# -ne 1 && echo "usage: ${0##*/} jail" && exit 1 - -# TODO: edit rc.conf and jail.conf - -mkdir -p /usr/local/jail/${1} -bsdinstall jail /usr/local/jail/${1} -service jail start ${1} diff --git a/screencast b/screencast @@ -1,9 +1,9 @@ #!/bin/sh ffmpeg -y \ - -f x11grab \ - -s $(xrandr | grep "connected primary" | awk '{print $4}' | sed 's/+0+0//') \ - -i :0.0 \ - -f oss -i /dev/dsp -filter:a "asetpts=N/SR/TB" \ - -c:v libx264 -r 30 -c:a mp3 \ - ${1} + -f x11grab \ + -s $(xrandr | grep "connected primary" | awk '{print $4}' | sed 's/+0+0//') \ + -i :0.0 \ + -f oss -i /dev/dsp -filter:a "asetpts=N/SR/TB" \ + -c:v libx264 -r 30 -c:a mp3 \ + ${1} diff --git a/se b/se @@ -1,3 +1,4 @@ #!/bin/sh -find /home/christos/src/scripts | grep -v '\.git' | fzf | xargs -r ${EDITOR} +find /home/christos/src/scripts | sed 1d | grep -v '\.git' | sort | fzf | +xargs -r ${EDITOR} diff --git a/setscreens b/setscreens @@ -1,4 +1,5 @@ #!/bin/sh + xrandr \ --output DVI-I-0 \ --mode 1280x1024 \ diff --git a/sjail b/sjail @@ -0,0 +1,89 @@ +#!/bin/sh + +sjail_init() +{ + echo " +path = \"/usr/local/jail/\${name}\"; +host.hostname = \"\${name}\"; + +exec.clean; +exec.start = \"/bin/sh /etc/rc\"; +exec.stop = \"/bin/sh /etc/rc.shutdown\"; +allow.mount; +allow.raw_sockets = 1; +mount.devfs; +devfs.ruleset = \"5\"; +vnet; +sysvmsg = new; +sysvsem = new; +sysvshm = new; +" >> /etc/jail.conf + + echo " +jail_enable=\"YES\" +jail_parallel_start=\"YES\" +jail_reverse_stop=\"YES\" + +if_bridge_load=\"YES\" +if_epair_load=\"YES\" + +cloned_interfaces=\"bridge0 epair0\" +ifconfig_bridge0=\"addm re0 addm epair0a up\" +ifconfig_epair0a=\"up\" +" >> /etc/rc.conf + + echo " +[devfsrules_jails=5] +add include \$devfsrules_hide_all +add include \$devfsrules_unhide_basic +add include \$devfsrules_unhide_login +add path 'bpf*' unhide +" >> /etc/devfs.conf + + /etc/netstart + service devfs restart +} + +sjail_new() +{ + local name="${1}" + + echo " +${name} { + vnet.interface = \"epair0b\"; + exec.start += \"dhclient epair0b\"; +} +" >> /etc/jail.conf + + mkdir -p /usr/local/jail + mkdir -p /usr/local/jail/${name} + bsdinstall jail /usr/local/jail/${name} + service jail start ${name} +} + +sjail_del() +{ + local name="${1}" + + service jail stop ${name} + chflags -R noschg /usr/local/jail/${name} + rm -rf /usr/local/jail/${name} + sed "/${name} {/,/}/d" /etc/jail.conf +} + +usage() +{ + echo "usage: ${0##*/} [-i] [-n jail_name] [-d jail_name]" 1>&2 + exit 1 +} + +while getopts id:n: arg; do +case "${arg}" in + i) sjail_init; exit 0 ;; + d) sjail_del "${OPTARG}"; exit 0 ;; + n) sjail_new "${OPTARG}"; exit 0 ;; + *) usage ;; +esac +done + +usage diff --git a/tag b/tag @@ -36,28 +36,20 @@ 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 +test -z "${total}" && xread "Total tracks in album: " total +test -z "${date}" && xread "Date: " date +test -z "${genre}" && xread "Genre: " genre + +temp="$(mktemp)" +cp -f "${file}" "${temp}" +ffmpeg \ + -i "${temp}" \ + -map 0 -y -codec copy \ + -metadata title="${title}" \ + -metadata album="${album}" \ + -metadata artist="${artist}" \ + -metadata track="${track}${total:+/"${total}"}" \ + ${date:+-metadata date="${date}"} \ + ${genre:+-metadata genre="${genre}"} \ + ${comment:+-metadata comment="${comment}"} "${file}" +rm -f ${temp} diff --git a/vds b/vds @@ -1,6 +1,7 @@ #!/bin/sh PLAYLIST="${HOME}/shit/playlist" + while getopts p: arg; do case "${arg}" in p) PLAYLIST="${OPTARG}" ;; diff --git a/walset b/walset @@ -1,6 +1,7 @@ #!/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