Linux Uncanny Systemd Specific Behavior About Mount

Alright, I stumbled on it like a n00b, if you please say so. But the damn thing gave me some headache before I understand why the heck it was happening.

Long story short, specifically Debian and Arch were running systemd by default and showing this to me, not mounting the specific pattern from fstab. Although, it was showing loaded and running from the systemctl output.

I was a dead rat and furious. After hovering about it sometimes, then came to know that I have to add a systemd specific ,option to the fstab file to get it mounted automatically during boot.

Firefox’s profile has to be mounted on tmpfs, and it was not happening. What I had in my fstab file is this :

firefox /home/bhaskar/.mozilla/firefox/18q9dvrr.default-release tmpfs      size=2G,user,exec,uid=1000,gid=1000                       0 0

…..and once I figure out what is needed to add to that line, after that it looks like this :

firefox /home/bhaskar/.mozilla/firefox/18q9dvrr.default-release tmpfs      x-systemd.automount,size=2G,user,exec,uid=1000,gid=1000                       0 0

Did you notice the difference??? Damn, it was x-systemd.automount , that option has to be added, then only it can be booted automatically during boot.

I have tried other methods of mounting but to no avail. It was not enabling the aumount.unit , until the option gets added to the specific line. So, the thing was not showing when running the standard stock df command. The most confusing part was that systemctl output was showing it was loaded and active .

When I visited that file was missing in the standard location i.e /usr/lib/systemd/system.

Now it is showing like this :

2024-01-29-103508_1701x58_scrot.png

I have a file in my home directory like this :

2024-01-29-104021_1920x302_scrot.png

Now it is showing properly with the standard df command :

2024-01-29-104359_1911x59_scrot.png

Linux Seeing PDF With Zathura Once Downloaded In The Browser

Alright, here is the process I follow to see the PDF with Zathura1. The deal is that, once the damn browser I am in, downloaded the pdf, it simply, automatically opens it in Zathura.

I primarily use the Vimb2 browser, but also use Firefox3 and Nyxt4 and I have written about them in the past.

I wrote two small scripts to accomplish that thing, let me share them with ya…

Monitor file arrival in the directory by using inotifywait5

#!/usr/bin/env bash

downdir=$HOME/Downloads
bib_source=$HOME/bibliography/pdf_docs/

# inotifywait -m --include "[pdf$]" ${downdir} -e create -e moved_to |
#     while read ${downdit} action file; do
#         notify-send "The file '$file' appeared in directory '${downdir}' via '$action'"
#     done


inotifywait -m ~/Downloads -e create -e moved_to |
while read path action file; do
    #echo "The file '$file' appeared in directory '$path' via '$action'"
    # Check if the file is a PDF or another file type.
    cd $downdir
    if [[ $(head -c 4 "$file") = "%PDF" ]]; then
         notify-send "PDF found - filename: $file"
          mv "$file" "$bib_source"
    else
        notify-send "NOT A PDF!"
fi
done

This script also moves the downloaded PDFs to the designated directory, where I keep all my PDFs in one location.

Seeing the PDF with Zathura

#!/usr/bin/env bash

latest_file=$(find $HOME/bibliography/pdf_docs/ -maxdepth 1 -type f -newermt $(date '+%F') -ls | gawk '{ print $11}' | sort -f -i -r | head -1)

$(command -v zathura) "$latest_file" >/dev/null 2>&1

Although I could have amalgamated those two scripts into one, but I refrained to. Small and separated stuff is easy on the eyes and also easy to debug.

Now, you need to infuse the second script to the appropriate location to bind with the browser. Firefox provides an easy way to bind it when you go to Settings and right under the Applications heading, select PDF then click on it pops up a menu and select the bottommost option which says use others and point to the second script to open with a designated application(here it is Zathura).

To use with the Vimb browser, you have to include a single line in the vimbconfig6 file like this :

au DownloadFinished *.pdf shellcmd! open-downloaded-pdf

This line tells the browser to use Autocommand7 and open the PDF from the designated directory.

For working with Nyxt I have started a discussion with the core developers and they responded and you can take a peek at it here .

