Airgap file-system

So I needed to create a file-system to house a handful of archive/backup tarballs (around 40 of them). I created an ext4 file-system with 100 inodes, like this:

# mkfs.ext4 -b 4096 -L airgap -m 0 -N 100 -v /dev/sdc1

Note: 100 inodes isn’t very many! Only supports up to 100 files/folders. Also note that 0% space is reserved for root. If you’re copying the above command make sure you replace /dev/sdc1 with an appropriate partition device.

Registering a systemd Service

So today I read How To Set Up VNC Server on Debian 8 which had a section on creating and registering the requisite scripts:

/usr/local/bin/myvncserver (make sure it’s executable with +x):

#!/bin/bash
PATH="$PATH:/usr/bin/"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
case "$1" in
start)
/usr/bin/vncserver ${OPTIONS}
;;
stop)
/usr/bin/vncserver -kill :${DISPLAY}
;;
restart)
$0 stop
$0 start
;;
esac
exit 0

/lib/systemd/system/myvncserver.service:

[Unit]
Description=VNC Server example

[Service]
Type=forking
ExecStart=/usr/local/bin/myvncserver start
ExecStop=/usr/local/bin/myvncserver stop
ExecReload=/usr/local/bin/myvncserver restart
User=vnc

[Install]
WantedBy=multi-user.target

Then to register and start:

systemctl daemon-reload
systemctl enable myvncserver.service
systemctl start myvncserver.service

pwned

I wrote the below BASH function today. It’s good because it performs super well compared to the alternative commands (which are commented out below above the new commands):

own() {

  echo "Taking ownership..."
  #chown -R jj5:jj5 .
  find . \! -user jj5 -or \! -group jj5 -execdir chown jj5:jj5  "{}" \;
  [ "$?" = 0 ] || { echo "Could not take ownership in '$PWD'."; exit 1; }

  echo "Fixing directory permissions..."
  #find . -type d -execdir chmod u+rwx "{}" \;
  find . -type d -and \( \! -perm /u=r -or \! -perm /u=w -or \! -perm /u=x \) -execdir chmod u+rwx "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix directory permissions in '$PWD'."; exit 1; }

  echo "Fixing file permissions..."
  #find . -type f -execdir chmod u+rw "{}" \;
  find . -type f -and \( \! -perm /u=r -or \! -perm /u=w \) -execdir chmod u+rw "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix file permissions in '$PWD'."; exit 1; }

}

The basic premise is don’t do work which doesn’t need to be done!