scripts

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

commit f3e3499ead0f5b9d419fa5b29ff9b1b8445f4b2f
parent 022dfcfc9429b75fa5a7432a052db1eed7a38c4b
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri, 27 May 2022 00:52:45 +0300

simplify

Diffstat:
Mbackup | 75+++++++++++++++++++++++++++++++++++++++------------------------------------
Mdeljail | 2+-
Mdoccomp | 4++--
Mmkjail | 2+-
Mvdq | 14--------------
Mvds | 6++----
6 files changed, 45 insertions(+), 58 deletions(-)

diff --git a/backup b/backup @@ -1,5 +1,43 @@ #!/bin/sh +main() +{ + f_incr=0 # Incremental backup + f_snap=0 # Renew snapshots in case they already exist + + while getopts ir arg; do + case "${arg}" in + i) f_incr=1 ;; + r) f_snap=1 ;; + *) usage ;; + esac + done + shift $((OPTIND - 1)) + + test ${#} -ne 2 && usage + + src_pool="${1}" + dst_pool="${2}" + + pool_exists "${src_pool}" + pool_exists "${dst_pool}" + + new_snap="$(date '+%Y%m%d')" + src_last_snap=$(last_snap "${src_pool}") + dst_last_snap=$(last_snap "${dst_pool}") + nsnaps=$(zfs list -t snapshot -o name ${dst_pool} | sed 1d | wc -l) + + delete_existing_snap "${src_pool}" "${src_last_snap}" + zfs snapshot -r ${src_pool}@${new_snap} + + if [ ${f_incr} -eq 1 ]; then + zfs send -RI ${src_pool}@${dst_last_snap} ${src_pool}@${new_snap} | + pv | zfs recv -Fu ${dst_pool} + else + zfs send -R ${src_pool}@${new_snap} | pv | zfs recv -Fu ${dst_pool} + fi +} + usage() { echo "usage: ${0##*/} [-ir] src[/set] dst[/set]" 1>&2 @@ -37,39 +75,4 @@ delete_existing_snap() fi } -f_incr=0 # Incremental backup -f_snap=0 # Renew snapshots in case they already exist - -while getopts ir arg; do -case "${arg}" in - i) f_incr=1 ;; - r) f_snap=1 ;; - *) usage ;; -esac -done -shift $((OPTIND - 1)) - -test ${#} -ne 2 && usage - -src_pool="${1}" -dst_pool="${2}" - -pool_exists "${src_pool}" -pool_exists "${dst_pool}" - -new_snap="$(date +%Y%m%d)" -src_last_snap=$(last_snap "${src_pool}") -dst_last_snap=$(last_snap "${dst_pool}") -nsnaps=$(zfs list -t snapshot -o name ${dst_pool} | sed 1d | wc -l) - -delete_existing_snap "${src_pool}" "${src_last_snap}" -zfs snapshot -r ${src_pool}@${new_snap} - -# Make sure dst has more than 1 snapshots before we delete anything. -#test ${nsnaps} -le 1 || delete_existing_snap "${dst_pool}" "${dst_last_snap}" - -if [ ${f_incr} -eq 1 ]; then - zfs send -RI ${src_pool}@${dst_last_snap} ${src_pool}@${new_snap} | pv | zfs recv -Fu ${dst_pool} -else - zfs send -R ${src_pool}@${new_snap} | pv | zfs recv -Fu ${dst_pool} -fi +main ${@} diff --git a/deljail b/deljail @@ -1,6 +1,6 @@ #!/bin/sh -test $# -ne 1 && echo "usage: ${0##*/} jail" 1>&2; exit +test $# -ne 1 && echo "usage: ${0##*/} jail" && exit 1 service jail stop ${1} chflags -R noschg /usr/local/jail/${1} diff --git a/doccomp b/doccomp @@ -22,6 +22,6 @@ 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 ;; + tex) pdflatex ${file} + rm -f *.aux *.log *.out *.bcf *.run.xml *.bbl *.blg *-blx.bib ;; esac diff --git a/mkjail b/mkjail @@ -1,6 +1,6 @@ #!/bin/sh -test $# -ne 1 && echo "usage: ${0##*/} jail" 1>&2; exit +test $# -ne 1 && echo "usage: ${0##*/} jail" && exit 1 # TODO: edit rc.conf and jail.conf diff --git a/vdq b/vdq @@ -1,18 +1,4 @@ #!/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 mpv $(awk '{print $1}' ${QUEUE}) diff --git a/vds b/vds @@ -2,12 +2,10 @@ PLAYLIST="${HOME}/shit/playlist" QUEUE="$(vdq -f)" -while getopts p:q arg; do +while getopts p: 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 + *) echo "usage: ${0##*/} [-p playlist]" 1>&2 exit 1 ;; esac done