• 7 Posts
  • 194 Comments
Joined 1 year ago
cake
Cake day: February 17th, 2024

help-circle



  • I self host vaultwarden and its great. Its an easy self host, and in my experience, it has never gone down on me.

    That being said, my experience is anecdotal. If you do go the vaultwarden route, realize that your vault is still accessible on your devices (phone, whatever) even if your server goes down, or if you just lose network connectivity. They hold local (encrypted at rest) copies of your vault that are periodically updated.

    Additionally, regardless of the route you take you should absolutely be practicing a good 3-2-1 backup strategy with your password vault, as with any other data you value.



  • You can do this with the dd command. To prep:

    Set up a live boot USB stick with your distro of choice.

    Install another SSD/nvme/HDD at least the same size as your bookworm install into your bookworm machine. If that’s not an option connect a USB drive that’s at least the same size as the drive with your bookworm installation.

    Boot into the live USB on the bookworm machine.

    Make sure the partition(s) from your bookworm install are unmounted.

    Quadruple check the drives/devices for the dd command. Here’s the basics of the command:

    dd if=/device/where/bookworm/is/installed of=USB/or/second/drive/in/machine bs=8M status=progress

    So, if your bookworm install is on /dev/sda, and the USB or secondary is /dev/sdb, then the Cmand would be:

    dd if=/dev/sda of=/dev/sdb bs=8M status=progress


  • I’ve been learning bash and working on scripts to automate stuff in my homelab. It’s been a lot of fun. I’m currently working on a script that will rename the movies and TV shows I rip from my DVD collection.

    The script queries the tmdb api, presents me with a mwnu of matches if there’s multiple matches, renames the media files according to jellyfin spec, and then places them in the proper folders to be indexed by Jellyfin and Kodi.











  • Oh god! I’m sorry about the missing )! I must have dropped it when copying things from my notes over to post the comment! (≧▽≦)

    Despite my error, I’m glad it worked, and even happier that you were able to take what we had worked out and modify it further to fit your other requirements. It’s fun helping each other out, and it’s also great learning.

    I learn by problem solving, so I’ve got all my notes from working on this in my knowledge base as well!

    In the future, feel free to ping me if you need help with other linux/cli/bash things. As I’ve mentioned before I’m no expert, but happy to help where I can.




  • Okay. To address the %20 and the https links, and the placeholder links, I came up with a bash script to handle this.

    Because of the variation in the links, instead of trying to write a sed command that will match only %20 in anchor markdown links, and placeholder links, while ignoring https links and ignoring all other text in the document.

    To do that, I used grep, a while loop, IFS, and sed

    Here’s the script:

    #! /bin/bash
    
    mdlinks="$(grep -Po ']\((?!https).*\)' ~/mkdn"
    
    while IFS= read -r line; do
    	dashlink="$(echo "$line" | sed 's/%20/-/g')"
    	sed -i "s/$line/${dashlink}/" /path/to/file
    done <<<"$mdlinks"
    

    I’m not sure how familiar you are with bash scripting, so I’ll do the same breakdown:

    #! /bin/bash - This tells the shell what interpreter to use for the script. In this case it’s bash.

    mdlinks="$(grep -Po ']\((?!https).*\)' /path/to/file" - This line uses grep to search for markdown link enclosures excluding https links and to output only the text that matches and saves all of that into a variable called mdlinks. Each link match will be a new line inside the variable.

    The breakdown of the grep command is as followes:

    grep - invokes the grep command

    -Po - two command flags. The P tells grep to use perl regular expressions. The o tells grep to only print the output that matches, rather than the entire line.

    ' - opens the regex statement

    ]\( - finds a closing bracket followed by an opening parentheses

    (?!https) - This is a negative look ahead, which a feature available in perl regex. This tells grep not to match if it finds the https string. The parentheses encloses the negative look ahead. The ?! Is what indicates it’s a negative look ahead, and the https is the string to look for and ignore.

    ' - closes the regex statement

    /path/to/file - the file to search for matches

    while IFS= read -r line; do - this invokes a while loop using the Internal Field Separator (IFS=), which by default includes newline character. This allows the loop to take in the variable containing all of the matched links and separate them line by line to work on one at a time. The read command does what it says and reads the input given. In this case our variable mdlinks. The -r flag tells read to ignore the backslash character and just treat it as a normal part of the input. line is the variable that each line will be saved in as they are worked through the loop. The ; ends while setup, and do opens the loop for the commands we want to run using the input saved in line.

    dashlink="$(echo "$line" | sed 's/%20/-/g')" - This command sequence runs the markdown link saved in the line variable into sed to find all instances of %20 and replace them with a -.

    dashlink - the variable we’re saving the new link with dashes to.

    = - separates the variable from the input being saved into the variable.

    " - opens this command string for variable expansion.

    $ - tells bash to do command substition, meaning that the output of the following commands will be saved to the variable, rather than the actual text of the commands that follows.

    ( - opens the command set

    echo - prints the given text or arguments to standard output, in this case the given argument is the variable $line

    " - tells bash to expand any variables contained within the quote set while ignoring any nonstandard characters like spaces or special shell characters that are saved in the variable.

    $line - the variable containing our active markdown link from the text document

    " - the closing quote ending the argument and the expansion enclosure

    | - This is a pipe, which redirects the standard output of the command on the left into the command on the right. Meaning we’re taking the markdown link currently saved in the variable and feeding it into sed

    sed - invokes sed so we can manipulate our text, and because sed is receiving redirected input, and we’ve specified no flags, the modified text will be printed to standard output.

    's/%20/-/g' - Our pattern match/substitution, which will find all occurrences of the string %20 in the markdown link fed into sed and replace them with -.

    )" - closes our command sequence for command substitution, and the variable expansion. At this point the text printed to standard output by sed is saved to the variable dashlink

    The next line is: sed -i "s/$line/${dashlink}/" /path/to/file, which uses sed to take the line and dashlink variables and use them to find the exact original markdown link in the text containing the %20 sequences, and replace it with the properly formatted markdown link with dashes.

    sed -i - invokes sed and uses the -i flag to edit the file in place.

    " - The double quote enclosure allows the expansion of variables in the pattern match/replacement sequence so it searches for the markdown link, and not the literal text string $line.

    s/ - opens our match/modify sequence.

    $line - the original markdown link that will be found

    / - ends the pattern matching section

    ${dashlink} - The variable containing the previously modified markdown link that now has dashes. This expands to that properly formatted link which will be written into the text file replacing the malformed link. I don’t know why this link has to be enclosed in curly braces while the first one does not.

    /" - ends the text modification section and closes the variable expansion.

    /path/to/file - the file to be worked on

    Finally we have done<<<"$mdlinks", which ends the while loop and feeds the mdlinks variable into it.

    done - closes the while loop

    <<< - This feeds the given argument into the while loop for processing

    " - expands the variable within while ignoring nonstandard characters

    $mdlinks - the variable we’re feeding in with all of our links containing %20, except for https links.

    " - closes the variable expansion.

    If you’ve never written/created your own bash script, here’s what you need to do.

    • in your home directory, or in the directory you’re working in with these files, use a text editor like vim or nano or gedit or kate or whatever plain text editor you want to to create a new file. Call the file whatever you want.

    • Paste the entirety of the script text into the file. Modify the file paths as needed to work the file you want to work. if working multiple files, you’ll need to update the script for each new file path as you finish one and move on to the next

    • Save and exit the file

    • Make the file executable at the terminal with sudo chmod +x /path/to/script/file

    • To run it:

      • Change directory to the directory that contains the script file (if you’re not already there)
      • at the command line use the command . ./name-of-script-file

  • I checked the locale and it is correct. I’m on Arch, and I just installed neovim to compare the cursor and typing behaviors, and in neovim it acts as expected when I type the ~.

    I did notice that in vim, I now have a blinking block cursor in insert mode as well as in visual mode, while in neovim, it’s a block cursor in visual mode and a vertical bar cursor in insert mode. This was the normal behavior in vim prior to whatever the heck I did.

    Edit: grammar