Update 2022-12-13 23:16 OpenBSD/amd64

This commit is contained in:
c0dev0id 2022-12-13 23:16:23 +01:00
parent 45c4ea3395
commit 98abe1e416
6 changed files with 152 additions and 223 deletions

View File

@ -20,20 +20,36 @@
#include <locale.h>
static char battery_percent[8];
static char battery_percent[24];
static char cpu_temp[24];
static char fan_speed[24];
static char cpu_base_speed[24];
static char cpu_avg_speed[24];
static char volume[24];
void volume_changed(void *addr, unsigned int vol) {
const wchar_t ico_vol = 0xF028; // 
printf("onvol invoked\n");
snprintf(volume,sizeof(volume), "%lc %2d%%", ico_vol, vol);
}
void update_volume() {
struct sio_hdl *hdl;
hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
sio_onvol(hdl, volume_changed, NULL);
sio_close(hdl);
}
void update_cpu_base_speed() {
const wchar_t ico_freq = 0xE234; // 
int temp;
size_t slen = sizeof(temp);
size_t templen = sizeof(temp);
int mib[5] = { CTL_HW, HW_CPUSPEED }; // Lenovo x1g10
if (sysctl(mib, 2, &temp, &slen, NULL, 0) == -1)
if (sysctl(mib, 2, &temp, &templen, NULL, 0) == -1)
snprintf(cpu_base_speed,sizeof(cpu_base_speed), "%lc N/A", ico_freq);
else
snprintf(cpu_base_speed,sizeof(cpu_base_speed), "%lc %4dMhz", ico_freq, temp);
@ -41,13 +57,13 @@ void update_cpu_base_speed() {
void update_cpu_avg_speed() {
struct sensor sensor;
size_t slen = sizeof(sensor);
size_t templen = sizeof(sensor);
uint temp = 0;
int i;
for (i = 0; i < 12; i++) {
int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_FREQ, 0 }; // Lenovo x1g10
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
if (sysctl(mib, 5, &sensor, &templen, NULL, 0) != -1) {
temp += ( sensor.value / 1000000 / 1000000 );
}
}
@ -56,20 +72,21 @@ void update_cpu_avg_speed() {
void update_fan_speed() {
struct sensor sensor;
size_t slen = sizeof(sensor);
size_t templen = sizeof(sensor);
const wchar_t ico_fan = 0xF70F; // 
int temp = -1;
// int mib[5] = { CTL_HW, HW_SENSORS, 5, SENSOR_FANRPM, 0 }; // Lenovo x230
int mib[5] = { CTL_HW, HW_SENSORS, 12, SENSOR_FANRPM, 0 }; // Lenovo x1g10
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1)
if (sysctl(mib, 5, &sensor, &templen, NULL, 0) != -1)
temp = sensor.value;
snprintf(fan_speed,sizeof(fan_speed), "%lc %dRPM", ico_fan, temp);
}
void update_cpu_temp() {
struct sensor sensor;
size_t slen = sizeof(sensor);
size_t templen = sizeof(sensor);
int temp = -1;
const wchar_t ico_low = 0xF2CB; // 
@ -83,7 +100,7 @@ void update_cpu_temp() {
//int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 }; // cpu0.temp0 (x230)
int mib[5] = { CTL_HW, HW_SENSORS, 12, SENSOR_TEMP, 0 }; // acpitz0.temp0 (x1)
if (sysctl(mib, 5, &sensor, &slen, NULL, 0) != -1) {
if (sysctl(mib, 5, &sensor, &templen, NULL, 0) != -1) {
temp = (sensor.value - 273150000) / 1000000.0;
}
if(temp > 80)
@ -104,7 +121,7 @@ void update_battery() {
int fd;
struct apm_power_info pi;
const wchar_t ico_empty = 0xF583; // 
const wchar_t ico_empty = 0xF58D; // 
const wchar_t ico_10 = 0xF579; // 
const wchar_t ico_20 = 0xF57A; // 
const wchar_t ico_30 = 0xF57B; // 
@ -116,18 +133,12 @@ void update_battery() {
const wchar_t ico_90 = 0xF581; // 
const wchar_t ico_full = 0xF578; // 
const wchar_t ico_chr_empty = 0xF58D; // 
const wchar_t ico_chr_10 = 0xF585; // 
const wchar_t ico_chr_25 = 0xF586; // 
const wchar_t ico_chr_50 = 0xF587; // 
const wchar_t ico_chr_65 = 0xF588; // 
const wchar_t ico_chr_80 = 0xF589; // 
const wchar_t ico_chr_90 = 0xF58A; // 
const wchar_t ico_chr_full = 0xF583; // 
const wchar_t ico_chr = 0xE00A; // 
const wchar_t ico_unknown = 0xF590; // 
wchar_t ico_buf = ico_unknown;
wchar_t ico_chr_buf = 0x20;
if ((fd = open("/dev/apm", O_RDONLY)) == -1 ||
ioctl(fd, APM_IOC_GETPOWER, &pi) == -1 ||
@ -141,49 +152,36 @@ void update_battery() {
strlcpy(battery_percent, "N/A", sizeof(battery_percent));
return;
}
if(pi.ac_state == APM_AC_ON) {
if(pi.battery_life > 97)
ico_buf = ico_chr_full;
else if(pi.battery_life > 90)
ico_buf = ico_chr_90;
else if(pi.battery_life > 80)
ico_buf = ico_chr_80;
else if(pi.battery_life > 65)
ico_buf = ico_chr_65;
else if(pi.battery_life > 50)
ico_buf = ico_chr_50;
else if(pi.battery_life > 25)
ico_buf = ico_chr_25;
else if(pi.battery_life > 10)
ico_buf = ico_chr_10;
else
ico_buf = ico_chr_empty;
} else {
if(pi.battery_life > 98)
ico_buf = ico_full;
else if(pi.battery_life > 90)
ico_buf = ico_90;
else if(pi.battery_life > 80)
ico_buf = ico_80;
else if(pi.battery_life > 70)
ico_buf = ico_70;
else if(pi.battery_life > 60)
ico_buf = ico_60;
else if(pi.battery_life > 50)
ico_buf = ico_50;
else if(pi.battery_life > 40)
ico_buf = ico_40;
else if(pi.battery_life > 30)
ico_buf = ico_30;
else if(pi.battery_life > 20)
ico_buf = ico_20;
else if(pi.battery_life > 10)
ico_buf = ico_10;
else
ico_buf = ico_empty;
}
if(pi.ac_state == APM_AC_ON)
ico_chr_buf = ico_chr;
else
ico_chr_buf = 0x20;
if(pi.battery_life > 94)
ico_buf = ico_full;
else if(pi.battery_life > 90)
ico_buf = ico_90;
else if(pi.battery_life > 80)
ico_buf = ico_80;
else if(pi.battery_life > 70)
ico_buf = ico_70;
else if(pi.battery_life > 60)
ico_buf = ico_60;
else if(pi.battery_life > 50)
ico_buf = ico_50;
else if(pi.battery_life > 40)
ico_buf = ico_40;
else if(pi.battery_life > 30)
ico_buf = ico_30;
else if(pi.battery_life > 20)
ico_buf = ico_20;
else if(pi.battery_life > 10)
ico_buf = ico_10;
else
ico_buf = ico_empty;
snprintf(battery_percent,sizeof(battery_percent),
"%lc %d%%", ico_buf, pi.battery_life);
"%lc%lc %d%%", ico_chr_buf, ico_buf, pi.battery_life);
}
int main(int argc, const char *argv[])
@ -194,6 +192,9 @@ int main(int argc, const char *argv[])
const wchar_t sep = 0xE621; // 
const wchar_t time = 0xE383; // 
// registers a callback and updates the volume on change
update_volume();
while(1) {
update_battery();
@ -210,6 +211,8 @@ int main(int argc, const char *argv[])
printf(" %lc ", sep);
printf("%s", fan_speed);
printf(" %lc ", sep);
printf("%s", volume);
printf(" %lc ", sep);
printf("%lc ", time);
printf("\n");

View File

@ -12,7 +12,7 @@ find "${DEVDIR}" /usr/include /usr/local/include -type f \
\( -name "*.c" \
-o -name "*.cc" \
-o -name "*.cpp" \
-o -name "*.c" \
-o -name "*.h" \
-o -name "*.hh" \
-o -name "*.hpp" \
\) > /home/sdk/.dev/files

View File

@ -103,14 +103,14 @@ local clear_data = require "clear_data"
local undoclose = require "undoclose"
-- Add command to list tab history items
local tabhistory = require "tabhistory"
-- local tabhistory = require "tabhistory"
-- Add greasemonkey-like javascript userscript support
local userscripts = require "userscripts"
-- local userscripts = require "userscripts"
-- Add bookmarks support
local bookmarks = require "bookmarks"
local bookmarks_chrome = require "bookmarks_chrome"
-- local bookmarks = require "bookmarks"
-- local bookmarks_chrome = require "bookmarks_chrome"
-- Add download support
local downloads = require "downloads"
@ -145,9 +145,9 @@ local completion = require "completion"
-- Press Control-E while in insert mode to edit the contents of the currently
-- focused <textarea> or <input> element, using `xdg-open`
local open_editor = require "open_editor"
local editor = require "editor"
editor.editor_cmd = "hterm vim {file}"
-- local open_editor = require "open_editor"
-- local editor = require "editor"
-- editor.editor_cmd = "hterm vim {file}"
-- NoScript plugin, toggle scripts and or plugins on a per-domain basis.
-- `,ts` to toggle scripts, `,tp` to toggle plugins, `,tr` to reset.
@ -161,7 +161,7 @@ local go_next_prev = require "go_next_prev"
local go_up = require "go_up"
-- Filter Referer HTTP header if page domain does not match Referer domain
require_web_module("referer_control_wm")
-- require_web_module("referer_control_wm")
local error_page = require "error_page"
@ -184,7 +184,7 @@ follow.stylesheet = follow.stylesheet .. [===[
-- local vertical_tabs = require "vertical_tabs"
-- Add a stylesheet when showing images
local image_css = require "image_css"
-- local image_css = require "image_css"
-- Add a new tab page
local newtab_chrome = require "newtab_chrome"

View File

@ -42,6 +42,9 @@ bind[sterm] = MOD+Return
program[bterm] = bterm
bind[bterm] = MOD+Shift+Return
program[devterm] = texec dev-src
bind[devterm] = MOD+Shift+D
program[exec] = dexec
bind[exec] = MOD+D

227
.kshrc
View File

@ -158,14 +158,11 @@ alias mupdf="mupdf-gl -XJ"
# network
alias edit_dns="ssh -t dns.codevoid.de \"doas vim /var/nsd/zones/master/codevoid.de && doas nsd-control reload\""
alias edit_gopher="vim sftp://gopher.codevoid.de/../www/htdocs/gopher/"
alias ts="doas tailscale"
ts-vpn() { doas tailscale up --exit-node=100.89.60.42; }
x() { ssh -t home.codevoid.de 'tmux -u attach || tmux -u'; }
t() { ssh -t tweety.home.codevoid.de 'tmux -u attach || tmux -u'; }
b() { ssh -t barton.oldbsd.de 'tmux -u attach || tmux -u'; }
netrestart() {(
set -x
doas ifconfig trunk0 destroy
@ -187,23 +184,7 @@ pass-reinit() {
}
cg() {
test -z "${1}" \
&& echo "usage: cg <ChatNet>" \
&& return
case ${1} in
b*) _net=Bitreich; ;;
c*) _net=CuffLink; ;;
e*) _net=EfNet; ;;
h*) _net=HackInt; ;;
i*) _net=IRCNet; ;;
l*) _net=LiberaChat; ;;
o*) _net=OFTC; ;;
r*) _net=RobustIRC; ;;
u*) _net=UUGRN; ;;
*) _net=${1}; ;;
esac
[ -z "$1" ] && return 2
catgirl \
-C copy \
-N notify-send \
@ -216,7 +197,7 @@ cg() {
-r x \
-u sdk \
-n sdk \
-w "sdk@$(hostname -s)/${_net}:$(pass Internet/znc)"
-w "sdk@$(hostname -s)/${1}:$(pass Internet/znc)"
}
# mount
@ -287,28 +268,19 @@ alias discord-me="firefox https://discord.com/channels/@me"
alias discord-immortals="firefox https://discord.com/channels/991041843871502366/1000826654974812160"
alias cups-config="firefox http://localhost:631"
# monitoring
lr() {
[ -z "$1" ] \
&& print "l-remote <hostname>" && return
if [ -z "$2" ]; then
_xtitle "$1: /var/log/messages (all)";
ssh -t "$1" "doas tail -f /var/log/{messages,daemon,secure,maillog}"
else
_xtitle "$1: /var/log/messages (grep $2)";
ssh -t "$1" "doas tail -f /var/log/{messages,daemon,secure,maillog} | fgrep -i $2"
fi
[ -z "$1" ] && return 2
[ -z "$2" ] \
&& ssh -t "$1" -- doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
|| ssh -t "$1" -- doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
| fgrep -i "$2"
}
l() {
if [ -z "$1" ];
then
_xtitle "/var/log/messages (all)";
doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog}
else
_xtitle "/var/log/messages (grep: $1)";
doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} | fgrep -i "$1"
fi
[ -z "$1" ] \
&& doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
|| doas tail -n 4000 -f /var/log/{messages,daemon,secure,maillog} \
| fgrep -i "$1"
}
@ -368,116 +340,54 @@ alias omisc="mutt -f $MUTT_HOST/Virtual/OpenBSD-misc"
# OPENBSD PORT TOOLS
########################################################################
CVSDIR=/usr
CVSROOT=sdk@cvs.openbsd.org:/cvs
alias cvs-diff="cvs -d $CVSROOT diff -uNp"
alias cvs-release="cvs -d $CVSROOT release"
alias cvs-commit="doas cvs -d $CVSROOT commit"
alias cvs-update="doas cvs -z 1 -d $CVSROOT -q up -Pd -A"
alias cvs-release="cvs -d $CVSROOT release"
alias cvs-checkout="doas cvs -z 1 -qd $CVSROOT checkout -P"
cvs-import-simulate() {(
set -ex
cvs-import-simulate() {
cvs -d sdk@cvs.openbsd.org:/cvs -n import \
ports/$(dirname $PWD)/$(basename $PWD) sdk sdk_$(date +"%Y%m%d")
)}
cvs-checkout-ports() {( set -x; cd $CVSDIR && doas cvs -z 1 -qd $CVSROOT checkout -P ports; )}
cvs-checkout-src() {( set -x; cd $CVSDIR && doas cvs -z 1 -qd $CVSROOT checkout -P src; )}
cvs-checkout-www() {( set -x; cd $CVSDIR && doas cvs -z 1 -qd $CVSROOT checkout -P www; )}
cvs-checkout-xenocara() {( set -x; cd $CVSDIR && doas cvs -z 1 -qd $CVSROOT checkout -P xenocara; )}
cvs-update-ports() {( set -x; cd $CVSDIR/ports && doas cvs -z 1 -d $CVSROOT -q up -Pd -A;)}
cvs-update-src() {( set -x; cd $CVSDIR/src && doas cvs -z 1 -d $CVSROOT -q up -Pd -A;)}
cvs-update-www() {( set -x; cd $CVSDIR/www && doas cvs -z 1 -d $CVSROOT -q up -Pd -A;)}
cvs-update-xenocara() {( set -x; cd $CVSDIR/xenocara && doas cvs -z 1 -d $CVSROOT -q up -Pd -A;)}
cvs-commit() {( set -x; doas cvs -d $CVSROOT commit $@; )}
cvs-checkout-all() {
cvs-checkout-src
cvs-checkout-xenocara
cvs-checkout-ports
cvs-checkout-www
}
cvs-update-all() {
cvs-update-src
cvs-update-xenocara
cvs-update-ports
cvs-update-www
}
pmark() { echo "$PWD" | tee /var/cache/pmark; }
p() { cd "$(</var/cache/pmark)" && echo $PWD; }
pj() { cd "$(port jump $1)" && echo $PWD; }
po() { cd "$(</var/cache/pmark)" && cd "$(make show=WRKSRC)"; }
alias portsweep='doas find . \( -name "*.orig" -or -empty \) -delete'
pdiff() {(
_name="$(make show=PKGNAME)"
_epoch="$(make show=EPOCH)"
_rev="$(make show=REVISION)"
_patchname="${_name}${_epoch:+v$_epoch}${_rev:+p$_rev}"
_portdir="$(echo "$PWD" | awk -F'/' '{ print $(NF-1)"/"$NF; }')"
cd ../../
doas cvs -d sdk@cvs.openbsd.org:/cvs diff -uNp "$_portdir" \
> "/home/sdk/diffs/${_patchname}.diff"
echo "/home/sdk/diffs/${_patchname}.diff"
)}
alias port-modgo-update='make MODGO_VERSION=latest modgo-gen-modules > modules.inc'
alias proot-rebuild="doas proot -c /etc/proot.conf; doas chroot /home/dpb pkg_add ccache"
alias proot-do="doas chroot /home/dpb/"
alias dmake="doas /usr/ports/infrastructure/bin/dpb -B /home/dpb -c -p 4 -j 4"
########################################################################
# KERNEL STUFF
########################################################################
alias update-ksh="cd /usr/src/bin/ksh \
&& doas make clean \
&& doas make obj \
&& doas make \
&& doas make install"
alias pmark="port mark"
p() { cd "$(port src)" && echo $PWD; }
pj() { cd "$(port jump $1)" && echo $PWD; }
po() { cd "$(port obj)" && echo $PWD; }
alias portclean="port clean"
alias portsweep='doas find . \( -name "*.orig" -or -empty \) -delete'
alias portdiff="port diff"
alias port-modgo-update='make MODGO_VERSION=latest modgo-gen-modules > modules.inc'
alias proot-rebuild="doas proot -c /etc/proot.conf; doas chroot /home/dpb pkg_add ccache"
alias proot-do="doas chroot /home/dpb/"
alias dmake="doas /usr/ports/infrastructure/bin/dpb -B /home/dpb -c -p 4 -j 4"
dev-dir() {
cd "$(cat /home/sdk/.dev/dir)";
}
dlast() {
doas -u build vim -c ':browse oldfiles'
}
dvim() {
doas -u build vim
}
ddiff() {(
cd /usr/src
f="$(cat /var/cache/dmark | sed 's|/usr/src/||g')"
cvs-diff "$f" | tee "/home/sdk/$(basename "$f").diff"
readlink -f "/home/sdk/$(basename "$f").diff"
)}
dgrepsys() {
ugrep --exclude-dir="CVS" \
--include="*.h" \
--include="*.c" \
--include="*.txt" \
--include="*.pl" \
--include="*.pm" \
--include="*.sh" \
--recursive \
"$1" \
/usr/src/sys/
}
dgrep() {
ugrep --exclude-dir="CVS" \
--include="*.h" \
--include="*.c" \
--include="*.txt" \
--include="*.pl" \
--include="*.pm" \
--include="*.sh" \
--recursive \
"$1" \
/usr/src/
}
pack() {
doas tar czvf "$1.tgz" "$1" \
&& readlink -f "$1.tgz"
}
########################################################################
# TWITCH FROM CLI
########################################################################
@ -487,10 +397,7 @@ twitch-stream() {
local API_KEY=$(pass Internet/Twitch | head -1)
local RES=$(xrandr | grep "*+" | awk '{print $1}')
local FAUX_OPTS="-d snd/default -m -vmic 5.0 -vmon 0.2 -r $RES -f 20 -b 4000"
(
set -x
fauxstream $FAUX_OPTS rtmp://live-ams.twitch.tv/app/$API_KEY
)
fauxstream $FAUX_OPTS rtmp://live-ams.twitch.tv/app/$API_KEY
}
########################################################################
@ -516,21 +423,36 @@ dotfiles_init() {
# FILE SHARING
########################################################################
dohttp_upload() {
local _file=$(readlink -f "$1");
local _name=$(cleanstring "$1");
scp -r "$_file" codevoid.de:/home/www/htdocs/http/$_name
ssh -t codevoid.de doas chown -R sdk:www "/home/www/htdocs/http/$_name"
printf "https://codevoid.de/h/$_name\n";
doupload-http() {
[ ! -f "$1" ] && return 2
chmod ugo+r "$1"
_name=$(basename "$1");
scp -r "$1" codevoid.de:/tmp
ssh codevoid.de "doas mv /tmp/$_name /home/www/htdocs/http/$_name"
echo "https://codevoid.de/h/$_name";
}
cleanstring() {
printf '%s' "$1" | tr "[:upper:]ÄÖÜ " "[:lower:]äöü_" \
| sed 's/ä/ae/g;s/ö/oe/g;s/ü/ue/g;s/ß/ss/g';
doupload-gopher() {
[ ! -f "$1" ] && return 2
chmod ugo+r "$1"
_name=$(basename "$1");
scp -r "$1" codevoid.de:/tmp
ssh codevoid.de "doas mv /tmp/$_name /home/www/htdocs/gopher/p/$_name"
case "$(file --mime-type -b "$1")" in
image/*) S="I";;
text/*) S="0";;
message/*) S="0";;
*/x-shellscript) S="0";;
*/pgp-keys) S="0";;
application/*) S="9";;
esac
echo "https://codevoid.de/$S/p/$_name";
echo "gopher://codevoid.de/$S/p/$_name";
}
########################################################################
# YOUTUBE-DL
########################################################################
YTDL_AGENT="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4506.0 Safari/537.36"
YTDL_OPTS="-i --no-part --abort-on-unavailable-fragment --buffer-size 16K --fragment-retries 100 --http-chunk-size 10M"
ytdl() {
@ -576,12 +498,11 @@ xr_secondary() {
xr_off() {
xrandr | awk '/disconnected/ { print $1 }'
}
alias xrandr_portrait="sync; xrandr --output DP-1 --rotate left"
xrandr_set() {
set -xe
for scr in $(xr_secondary)
do
xrandr --output $scr --$1 $(xr_primary) --mode 1920x1080
xrandr --output $scr --$1 $(xr_primary) --mode auto
done
for scr in $(xr_off)
do
@ -613,11 +534,13 @@ xrandr_4k() {
xrandr --output $(xr_primary) --mode 3840x2160
}
alias xrandr_portrait="sync; xrandr --output DP-1 --rotate left"
########################################################################
# GNUPG AGENT
########################################################################
if [ -f $HOME/.gnupg/pubring.gpg ];
if [ -f $HOME/.enable_gpg ];
then
GPG_TTY=$(tty)
SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)

View File

@ -227,7 +227,7 @@ function MyMake()
if filereadable("Makefile")
:w! | !make
else
:w! | !cc -o %:p:r %:p
:w! | !cc -o %:p:r -lsndio %:p
endif
endfunction