Miscellaneous Findings VI: Commands, Pi

This time, in Miscellaneous Findings, we’ve got some command line things, plus a huge Raspberry Pi setup dump, with some related stuff about hard drives and filesystems mixed in.

This is a roundup of miscellaneous things that I’ve found out about (or have rediscovered). I take notes on findings regularly, and I put the findings that translate well to speech on my podcast, Small Findings. The rest (which are often technical findings), I put here. They’re not always written up for maximum comprehension as a blog post, but if anything is hard to understand, please email me if you need clarification.

Git shortlog

https://git-scm.com/docs/git-shortlog

It’s surprisingly nice to read. e.g.:

Jim Kang (54):
      Hacked up Field. Have a minimally viable TypeScript rollup config.
      Add make target and rollup config for working on a small piece of the app independetly.
      Renaming again.
      Start basic card layout.
      Start move to svelte. Get watch working.
      Convert card to svelte component.
      Move experiments to vats.
      Stub out stores vat.
      Type checking finally working in Svelte components?? Next: Single multi-page rollup config for vats.
      Get multiple rollup configs to work.
      Start stores. Bind to card store in component.
      Drop unneeded crud.
      Stub in all cards store.
      Start persisting to localStorage in stores.
      Hack in a delete.
      Move persistent state stuff into state, take that out of the stores to make them responsible for mostly notifying subscribers.
      Start an export cards component.
      Start import component. Reporting conflicts but not doing anything with them yet.
      Fix wrong set of cards being imported (cards from file, not the ones already in the store), enable Card component to render read-only.

#git #command

Excluding dirs from find

Say you want to find all of the directories in which you have a rollup.config.js file.

You could try

find . -name rollup.config.js

But that would also search all of the node_modules directories, and you mean to find projects in which you’ve used rollup directly.

You can add -path and -not to exclude them from the search:

find . -name rollup.config.js -and -not \( -path '*/node_modules/*' \) -prune

#search #unix #command #find

Raspberry Pi setup

Basics

With a pre-loaded Canakit boot SD card inserted:

  • Connect keyboard, mouse, and display, then power.
  • Pick your wifi network in the wizard.
  • Select “Raspbian Stretch” as the OS to install in the wizard.
  • Open terminal and change password for pi.

Without one:

  • [Get a Raspberry Pi OS image onto an SD card]
  • Hook it up to a TV or display with an HDMI cable
  • Connect a mouse and keyboard
  • Connect a power supply

Remote access

From Remy Sharp’s post:

  • Create an empty file in /boot named ssh: sudo touch /boot/ssh.
  • Reboot.
  • On another computer: arp -a or (sudo nmap -sn [ROUTER-IP]/24 | grep -i raspberry -B 2)
  • SSH in with the user pi

Key-based access

From https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md:

  • cd ~ && install -d -m 700 ~/.ssh
    • Creates the .ssh dir with the right permissions.
  • From a computer where you already have your public key: cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'
  • Remove password auth

    • Edit /etc/ssh/sshd_config with these settings:

      ChallengeResponseAuthentication no
      PasswordAuthentication no
      UsePAM no
      
    • sudo /etc/init.d/ssh reload

External USB hard drive

  • Connect the hard drive to the Pi
  • sudo blkid
    • Make sure the HD appears on /sda1 and /sda2
  • Format it. sudo fdisk /dev/sda to enter interactive fdisk. Reference
    • d (I think) to delete the /sda1 and /sda2 partitions.
    • n to create a new big partition that spans the whole HD. Accept defaults.
    • w to commit this.
  • mkfs.ext4 /dev/sda1
  • Set up automatic mounting. sudo vi /etc/fstab. Add the line: - /dev/sda1 /mnt/storage ext4 defaults,nofail 0 0
    • (Manual mounting would go like this: sudo mkdir /mnt/usb && sudo mount /dev/sdb1 /mnt/usb, unmount: sudo umount /dev/sdb1)
      • nofail is what lets the OS boot even if the HD is not plugged in.
  • If the HD looks like it has nothing on it after a power outage

If you use a vfat filesystem, I don’t think you can change owners?

The consequences of this is that everything is owned by root, and everything, including rsync, must run as root.

Also, you can’t have files larger than 4 GB.

Also also wildcards only go so far if they are in the middle of a specification. ls sm*.js will work, but ls smi*.js will not.

Warning: If you reformat your external drive, you may not be able to boot, even if you have nofail in the fstab entry! It happented to me.

Changing the wifi password

  • Edit /etc/wpa_supplicant/wpa-supplicant.conf
  • Change the psk value under the network entry.

Getting a static ip on the WiFi

The following steps from Raspberry Pi static ip worked:

  • Get the router ip from ip r | grep default (It’s the first ip listed.)
  • cat /etc/resolv.conf to get the nameserver ip.
  • Add this to /etc/dhcpcd.conf:

    interface wlan0
    static ip_address=<desired ip>/24
    static routers=<router ip>
    static domain_name_servers=<router ip> 8.8.8.8
    

You can substitute an external DNS server ip in domain_name_servers.

  • sudo reboot

Turning off the wifi

https://raspberrytips.com/disable-wifi-raspberry-pi/

Edit /boot/config.txt to add this line: dtoverlay=disable-wifi

Root user

The root user does not have a password by default. You can give it a password, but the pi user can sudo, so using sudo su may be easier.

Installing Plex

https://linuxize.com/post/how-to-install-plex-media-server-on-raspberry-pi/

  • sudo apt update
  • sudo apt install apt-transport-https ca-certificates curl
  • curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
  • deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
  • sudo apt update
  • sudo apt install plexmediaserver
  • Check: sudo systemctl status plexmediaserver

Set up dirs

  • sudo mkdir -p /mnt/smidgeocloud/plexmedia
  • sudo chown -R plex /mnt/smidgeocloud/plexmedia (But not for a FAT drive)
  • Config in browser at http://server-ip:32400/web

I somehow ended up with music in the media directory being owned by the 503 user, which prevented the pi user from creating dirs there.

drwxrwxr-x 587 503 staff 20480 Mar 27 01:52 music

I chmodded it to pi.