From 847b847c79321993e9ba47c84d74e9ce68ded25b Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Tue, 25 Jul 2023 02:11:50 +0800 Subject: [PATCH] Iron out gpg and gpg-agent config, among other things Also in this commit: * Added handle-pinentry wrapper script to exec right pinentry based on environment. * Add VS Code config for stuff like GitLens settings and recommended extensions. Signed-off-by: Andrei Jiroh Halili --- .config/htop/htoprc | 44 ++++++++------------------------- .gnupg/gnupg.conf | 12 +++++++++ .gnupg/gpg-agent.conf | 12 +++++++++ .vscode/extensions.json | 5 ++++ .vscode/settings.json | 17 +++++++++++++ bin/handle-pinentry | 54 +++++++++++++++++++++++++++++++++++++++++ bin/setup-chroot | 5 +++- 7 files changed, 114 insertions(+), 35 deletions(-) create mode 100644 .gnupg/gpg-agent.conf create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 bin/handle-pinentry diff --git a/.config/htop/htoprc b/.config/htop/htoprc index 84b56cb..cd2465f 100644 --- a/.config/htop/htoprc +++ b/.config/htop/htoprc @@ -1,15 +1,16 @@ # Beware! This file is rewritten by htop when settings are changed in the interface. # The parser is also very primitive, and not human-friendly. -htop_version=3.2.1 -config_reader_min_version=3 fields=0 48 17 18 38 39 40 2 46 47 49 1 +sort_key=46 +sort_direction=-1 +tree_sort_key=47 +tree_sort_direction=-1 hide_kernel_threads=1 hide_userland_threads=0 shadow_other_users=1 show_thread_names=0 show_program_path=1 highlight_base_name=1 -highlight_deleted_exe=1 highlight_megabytes=1 highlight_threads=1 highlight_changes=0 @@ -17,8 +18,9 @@ highlight_changes_delay_secs=5 find_comm_in_cmdline=1 strip_exe_from_cmdline=1 show_merged_command=1 +tree_view=1 +tree_view_always_by_pid=0 header_margin=1 -screen_tabs=1 detailed_cpu_time=1 cpu_count_from_one=1 show_cpu_usage=1 @@ -30,34 +32,8 @@ account_guest_in_cpu_meter=1 color_scheme=0 enable_mouse=1 delay=5 +left_meters=AllCPUs Memory Swap +left_meter_modes=1 1 1 +right_meters=Tasks LoadAverage Uptime +right_meter_modes=2 2 2 hide_function_bar=0 -header_layout=three_25_25_50 -column_meters_0=CPU Memory Swap ZFSARC ZFSCARC -column_meter_modes_0=1 1 1 2 2 -column_meters_1=DiskIO NetworkIO LoadAverage Tasks Battery -column_meter_modes_1=1 1 1 1 1 -column_meters_2=PressureStallIOFull PressureStallMemoryFull Hostname DateTime Uptime -column_meter_modes_2=1 1 2 2 2 -tree_view=1 -sort_key=46 -tree_sort_key=47 -sort_direction=-1 -tree_sort_direction=1 -tree_view_always_by_pid=0 -all_branches_collapsed=0 -screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command -.sort_key=PERCENT_CPU -.tree_sort_key=PERCENT_MEM -.tree_view=1 -.tree_view_always_by_pid=0 -.sort_direction=-1 -.tree_sort_direction=1 -.all_branches_collapsed=0 -screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE -.sort_key=IO_RATE -.tree_sort_key=PID -.tree_view=0 -.tree_view_always_by_pid=0 -.sort_direction=-1 -.tree_sort_direction=1 -.all_branches_collapsed=0 diff --git a/.gnupg/gnupg.conf b/.gnupg/gnupg.conf index c2116ce..8e682a8 100644 --- a/.gnupg/gnupg.conf +++ b/.gnupg/gnupg.conf @@ -1,5 +1,17 @@ +# Documentation is available online at https://www.gnupg.org/documentation/manuals/gnupg/GPG-Configuration-Options.html#gpg_002doption-_002d_002doptions + +# Make sure to use my new PGP key instead of the old one. +# TODO: Schedule key expiration for the old one soonish. default-key 4D5E631758CB9CC45941B1CE67BFC91B3DA12BE8 + # Go abit like Keybase, but keep the WoT parts. trust-model tofu+pgp + # use keys.openpgp.org instead of keyserver.ubuntu.com or whatever keyserver hkps://keys.openpgp.org + +# long fpr + 0x prefix +keyid-format 0xlong + +# From the docs: This is dummy option. gpg always requires the agent. +#use-agent diff --git a/.gnupg/gpg-agent.conf b/.gnupg/gpg-agent.conf new file mode 100644 index 0000000..eb71eb3 --- /dev/null +++ b/.gnupg/gpg-agent.conf @@ -0,0 +1,12 @@ +# Cache passphrases for 15m by default up to 3 hours. +default-cache-ttl 900 +max-cache-ttl 10800 +default-cache-ttl-ssh 900 +max-cache-ttl-ssh 10800 + +# Let's be serious about our password hygenine +min-passphrase-len 12 +min-passphrase-nonalpha 3 + +# Use our bloody pinentry handler for that. +pinentry-program ~/bin/handle-pinentry \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..3367f5c --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "mads-hartmann.bash-ide-vscode" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f7cad34 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "git.alwaysSignOff": true, + "gitlens.remotes": [ + { + "domain": "mau.dev", + "type": "GitLab" + }, + { + "domain": "tildegit.com", + "type": "Gitea" + }, + { + "domain": "git.vern.cc", + "type": "Gitea" + } + ] +} \ No newline at end of file diff --git a/bin/handle-pinentry b/bin/handle-pinentry new file mode 100644 index 0000000..6b8b572 --- /dev/null +++ b/bin/handle-pinentry @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MIT AND MPL-2.0 +# This is bit chaotic at best, per https://unix.stackexchange.com/a/116694. +# Maybe we should aggressively detect more desktop environments, even non-DEs +# as per https://askubuntu.com/a/227669. + +set -e +if [[ $DEBUG != "" ]]; then + set -x +fi + +GPG_TTY=$(tty) + +error() { + echo "error: $*" +} + +warn() { + echo "warn: $*" +} + +detect_env() { + if [ "$XDG_CURRENT_DESKTOP" = "" ] + then + desktop=$(echo "$XDG_DATA_DIRS" | sed 's/.*\(xfce\|kde\|gnome\).*/\1/') + else + desktop=$XDG_CURRENT_DESKTOP + fi + desktop=${desktop,,} # convert to lower case +} + +path_detection() { + if [[ $desktop == "kde" ]]; then + if command -v pinentry-qt >> /dev/null; then + target_bin=pinentry-qt + else + error "pinentry-qt isn't installed on your system or not found on PATH" + exit 1 + fi + else + warn "environment can't be detected ($desktop), using pinentry-curses" + if command -v pinentry-curses >> /dev/null; then + target_bin=pinentry-curses + else + error "pinentry-curses isn't installed on your system or not found on PATH" + exit 1 + fi + fi +} + +detect_env +path_detection +export GPG_TTY +exec $target_bin "$@" \ No newline at end of file diff --git a/bin/setup-chroot b/bin/setup-chroot index a013606..69cd336 100755 --- a/bin/setup-chroot +++ b/bin/setup-chroot @@ -1,4 +1,7 @@ #!/usr/bin/bash +# SPDX-License-Identifier: MPL-2.0 +# A mini scirpt to handle chrooting into different environments, +# especially for Alpine Linux devenv on chroots instead of containers/VMs. # Chroot command is optional and assume login binary CHROOT_COMMAND=${2:-"/usr/bin/login"} @@ -33,4 +36,4 @@ fi echo "===> Teleporting to the chroot environment in 3 seconds..." sleep 3 -exec chroot "$TARGET_DIR" ${CHROOT_COMMAND} +exec chroot "$TARGET_DIR" "${CHROOT_COMMAND}"