From 9cda0e04d81c166db423b2c6f1af8cfb3f4d3523 Mon Sep 17 00:00:00 2001 From: Von Random Date: Thu, 21 Jan 2021 13:23:22 +0300 Subject: [PATCH 01/10] base256.py: support hex value --- base256.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base256.py b/base256.py index 7a3e860..05d3528 100755 --- a/base256.py +++ b/base256.py @@ -4,7 +4,8 @@ from sys import argv def from_base256(number): - num = int(number) + base = 16 if number.startswith('0x') else 10 + num = int(number, base) addr = list() for e in range(3, -1, -1): multiplier = 256 ** e From d250409d5f0a29946ac85bf719643a008fd50146 Mon Sep 17 00:00:00 2001 From: Von Random Date: Thu, 21 Jan 2021 13:25:56 +0300 Subject: [PATCH 02/10] base256.py: better support for hex value --- base256.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/base256.py b/base256.py index 05d3528..1684bb1 100755 --- a/base256.py +++ b/base256.py @@ -4,8 +4,7 @@ from sys import argv def from_base256(number): - base = 16 if number.startswith('0x') else 10 - num = int(number, base) + num = int(number, 0) addr = list() for e in range(3, -1, -1): multiplier = 256 ** e From 5a634016cf218d279628620d89b247f0e1dbb9eb Mon Sep 17 00:00:00 2001 From: Von Random Date: Sun, 7 Feb 2021 05:36:55 +0300 Subject: [PATCH 03/10] q3srv: implement a simple wrapper script for q3ded --- q3srv | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 q3srv diff --git a/q3srv b/q3srv new file mode 100755 index 0000000..0b4f149 --- /dev/null +++ b/q3srv @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +from argparse import ArgumentParser +from os import system +from random import shuffle +from sys import exit + +# TODO: move this shit to a yaml config somewhere in /etc +USER = 'quake3' # linux user, for sudo -u +BIN = '/usr/bin/q3ded' +CONF = '/srv/q3/.q3a/baseq3/autoexec.cfg' +PARAM = '+exec autoexec.cfg' + +MAPLISTS = { + 'ffa': [ + 'q3dm2', 'q3dm3', 'q3dm4', 'q3dm5', 'q3dm6', + 'q3dm7', 'q3dm8', 'q3dm9', 'q3dm10', 'q3dm11' + ], + 'duel': [ + 'q3dm1', 'q3dm2', 'pro-q3dm6', 'pro-q3dm13', + 'q3tourney1', 'q3tourney3', 'q3tourney5', 'q3tourney6', + 'pro-q3tourney2', 'pro-q3tourney4' + ], + 'ctf': list() +} +BOTS = { + 'level': '3', + 'names': [ + 'Anarki', 'Angel', 'Crash', 'Doom', 'Hunter', + 'Klesk', 'Major', 'Mynx', 'Orbb', 'Slash', 'Xaero' + ] +} + + +# these are saved to the q3config_server.cfg on the first run +# no point in keeping them here afterwards +BOOTSTRAP_OPTS = dict() +# BOOTSTRAP_OPTS = { +# 'sv_pure': '0', # enable client side mods, like better fonts or graphics +# 'sv_maxclients': '8', +# 'sv_hostname': 'myhost.tld' +# +# # this will let your server send maps to clients +# # the downloads are attempted from http://%sv_dlURL%/baseq3/mapname.pk3 +# # note the protocol - no support for https, +# # as well as the need to have baseq3 as a part of the path +# # note that clients have to seta cl_allowDownload 1 for that to work +# 'sv_dlURL': 'anyhost.tld/q3', +# 'sv_allowDownloads': '1' +# } + + +def parse_arguments(): + desc = 'host a q3 server' + parser = ArgumentParser(description=desc) + parser.add_argument('-m', '--gamemode', default='ffa') + parser.add_argument('-f', '--fraglimit', type=int, default=15) + parser.add_argument('-t', '--timelimit', type=int, default=10) + parser.add_argument('-b', '--bots', type=int, default=0) + return parser.parse_args() + + +def gen_confline(param, value): + return 'seta {} "{}"\n'.format(param, value) + + +def gen_maplist(maplist): + shuffle(maplist) + num = 1 + stmpl = 'set d{} "map {} ; set nextmap vstr d{}"\n' + script = str() + while maplist: + nextnum = 1 if len(maplist) == 1 else num + 1 + script += stmpl.format(num, maplist.pop(), nextnum) + num += 1 + script += 'vstr d1\n' + return script + + +def gen_addbots(count, level='3', names=list()): + shuffle(names) + btmpl = 'addbot {} {}\n' + script = str() + for bot in names[:count]: + script += btmpl.format(bot, level) + return script + + +def main(): + args = parse_arguments() + cfg_data = str() + try: + assert args.gamemode in MAPLISTS + except AssertionError: + exit('Wrong game mode specified!') + + for param in BOOTSTRAP_OPTS: + cfg_data += gen_confline(param, BOOTSTRAP_OPTS[param]) + cfg_data += gen_confline('fraglimit', args.fraglimit) + cfg_data += gen_confline('timelimit', args.timelimit) + # this should be last since it launches the actual maplist + cfg_data += gen_maplist(MAPLISTS[args.gamemode]) + if args.bots: + cfg_data += gen_addbots(args.bots, **BOTS) + + with open(CONF, 'w+') as config: + config.write(cfg_data) + system('sudo -u {} {} {}'.format(USER, BIN, PARAM)) + + +if __name__ == '__main__': + main() From e9243344a8c08382336d487184a80e519698f28d Mon Sep 17 00:00:00 2001 From: Von Random Date: Tue, 8 Jun 2021 20:27:36 +0300 Subject: [PATCH 04/10] minor tweaks and new tools --- gdk_scale | 4 ++++ base256.py => iphex | 4 ++-- post-autorandr | 51 ++++++++++++++++++++++++++++++++++++++++++ termcompat | 1 + xscreensaver-companion | 4 ++-- 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100755 gdk_scale rename base256.py => iphex (91%) create mode 100755 post-autorandr diff --git a/gdk_scale b/gdk_scale new file mode 100755 index 0000000..da2a457 --- /dev/null +++ b/gdk_scale @@ -0,0 +1,4 @@ +#!/usr/bin/env zsh + +export GDK_SCALE=$1 GDK_DPI_SCALE=$(printf '%.1f' $((1.0/$1))) +exec $2 diff --git a/base256.py b/iphex similarity index 91% rename from base256.py rename to iphex index 1684bb1..1093aaa 100755 --- a/base256.py +++ b/iphex @@ -4,7 +4,7 @@ from sys import argv def from_base256(number): - num = int(number, 0) + num = int(number, 16) addr = list() for e in range(3, -1, -1): multiplier = 256 ** e @@ -20,7 +20,7 @@ def to_base256(addr): for e in range(3, -1, -1): num += int(addr[3-e]) * 256 ** e - return str(num) + return '{0:08x}'.format(num) try: result = from_base256(argv[1]) diff --git a/post-autorandr b/post-autorandr new file mode 100755 index 0000000..9ec7c5d --- /dev/null +++ b/post-autorandr @@ -0,0 +1,51 @@ +#!/usr/bin/env zsh +#------------------------------------------------------------------------------ +# xsettingsd systemd unit: +# -- +# [Unit] +# Description=xsettingsd magic +# +# [Service] +# ExecStart=/usr/bin/xsettingsd +# ExecReload=/bin/kill -HUP $MAINPID +# +# [Install] +# WantedBy=default.target +# -- +XSETTINGSD_TEMPLATE='Xft/Hinting 1\nXft/HintStyle "hintslight"\nXft/Antialias 1\nXft/RGBA "rgb"\nXft/DPI %s\n' +XSETTINGSD_CONFIG=/run/user/$UID/xsettingsd-config + +XKB_OPTS='grp:win_space_toggle,compose:menu' +XKB_LAYOUTS='us(altgr-intl),ru(typewriter)' + +WALLPAPER=$HOME/.wallpaper + +TOUCHPAD_DEV='SynPS/2 Synaptics TouchPad' + +DPI=${1:-96} +#------------------------------------------------------------------------------ + +# reset xkbmap, set xkbmap +setxkbmap us -option +setxkbmap $XKB_LAYOUTS -option $XKB_OPTS + +# configure touchpad +xinput set-prop $TOUCHPAD_DEV 'libinput Click Method Enabled' 0 1 +xinput set-prop $TOUCHPAD_DEV 'libinput Middle Emulation Enabled' 1 + +# background +feh --bg-fill $WALLPAPER + +# dpi - xsettignsd, has to be started here because config is absent on boot +printf $XSETTINGSD_TEMPLATE $(($DPI * 1024)) > $XSETTINGSD_CONFIG +systemctl --quiet --user is-active xsettingsd || systemctl --user start xsettingsd +systemctl --user reload xsettingsd.service + +# dpi - other +xrdb -merge <(echo "Xft.dpi: $DPI") +xrandr --dpi $DPI +i3-msg restart + +# report +current_config=$(autorandr --current) +notify-send "$current_config config applied" diff --git a/termcompat b/termcompat index 0681c66..ae5c9ff 100755 --- a/termcompat +++ b/termcompat @@ -1,6 +1,7 @@ #!/usr/bin/env bash # run with more compatible TERM value typeset -A terms=( + [alacritty]='xterm' [xterm-kitty]='xterm' [rxvt-unicode-256color]='rxvt-unicode' [st-256color]='xterm-256color' diff --git a/xscreensaver-companion b/xscreensaver-companion index 929f48a..3d23176 100755 --- a/xscreensaver-companion +++ b/xscreensaver-companion @@ -35,13 +35,13 @@ function parse_actions case $action in (LOCK|BLANK) setxkbmap us -option - notify-send DUNST_COMMAND_PAUSE + dunstctl set-paused true ;; (UNBLANK) check_start gxkb $HOME/git/mine/vscripts/mykblayouts $HOME/.local/bin/touchpad-config - notify-send DUNST_COMMAND_RESUME + dunstctl set-paused false ;; esac done From 55c0f11b4020a7471377450f5a5dc890902a8ba4 Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 24 Oct 2022 00:12:46 +0300 Subject: [PATCH 05/10] termcompat alteration --- termcompat | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/termcompat b/termcompat index ae5c9ff..4598304 100755 --- a/termcompat +++ b/termcompat @@ -1,10 +1,14 @@ -#!/usr/bin/env bash +#!/usr/bin/env zsh # run with more compatible TERM value -typeset -A terms=( - [alacritty]='xterm' - [xterm-kitty]='xterm' - [rxvt-unicode-256color]='rxvt-unicode' - [st-256color]='xterm-256color' - [tmux-256color]='screen.xterm-new' -) -TERM="${terms[$TERM]:-$TERM}" exec "$@" +case $TERM in + (st-*) ;& + (alacritty*) ;& + (xterm-kitty) ;& + export TERM=xterm;; + (rxvt-unicode-*) + export TERM=rxvt-unicode;; + (tmux-*) + export TERM=screen.xterm-new;; +esac + +exec "$@" From 110a876cdcc0f121576275a9297b1f86435c3389 Mon Sep 17 00:00:00 2001 From: Von Random Date: Fri, 10 Feb 2023 00:54:56 +0200 Subject: [PATCH 06/10] add a script to test for private ip ranges --- is_private | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 is_private diff --git a/is_private b/is_private new file mode 100755 index 0000000..fcf47da --- /dev/null +++ b/is_private @@ -0,0 +1,27 @@ +#!/usr/bin/env zsh +typeset -ga PRIVATE_RANGES=( + 00001010 # 10.0.0.0/8 + 101011000001 # 172.16.0.0/12 + 1100000010101000 # 192.168.0.0/16 +) + +test_range() { + typeset net addr=$(printf '%.2x' ${(s:.:)1}) + for net in $PRIVATE_RANGES; do + ((16#$addr >> (32 - $#net) == 2#$net)) && return 0 + done +} + +report() { + typeset result='private' addr=$1 state=$2 + ((state)) && result='not private' + printf "%s is %s\n" $addr $result + exit $state +} + +main() { + test_range $1 && report $1 0 + report $1 1 +} + +main $@ From a26569827631da2bed796a6714774b2b30d94749 Mon Sep 17 00:00:00 2001 From: Von Random Date: Fri, 10 Feb 2023 01:05:13 +0200 Subject: [PATCH 07/10] trigger post-receive --- is_private | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/is_private b/is_private index fcf47da..5625119 100755 --- a/is_private +++ b/is_private @@ -24,4 +24,4 @@ main() { report $1 1 } -main $@ +main $1 From 18c36c734085e79a5000cf9bce066820f89aa60b Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 19 Jun 2023 17:56:14 +0300 Subject: [PATCH 08/10] vcascadia-gen: a small script to lock Cascadia otf style sets --- vcascadia-gen.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 vcascadia-gen.sh diff --git a/vcascadia-gen.sh b/vcascadia-gen.sh new file mode 100755 index 0000000..5cb988c --- /dev/null +++ b/vcascadia-gen.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env zsh +### +# https://github.com/microsoft/cascadia-code +# ss01 - handwritten italic +# ss02 - lua not equal ~= - does not work :( +# ss03 - serbian locale +# ss19 - slashed zero 0 +# ss20 - graphical control characters +### + +arch=vcascadia.tgz + +nsrc=CascadiaCodePL.ttf +ndst=normal.ttf +nss=ss19,ss20 + +isrc=CascadiaCodePLItalic.ttf +idst=italic.ttf +iss=ss01,$nss + +rm -fv $arch $ndst $idst + +pip install --upgrade opentype-feature-freezer +pyftfeatfreeze -f $nss -R 'Cascadia Code PL/vcascadia' $nsrc $ndst +pyftfeatfreeze -f $iss -R 'Cascadia Code PL/vcascadia' $isrc $idst + +tar -acvf $arch $ndst $idst From 3f11bead74a2471ad801ed17a24c7b9ff3a52010 Mon Sep 17 00:00:00 2001 From: Von Random Date: Tue, 20 Jun 2023 14:26:34 +0300 Subject: [PATCH 09/10] vcascadia-gen: fix name, use otf instead of ttf --- vcascadia-gen.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/vcascadia-gen.sh b/vcascadia-gen.sh index 5cb988c..a59bc37 100755 --- a/vcascadia-gen.sh +++ b/vcascadia-gen.sh @@ -2,26 +2,24 @@ ### # https://github.com/microsoft/cascadia-code # ss01 - handwritten italic -# ss02 - lua not equal ~= - does not work :( +# ss02 - lua not equals ~= # ss03 - serbian locale # ss19 - slashed zero 0 # ss20 - graphical control characters ### +# opentype-feature-freezer is necessary, install with pipx or pip +# pip install --upgrade opentype-feature-freezer +### -arch=vcascadia.tgz +name=VascadiaMod +arch=$name.tgz +ss=ss01,ss19,ss20 -nsrc=CascadiaCodePL.ttf -ndst=normal.ttf -nss=ss19,ss20 +for font in CascadiaCodePL*.otf; do + src=$font + dst=${font/CascadiaCodePL/$name} -isrc=CascadiaCodePLItalic.ttf -idst=italic.ttf -iss=ss01,$nss + pyftfeatfreeze -f $ss -R "Cascadia Code PL/$name" $src $dst +done -rm -fv $arch $ndst $idst - -pip install --upgrade opentype-feature-freezer -pyftfeatfreeze -f $nss -R 'Cascadia Code PL/vcascadia' $nsrc $ndst -pyftfeatfreeze -f $iss -R 'Cascadia Code PL/vcascadia' $isrc $idst - -tar -acvf $arch $ndst $idst +eval tar -acvf $arch $name* From 8785b81184369e24a82977572dff28285e29a856 Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 26 Jun 2023 17:50:36 +0300 Subject: [PATCH 10/10] truecolortest.awk: use more compatible symbol --- truecolortest.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/truecolortest.awk b/truecolortest.awk index 20b8de0..ce72813 100755 --- a/truecolortest.awk +++ b/truecolortest.awk @@ -2,7 +2,7 @@ # a simple script to test 24 bit compatibility in a terminal # source: https://gist.github.com/XVilka/8346728 BEGIN{ - s="▀▀▀▀▀▀▀▀▀▀"; s=s s s s s s s s; + s="=========="; s=s s s s s s s s; for (colnum = 0; colnum<77; colnum++) { r = 255-(colnum*255/76); g = (colnum*510/76);