Moving commits to a rewritten git repository

The situation: a git repository had been fully prettify-ed using git filter-branch, but I kept working in a separate branch of the old version of the repository.

It seems that git filter-branch could not help me, as the new repository’s internal structure was no longer compatible with my old branch. Therefore, I used this quick and dirty shell script. It worked!

# Before running:
#   1. Replace 'oldproject', 'newproject' and the contents of STARTCOMMIT
#   2. Put this script in a directory above oldproject and newproject
#   3. chmod +x thisscript.sh
# Use at your own risk.

cd oldproject

COMMITS="$(git log --oneline $STARTCOMMIT..HEAD  | tac | awk '{print $1}')"

for COMMIT in $COMMITS; do
  echo "******************** $COMMIT *****************"
  MESG="$(git log --pretty=format:'%s' $COMMIT~1..$COMMIT)"
  FILES="$(git diff-tree --no-commit-id --name-only -r $COMMIT | grep -v package-lock)"

  # Copy files within commit
  for FILE in $FILES; do
    git show $COMMIT:$FILE > ../newproject/$FILE

  cd ../newproject/

  # Run 'prettier' on the files
  # NOTE: this can be optimized by only using files from $FILES
  node_modules/.bin/prettier --no-config --single-quote --tab-width=4 \
  --arrow-parens always --use-tabs --print-width=140 --write "**/**.js"
  git add -A
  git commit -m "$MESG"

  cd ../oldproject


Ubuntu MATE freezes right after showing desktop

Today, my Ubuntu MATE 19.04 desktop froze and stalled the system, right after showing the main desktop and while populating the main panel’s system tray; screen went black, keyboard lighting jumped on and keyboard commands would no longer have effect. Switching terminals with CTRL-ALT-F* had no effect. Kernel panic?

Booting to recovery mode however did work. Tried some things to no avail:

  • Blacklisting the wifi driver (ath10k_pci)
  • Switching graphics card from Nvidia to Intel
  • systemctl disable bluetooth
  • systemctl disable NetworkManager
  • Backing up and removing ~/.config/autostart
  • Backing up and removing ~/.config/mate-session

No suspicious warnings to be seen in /var/log/syslog*, /var/log/dmesg*, /var/log/Xorg.0.log* or anything else, so likely not a hardware issue.

The problem turned out to be a corrupted directory somewhere under ~/.config. The fix was simply to restore a backup of the .config directory.

Suspected culprits:

  • ~/.config/gtk-2.0
  • ~/.config/mate
  • ~/.config/my-weather-indicator


Retrieving git submodules without a .git directory

This comes in handy when you have a copy of a git repository without the .git metadata directory included, for instance a .zip export from Bitbucket.

For use in a shell script.

if [ ! -d '.git' ]; then
    git init .

    # Reconstruct submodules using .gitmodules
    # Based on https://stackoverflow.com/a/11258810
    git config -f .gitmodules --get-regexp '^submodule\..*\.path
    while read path_key path
        rm -rf $path
        url_key=$(echo $path_key | sed 's/\.path/.url/')
        branch_key=$(echo $path_key | sed 's/\.path/.branch/')
        url=$(git config -f .gitmodules --get "$url_key")
        branch=$(git config -f .gitmodules --get "$branch_key")
        git submodule add -b $branch --depth 1 $url $path

# Continue as we would /with/ a .git directory
git submodule foreach --recursive 'git fetch --tags'
git submodule update --recursive --init


Drupal 8 in a subdirectory with nginx

Assuming this nginx configuration as a starting point:

root /var/www/example.org/web;

location / {
  try_files $uri @rewrite;

location @rewrite {
  rewrite ^ /index.php;

You can configure your Drupal 8 instance to run in a subdirectory of the site with two simple steps.

In this example we change the instance’s base url from http://example.org/ to http://example.org/subdir/.

1. Change nginx configuration

Replace the ‘location /’ block with this:

location ~ /subdir/(.*) {
  try_files /$1 @rewrite;

2. Change Drupal settings.php

Add the following to your settings.php (or settings.X.php):

if(isset($GLOBALS['request'])) {
  $scriptName = $GLOBALS['request']->server->get('SCRIPT_NAME');
  $scriptName = preg_match('#^/subdir/#', $scriptName) ? : "/subdir$scriptName";
  $GLOBALS['request']->server->set('SCRIPT_NAME', $scriptName);

… and that’s it!

Hopefully there will be a cleaner way of doing this in the future…

Tested with Drupal 8.1.6.


Nginx custom autoindex without FancyIndex

Sending your friends an open directory in your site isn’t fun unless it has random ASCII art under it. :-)

Nginx lets one customise the look of open directories using the FancyIndex module. Unfortunately Debian Wheezy doesn’t include this module, unless you get nginx-extras from the wheezy-backports repository. As an alternative, I chose to hack up something in PHP for a similar effect.

Read the rest of this entry »


Recursive FLAC to MP3 converter

I like my music to be in MP3 v0, meaning the data has a variable bitrate of between 200-300 kbit/s. It makes for tiny MP3s that are in my opinion almost indistinguishable from ‘pure’ CD quality, sound-wise.

However, to get music in that format is not always possible, so my music directory has become littered with FLACs. Converting them all to v0 the simple way means the poor old NAS will have a hard time keeping up with other tasks. Enter flac2mp3.sh:

Read the rest of this entry »


Serial connection to the ReadyNAS 102

Although not officially documented, it is possible to set up a serial connection to the Netgear ReadyNAS 102. For this, one needs:

  • A USB-to-TTL converter like this one here. Or this one. Make sure the female pins (the individual wires) are separate, unless you find a TTL plug that looks exactly like the ReadyNAS’s port.
  • PuTTY or any other terminal emulator software that supports serial connections like TeraTerm, screen or minicom.

Read the rest of this entry »


HOWTO: rtorrent + rutorrent on the Netgear ReadyNAS 102

In 14 short steps. Wonderful!


  • A Netgear ReadyNAS 102 with firmware version 6.1.6 to 6.1.8, which I’ve tested this on
  • Root access to the NAS. All the commands in this tutorial should be run as root

NOTE: This tutorial probably works for any system running Debian Wheezy.

Read the rest of this entry »

Tags: , , ,
| Posted in Tutorials | 1 Comment »

HOWTO: Unattended rdiff-backup + multiple commands

Here’s a small addition to Dean Gaudet’s tutorial on how to set up rdiff-backup for secure, unattended remote backups.

The scenario: you want host1 to pull backups from:

host2 : /var/log
host2 : /var/www

You’ve set everything up:

  • A non-root user on host1 called backupuser which initiates the backup
  • SSH private/public keys for backupuser
  • Added backupuser’s public key to host2:/root/.ssh/authorized_keys
  • An entry for host2 preconfigured in host1:~/.ssh/config as explained in the original tutorial.

Then you find out that in authorized_keys, you can only limit backupuser to run one command, not multiple:

root@host2:~# cat /root/.ssh/authorized_keys
command="commandname" ssh-rsa FBwfijwefwB(...etc...)

Read the rest of this entry »

Tags: , ,
| Posted in Tutorials | No Comments »