;; Open downloaded pdf in zathura

(define-configuration browser
((after-download-hook
(hooks:add-hook
 %slot-default%
    (nyxt::make-handler-download
    (lambda (download)
    (when (str:ends-with-p "pdf" (nyxt::destination-path download))
    (echo "Opening ~a in zathura." (nyxt::destination-path download))
    (uiop:launch-program `("zathura" ,(nyxt::destination-path download)))))
    :name 'open-pdf-in-zathura)))))

Pretty darn simple!

How Do I Sync My Blog In Various Places, Remote Repositories? If It Is At All Interest You

Alright, I am going to showcase my workflow of disseminating my blogs in various ways. All it takes little scripts to stitch together and produce the things I want.

I write stuff equally inside Vim and Emacs (like everyone else in the wild, nothing surprising here) and keep stuff in various places for my sake, including pushing selected stuff out on the cloud.

Here is a small script, which does sync to various directories:

#!/usr/bin/env bash

source_dir="/home/bhaskar/blogs/content/articles/2024/"

dest_dir="/home/bhaskar/.emacs.d/OrgFiles/"

backup_dir="/data/blogs/content/articles/2024/"

# inotifywait -m -q -e | while read -r file  | fzf --prompt "select file:"
  # do
  #   # cp "$source_dir" "$dest_dir"
  # done

find "$source_dir" -type f -exec sh -c "basename {}" \; 2>/dev/null | fzf --prompt="Select file:" | xargs -I {} cp "$source_dir/{}" "$dest_dir"

$(command -v rsync) --stats --progress -ravz "$source_dir" "$backup_dir"

if [ $? == 0 ];then

notify-send "File copied to destination dirs sucessfully"
else
        notify-send "Nope,not done."
fi

Ordinary? Huh! It does the job for me.

The below script takes that syncing further including pushing it into the remote repositories:

#!/usr/bin/env bash
# Sync blogs in various places in the file system once then remote push to repositories

source_dir="/home/bhaskar/blogs/content/articles/2024/"
html_blogs="/home/bhaskar/html_blogs/2024/"
cd $source_dir || exit 1

latest_file=$(find . -iname "*.org" -type f -newermt $(date '+%F') -ls | gawk '{ print $11 }' | sort -f -i -r | head -1 | tr -d "./")

mv *.html "$html_blogs"
rm -f .*.~undo-tree~


# call up other script which sync with other with fzf integration
sync_blog

# This will automate git add and git commit with signing at once
addcom "${latest_file}"

# Pushing the latest file to the remote repositories
git push

# If the last command executed successfully then pop out the msg
if [ $? == 0 ];then
        notify-send "Successfully pushed to remote repositories"
else
        notify-send "No,something went wrong, fix it!"

fi

Okay, you spotted there is an “unknown command” in the above script, called “addcom”, that’s a little bunny I wrote for my convenience, here it is :

#!/usr/bin/env bash

addcom ()
{
    git add .;
    git ci "$@" 2> /dev/null;
    if [[ "$@" == "" ]]; then
        echo Not allowed empty commit msg...aborting;
    fi
}
addcom "$@"

Ah, see! How trivialities grasp me, and the results are showing. 🙂

Linux Various Browsers History And Bookmarks Combined View

Alright, like everyone else in the wild, I do use various browsers and I have written about them in the past. Here in this post, I will show you a technique about how to combine different browsers’ History and Bookmarks in one place and show them system-wide, so they can be used in various browsers. I have also given a hint about, how I have been using those browsers in the past too.

Basically, all the operation is done by stitching together various small scripts that output the desired thing at the end.

How Do I Add Bookmarks In My System

#!/usr/bin/env bash
#set -vx
if [[ -z "$1" ]]; then
#  printf "Search query: ";
  query=$( echo | dmenu -p "Add Bookmark Url:" )
else
        query="$1"
fi

#query="${query// /_}"
#echo "$query"

if [[ "$query" == "" ]];then
        exit 1
else

#setsid -f $(command -v vimb) $query
echo "$query" >> ~/.config/vimb/bookmark
notify-send "Bookmark Added for this URL : "$query" "
fi

Well, I have a key bind to open the prompt for the URL with dmenu at the top of the screen and then I have to paste the URL on that prompt and press enter. That’s all to get it saved.

I have said it numerous occasions in several blogs that I am using I3 Window Manager as my base Window Maker. Dmenu is the menu system.

How To Show Bookmarks Via Dmenu

#!/usr/bin/env bash

## Add name of your browser here ( not text-browsers )

BROWSER=$(echo $BROWSER)

## add your plain text bookmarks here, you can add tag after the bookmark bookmart url e.g., "www.google.co.in search googlesearch", use "link-handler" for adding bookmarks

BOOKMARKS=~/.config/vimb/bookmark

# use dmenu to display bookmarks and select one

$(command -v dmenu) -l 30  -p Bookmarks: < "$BOOKMARKS" | read -a url

[[ ! $url ]] && exit

How Do I Sync Various Browsers History To One Place?

#!/usr/bin/env bash

#sync firefox browsing history with vimb's ; just to get a unified history

sqlite3 -list /home/bhaskar/.mozilla/firefox/18q9dvrr.default-release/places.sqlite 'select url from moz_places ;' | grep ^http >> ~/.config/vimb/history

sed -i '/linkedin\|duckduckgo\|twitter\|tweetdeck\|account\|mail\|reddit\|lkml\|retail\|glassdoor\|getpocket\|amazon\|fedora\|youtube\|youtu\|sign_in\|dictionary\|lwn\/d' ~/.config/vimb/history

….and this

#!/usr/bin/env bash

extract_url_by_awk ~/.config/vimb/history 2>&1 | gawk '{ print $1 }' | cat >/home/bhaskar/hist_urls

Sometimes I do run the Surf browser and its history and bookmarks are kept in different ways.

Surf Bookmark

#!/usr/bin/env bash
#===============================================================================
#
#          FILE: surf_bookmark.sh
#
#         USAGE: ./surf_bookmark.sh
#
#   DESCRIPTION: Show bookmarks enlisting at the bottom of the screen for surf
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Bhaskar Chowdhury (https://about.me/unixbhaskar), unixbhaskar@gmail.com
#  ORGANIZATION: Independent
#       CREATED: 01/04/2022 10:00
#      REVISION:  ---
#===============================================================================
set -o nounset

basepath="$HOME/.surf"

cd $basepath || exit 1

if test $(find "bookmark_gen" -cmin +120)
then
            touch bookmark_gen
fi
tac ~/.surf/bookmarks | dmenu -l 10 -b -i -p "Bookmarks:"  | xargs -I {}  setsid -f surf {}

Surf History Enlisting

#!/usr/bin/env bash
#===============================================================================
#
#          FILE: dmenu.uri.sh
#
#         USAGE: ./dmenu.uri.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Bhaskar Chowdhury (https://about.me/unixbhaskar), unixbhaskar@gmail.com
#  ORGANIZATION: Independent
#       CREATED: 01/04/2022 10:00
#      REVISION:  ---
#===============================================================================
set -o nounset
notify-send --expire-time=5000 "This conversion might take lot of time ...hang on ....."
extract_url_by_awk ~/.config/vimb/history 2>&1 | gawk '{ print $1 }'| cat >/home/bhaskar/.surf/history
tac ~/.surf/history | dmenu -l 10 -b -i -p "History:"  | xargs -I {} surf {}

Pretty ordinary stuff, right? But I am happy with it. 🙂

I have used another script in the above code snippet, which is extract_url_by_awk and here it is :

#!/usr/bin/env bash

filename=$1

if [[ $1 == "" ]];then
        echo you need to provide the filename.
        exit 1
        fi


sed -ne 's/.*\(http[^"]*\).*/\1/p'  < $filename

Nyxt Bookmarks Kept Separate, Because It Uses Different Formats

Also, Nyxt keeps its bookmark in different formats, so the file is different, and I haven’t put an effort into amalgamating these into a unified one. But the content of the file looks like this :

(
(:url "https://0xax.gitbooks.io/linux-insides/content/" :title "Introduction · Linux Inside" :date "2022-01-28T23:32:49.204006Z" :tags ("kernelbook"))
(:url "https://0xax.gitbooks.io/linux-insides/content/Booting/linux-bootstrap-1.html" :title "From bootloader to kernel · Linux Inside" :date "2022-05-15T01:41:06.891210Z" :tags ("linuxinside"))
(:url "https://ag91.github.io/blog/2021/06/08/emacs-nyxt-and-engine-mode-how-to-browse-urls-via-nyxt-and-slime/" :title "Emacs, Nyxt and Engine-mode: how to browse URLs via Nyxt and Slime - Where parallels cross" :date "2021-12-16T06:09:52.515996Z" :tags ("browser"))
(:url "https://ag91.github.io/blog/2022/01/29/escalate-your-helm-searches/" :title "Escalate your helm searches! - Where parallels cross" :date "2022-01-29T01:34:51.942098Z" :tags ("helm"))
(:url "https://begriffs.com/posts/2018-11-15-c-portability.html" :title "C Portability Lessons from Weird Machines" :date "2022-02-21T22:51:52.213852Z" :tags ("oldcomparchitecture"))
(:url "https://blog.boot.dev/cryptography/how-sha-2-works-step-by-step-sha-256/" :title "How SHA-256 Works Step-By-Step | Boot.dev" :date "2022-04-23T10:08:50.397288Z" :tags ("sha"))
(:url "https://blog.nelhage.com/post/a-cursed-bug/" :title "A Cursed Bug - Made of Bugs" :date "2022-02-23T11:08:41.870994Z" :tags ("kernelinternals"))
(:url "https://blog.packagecloud.io/how-to-extract-and-disassmble-a-linux-kernel-image-vmlinuz/" :title "How to extract and disassemble a Linux kernel image (vmlinuz) | Packagecloud Blog" :date "2022-04-07T07:14:35.397823Z" :tags ("kernelextraction"))

This file can be found on most Linux systems in this path ~/.local/share/nyxt/bookmarks.lisp

Linux Misbehaving GnuPG…Process To Somehow Fix The Damn Thing…Kinda Brute-force

Well, we all use this tool1 somehow knowingly or unknowingly. Sometimes directly and other times bind with other tools. But this tool is such a present in our armory to get the thing going daily on some operations, that ignoring the tool becomes quite impossible.

In this post, I am gonna discuss and process I follow to fix little glitches that time to time impose on me by not obeying the work it is supposed to do. Here are a few common GnuPG Troubleshooting pages containing some instances.

Now, sometimes, the damn agent will die for no apparent reason and I am forced to bounce it with method. Here is something I have ingrained in my .bashrc , so every time I open up a terminal and apply the method.

2024-01-14-095448_702x192_scrot.png

The above enlisting is just a small function that basically kills the existing gpg-agent ..and this below trick..

bhaskar_09:55:43_Sun Jan 14: :~>grep GPG .bashrc
GPG_TTY=$(tty)
export GPG_TTY

..reinitialize the terminal so it will run.

Whenever It is not working as expected I just call up that function (yeah…yeah I know it can be automated, but I didn’t opt for it for a reason), and voila!

As you have noticed I have enabled the debug option and directed the output to a file. From time to time, I look into that file to; find out if something might be messing around or not. This is a recommended step to get along with this tool.

Here is a random screenshot I just took while writing this post for your visual cue.

2024-01-14-100212_1920x1200_scrot.png

Footnotes:

Arch Linux How To Fix The Damn Ispell Error In Emacs

One of the few rare moments is when I hop into a specific Linux distribution, namely Arch Linux, and start one of my editors and surprise(read annoyed) by encountering a stupid error.

Here is what I got while trying to compose a blog post in customary style like every other time :

2024-01-02-063454_1920x1200_scrot.png

Clearly, it is an ispell error.

Despite having Ispell installed it still spits out an error like this :

2024-01-02-063502_1920x1200_scrot.png

So, it is missing the words file. I had to get it.

And the problem vanishes once restart the Emacs daemon and client.