c0dev0id gopher phlog about computer stuff (programming, openbsd and more) gopher://codevoid.de Memory management, virtual and residential memory gopher://codevoid.de/1/posts/2021-09-26-memory-management.gph gopher://codevoid.de/1/posts/2021-09-26-memory-management.gph 2021-09-26T00:00:00Z C0dev0id used. Note 2: Stack memory will also show up as residential when used. Unused stack memory will *not* show up as virtual memory. Note 3: Residential memory includes shared memory as well. If you see 10 chrome processes which are consuming 300MB of residential memory each, this does *not* mean that chrome as a whole is using 3000MB. TODO: Find out how the shared memory part of RES can be seen on OpenBSD. (Linux has SHR in top) Changelog: * 2021-09-26: Created * 2021-09-26: + segfault example * 2021-11-01: s/1G/2G/g in the paragraph below malloc() # * 2022-06-28: ]]> GnuPG Quickstart gopher://codevoid.de/1/posts/2021-05-19-gnupg-quickstart.gph gopher://codevoid.de/1/posts/2021-05-19-gnupg-quickstart.gph 2021-05-19T00:00:00Z C0dev0id sub rsa3072 2021-05-19 [E] [expires: 2023-05-19] If you see an error like: gpg: agent_genkey failed: Permission denied Add the following entry and try again. $ cat ~/.gnupg/gpg-agent.conf allow-loopback-pinentry Congratulations, you got yourself a GPG Key. This long gibberish is your full GPG Key ID. Most of the time, you can simply use the last 8 characters. So the short version of this GPG Key is DBECC2C1. You can set it as default key, so it's used to encrypt stuff when no explicit key is given. $ cat ~/.gnupg/gpg.conf default-key DBECC2C1 # Share the key with your people If you want someone to be able to encrypt something for you, send him or her the output of: $ gpg --export -a DBECC2C1 You can also use your email address instead of the Key ID, if you have only one key with it. This key is public. So put it on some webspace and add a link to your email header or signature. # Upload the key so people can find it You can also upload your key to a key server. For this, configure a keyserver: $ cat ~/.gnupg/gpg.conf keyserver hkp://ha.pool.sks-keyservers.net Then send your key to it: $ gpg --send-keys DBECC2C1 # You got a key from someone Add a key from someone else to gnupg, so you can use it to encrypt data for this person. If the key is on your harddrive, use: $ gpg --import The file ending here is kind of undefined. Some call it .asc, .gpg, .pub or .key. If the key is on a key server, you can import it like so: $ gpg --recv-key 52BE43BA This would import my key. You can look at it now with: $ gpg --list-keys 52BE43BA # Encrypt a file This encrypts the file plain.txt with the public key DBECC2C1. $ gpg --encrypt -r DBECC2C1 file.txt Now you have file.txt.gpg, which is the encrypted version # Decrypt a file GnuPG automaticall figures out what key it can use to decrypt a file. So tthis will output the content of file.txt on the terminal. If you want tto save the output in a file, add -o file.txt. $ gpg -d file.txt.gpg $ gpg -d file.txt.gpg -o file.txt Choose a better password prompt =============================== You can change the way gpg asks for the password: $ cat ~/.gnupg/gpg-agent.conf pinentry-program /usr/local/bin/pinentry-curses Options are: - pinentry (sometimes also called pinentry-tty) - pinentry-curses - pinentry-gtk2: pkg_add pinentry-gtk2 - pinentry-gnome3: pkg_add pinentry-gnome3 - pinentry-dmenu: gopher://github.com/ritze/pinentry-dmenu ! Note: If you use a console pinentry program and want to use gpg with a ! ! GUI tool (like thunderbird), the password prompt will be invisible and ! ! gpg/thunderbird will freeze. " Makes sense, doesn't it? Start GPG Agent for password caching ==================================== Put this in your .kshrc or .bashrc: $ cat ~/.kshrc export GPG_TTY=$(tty) gpg-connect-agent /bye Make a Backup ============= There is no handholding cloud or support team you can call when you messed up or deleted your key. So back it up safely. Either you backup your ~/.gnugp directory, or you export the secret keys and backup them safely. $ gpg --export-secret-keys -a DBECC2C1 > gpg_key_backup.sec Seriously, don't skip this step. Configure Mutt ============== Install mutt with the gpgme flavor. Gpgme is the "new way" of handling gpg in mutt. $ pkg_add mutt--gpgme If you're not on OpenBSD, check with `mutt -v` if it was compiled with tthe --enable-gpgme option. Then enable it in mutt. $ cat ~/.muttrc crypt_use_gpgme = yes In the mutt compose view, you can now select Security Options. From: C0dev0id To: j.doe@example.com Cc: Bcc: Subject: Hello my friend Reply-To: Fcc: =Sent Security: Sign, Encrypt (PGP/MIME) Sign as: You can change the setting with the key "p", which should bring up a selection menu. PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, s/(m)ime or (c)lear? Changelog: * 2021-05-17: Created * 2022-06-28: Gemini compatible styling :/ ]]> Linux Presentation Day 2021 (DE) gopher://codevoid.de/1/posts/2021-05-05-linux-presentation-day-2021.gph gopher://codevoid.de/1/posts/2021-05-05-linux-presentation-day-2021.gph 2021-05-05T00:00:00Z C0dev0id DeltaChat - an e-mail based OSS messenger gopher://codevoid.de/1/posts/2021-01-12-deltachat.gph gopher://codevoid.de/1/posts/2021-01-12-deltachat.gph 2021-01-12T00:00:00Z C0dev0id Port Submission Checklist gopher://codevoid.de/1/posts/2021-01-10-port-submission-checklist.gph gopher://codevoid.de/1/posts/2021-01-10-port-submission-checklist.gph 2021-01-10T00:00:00Z C0dev0id Mutt inline patch handling gopher://codevoid.de/1/posts/2021-01-09-mutt-inline-patch-macro.gph gopher://codevoid.de/1/posts/2021-01-09-mutt-inline-patch-macro.gph 2021-01-09T00:00:00Z C0dev0id rm -f /tmp/mutt-patch.diff /tmp/mutt-patch.diff echo 'Saved as /tmp/mutt-patch.diff' ~/.mutt/scripts/portpatch.sh /tmp/mutt-patch.diff" The portpatch.sh script: #!/bin/sh printf '\n-------------------------------------------------------\n' cat "$1" | egrep ^Index\|^RCS\|--git printf '-------------------------------------------------------\n\n' printf "Path for patch [/usr/ports]? " read _path [ -z "$_path" ] && _path=/usr/ports doas patch -p0 -d $_path < "$1" cd $_path && ksh The script shows some relvant bits from the email patch that are handy tto determine on which path the patch shall be applied. Next it alles the user to enter a different path. I most use /usr/ports, so this is the default. Then the patch is applied and a ksh shell is opened for further work. Quitting the shell brings me back to mutt to work on the next email. This is quite friggin handy. # Changelog: # * 2021-01-09: Created ]]> OpenBSD How to use a webcam gopher://codevoid.de/1/posts/2020-11-15-openbsd-video-faq.gph gopher://codevoid.de/1/posts/2020-11-15-openbsd-video-faq.gph 2020-11-15T00:00:00Z C0dev0id > /etc/sysctl.conf +----------------------------------------------------------------------+ | | | Supported Hardware | | | +----------------------------------------------------------------------+ Most webcams today implement the USB Video Class (UVC) specification, which is supported by the uvideo(4) device driver and attaches to the video(4) device. The manpage lists some supported devices, but there is a good chance that other devices work as well. For example, webcams in Lenovo Thinkpad laptops do usually work. A supported webcam (or other video device) shows up in dmesg like this: uvideo0 at uhub0 port 8 configuration 1 interface 0 "Azurewave \ Integrated Camera" rev 2.01/69.05 addr 10 video0 at uvideo0 uvideo1 at uhub0 port 8 configuration 1 interface 2 "Azurewave \ Integrated Camera" rev 2.01/69.05 addr 10 video1 at uvideo1 You see that an uvideo device was detected and has been attached to video0. This device will be accessible through /dev/video0. Modern laptops sometimes attach a second video device, which is the infrared camera for face recognition. The second camera does not produce a usable video stream. You can find the usable camera with the video(1) command: $ video -q -f /dev/video0 video device /dev/video0: encodings: yuy2 frame sizes (width x height, in pixels) and rates (in frames per second): 320x180: 30 320x240: 30 352x288: 30 424x240: 30 640x360: 30 640x480: 30 848x480: 20 960x540: 15 1280x720: 10 controls: brightness, contrast, saturation, hue, gamma, sharpness, white_balance_temperature $ video -q -f /dev/video1 video: /dev/video1 has no usable YUV encodings The usable camera device shows supported resolutions and frameratei. Note that the framerates only apply to the uncompressed YUY2 stream. More on that in "Recording a webcam stream" +----------------------------------------------------------------------+ | | | Using a webcam as user | | | +----------------------------------------------------------------------+ To use the webcam as regular user, you need to change the device permissions. Only root is allowed to access video devices by default. One way of allowing your user to access the video devices is to change the permissions from ~/.xsession. You can configure doas(1) to perform chmod(1) as superuser without asking for a password for your user. $ doas chown $USER /dev/video0 +----------------------------------------------------------------------+ | | | Recoding a webcam stream | | | +----------------------------------------------------------------------+ This section uses ffplay and ffmpeg from graphics/ffmpeg. To find out what your camera is capable of, run the following command: $ ffplay -f v4l2 -list_formats all -i /dev/video0 [...] [video4linux2,v4l2 @ 0x921f8420800] Raw : yuyv422 : YUYV : 640x480 \ 320x180 320x240 352x288 424x240 640x360 848x480 960x540 1280x720 [video4linux2,v4l2 @ 0x921f8420800] Compressed: mjpeg : MJPEG : \ 1280x720 320x180 320x240 352x288 424x240 640x360 640x480 848x480 At the end of the output, you'll find two lines similiar to the two above. The first line shows resolutions supported in the uncompressed YUYV format. The frame rates in this format can be very low. The second line shows the supported MJPEG compressed video resolutions, which deliver much higher framerates (usually 30fps or 60fps). Now try to play the webcam stream. Choose one of the MJPEG resolutions and run: $ ffplay -f v4l2 -input_format mjpeg -video_size 1280x720 -i /dev/video0 [...] Input #0, video4linux2,v4l2, from '/dev/video0':B sq= 0B f=0/0 Duration: N/A, start: 1599377893.546533, bitrate: N/A Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown\ /unknown), 1280x720, 30 fps, 30 tbr, 1000k tbn, 1000k tbc The webcam stream should be displayed. Ffplay also shows the used resolution and the framerate (fps) used. If this works, you can go ahead and record the video with ffmpeg: $ ffmpeg -f v4l2 -input_format mjpeg -video_size 1280x720 \ -i /dev/video0 ~/video.mkv +----------------------------------------------------------------------+ | | | Controlling webcam settings | | | +----------------------------------------------------------------------+ Webcams usually have brightness, contrast and other controls. Video(1) allows you to alter these settings. First find out which supported controls your camera has: $ video -c brightness=128 contrast=32 saturation=64 hue=0 gamma=120 sharpness=3 white_balance_temperature=auto You can change for example the brightness setting to 200: $ video brightness=200 brightness: 128 -> 200 If you would like to reset all settings to their defaults, you can do so with: $ video -d $ video -c brightness=128 contrast=32 saturation=64 hue=0 gamma=120 sharpness=3 white_balance_temperature=auto Some settings, like the white_balance_temperature support automatic adjustments. You can set them to a fixed value or set them to "auto", which lets the camera decide and use whatever value it thinks is best. +----------------------------------------------------------------------+ | | | Access webcam in chromium | | | +----------------------------------------------------------------------+ Chromium has access to /dev/video and /dev/video0 by default. To allow Chromium to access other video devices, you need to add the device paths tto /etc/chromium/unveil.main and /etc/chromium/unveil.utility_video +----------------------------------------------------------------------+ | | | Access webcam in firefox | | | +----------------------------------------------------------------------+ Firefox has access to /dev/video and /dev/video0 by default. To allow Firefox to access other video devices, you need to add the device paths to /etc/firefox/unveil.main. # Changelog: # * 2020-11-15: Created # * 2021-01-04: Changed styling # * 2021-07-21: Corrected browser headings ]]> OpenBSD FDE Setup gopher://codevoid.de/1/posts/2020-11-14-openbsd-fde.gph gopher://codevoid.de/1/posts/2020-11-14-openbsd-fde.gph 2020-11-14T00:00:00Z C0dev0id OpenBSD Desktop GPU recommendation gopher://codevoid.de/1/posts/2020-07-12-openbsd-desktop-gpu.gph gopher://codevoid.de/1/posts/2020-07-12-openbsd-desktop-gpu.gph 2020-07-12T00:00:00Z C0dev0id Browser Dark Mode (Chrome and Firefox) gopher://codevoid.de/1/posts/2020-05-17-browser-dark-mode.gph gopher://codevoid.de/1/posts/2020-05-17-browser-dark-mode.gph 2020-05-17T00:00:00Z C0dev0id > $HOME/.config/vimb/config # Changelog: # * 2020-05-17: Created # * 2020-12-04: Added vimb ]]> Build OpenBSD Kernel gopher://codevoid.de/1/posts/2019-10-24-build-openbsd-kernel.gph gopher://codevoid.de/1/posts/2019-10-24-build-openbsd-kernel.gph 2019-10-24T00:00:00Z C0dev0id LineageOS on Motorola Z2 Force gopher://codevoid.de/1/posts/2019-10-17-LineageOS-on-Motorola-Z2-Force.gph gopher://codevoid.de/1/posts/2019-10-17-LineageOS-on-Motorola-Z2-Force.gph 2019-10-17T00:00:00Z C0dev0id Boot into bootloader (power+down) - $ fastboot flash boot_a .img - $ fastboot flash boot_b .img - > Boot into bootloader (power+down) -> Boot Recovery - > Factory Reset -> Wipe data / factory reset + Wipe System - > Apply update -> adb sideload - $ adb sideload .zip - $ adb sideload .zip - > Reboot $ == commandline activity > == phone activity Notes: * "adb devices" works without USB drivers * "fastboot devices" shows nothing if USB drivers are not installed * This phone has two boot areas and therefore "fastboot flash boot" will fail. The areas "boot_a" and "boot_b" must be used instead. If "boot_a" and "boot_b" are flashed differently, booting will fail. # Changelog: # * 2019-10-17: Created # * 2019-10-17: Added activity indicator and "Prepare" # * 2019-10-17: Clarify boot_a, boot_b situation ]]> Manage dotfiles with git gopher://codevoid.de/1/posts/2019-04-27-manage-dotfiles-with-git.gph gopher://codevoid.de/1/posts/2019-04-27-manage-dotfiles-with-git.gph 2019-04-27T00:00:00Z C0dev0id ~/.ssh/config $ } With this I run "sshconfig", update my file, save, done. of course I added only config.gpg to my git. On a new system I have to run sshconfig once to create the config file. 2. Stuff outside $HOME I wanted to add a few files that reside in /etc. Here I took the lazy route and created $HOME/.etc and copied the files there. On a new machine I have the files, but need to copy them manually. Works fine for me. 3. Host specific files I try to keep my dotfiles compatible to all computers I use. But sometimes this is not possible and there are a few methods to battle this. If your configuration allows code evaluation, you may do something like ". myconfig.$(hostname -s)" and just check in individual files per host. If this does not work or you have a file that needs to have a password in it, you could copy the file, remove the password and check it in as template or sample file. The methods above served me very well over the past years and I'm not seeing why I would want to change it. It's easy and simple and I don't need to remember anything beside a few git commands. Well okay, because I'm lazy and don't want to think about git commit messages, I'm using this to push my changes: $ dotfiles_autoupdate() { $ MSG="Update $(date +"%Y-%m-%d %H:%M") $(uname -s)/$(uname -m)" $ config add -u && \ $ config commit -m "$MSG" && \ $ config push $ } This command takes all changed files and commits them with the date and some machine information. Not creative, but I don't care. YMMV. # Changelog: # * 2019-04-27: Created # * 2019-04-28: Added password evaluation examples # * 2020-05-17: Added password-store and sshconfig examples ]]>