Change OpenRGB profile on unlock

I have a computer, which my son uses primarly for gaming. I also use it for gaming, when it is available (as of right now, when he has gone to bed). The computer is pimped out with RGB. I got tired of Asus Armoury Crate every now and then maxing the CPU causing the fans to make too much noice, so I replaced it with OpenRGB.

OpenRGB is started automagically when either of us logs in, and sets our own profile. The problem was when we switched between users the last logged in users profile would be the active one.

A combination of a VB script and a scheduled task solves this problem. Create a color profile in OpenRGB and save it with a good name (preferably without spaces).

As an example, create C:\OpenRGB.vb with the following contents:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Program Files\OpenRGB\"
WshShell.Run "OpenRGB.exe --profile ""my-openrgb-profile""", 0, false

Then create a scheduled task that is trigger on workstation unlock and runs the C:\OpenRGB.vb script, something like:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2023-01-13T21:39:19.3700162</Date>
<Author>COMPUTER\User Name</Author>
<URI>\OpenRGB</URI>
</RegistrationInfo>
<Triggers>
<SessionStateChangeTrigger>
<Enabled>true</Enabled>
<StateChange>SessionUnlock</StateChange>
<UserId>COMPUTER\User Name</UserId>
</SessionStateChangeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-775115785-2816134056-1390457888-1001</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\OpenRGB.vbs</Command>
</Exec>
</Actions>
</Task>

Now I just need QMK to finish their new client protocol XAP, and for OpenRGB to implement support for that protocol so it also can control the RGB lightning on the keyboard.

Automagically build load modules when updating the kernel

I bought a new wireless network card to my parents, and it turned out that there wasn’t support in the generic Ubuntu kernel for it. The last month they haven’t been able to use their computer since the card stopped working after updating the kernel, and hence missing the custom built load module.

After rebuilding the load module I was following the output when installing about 200 updates and saw that after updating the kernel there were some scripts from /etc/kernel/postinst.d running.

I then realized that it should be possible to solve the problem by adding a custom script that would rebuild the load module when updating the kernel.

Step 1 was to create a script in both /etc/kernel/postinst.d and /etc/kernel/header_postinst.d that I named build_wifi_driver:

#!/bin/bash
# We're passed the version of the kernel being installed
inst_kern=$1

cd /root/DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/
make KERNEL_VERSION=$inst_kern
make KERNEL_VERSION=$inst_kern install

The second problem was that the Makefiles for the load module had to be updated to use $(KERNEL_VERSION) instead of $(shell uname -r). I had to update three different Makefiles:

DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/Makefile:

--- DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/Makefile    2009-12-28 13:38:34.000000000 +0100
+++ DPO_RT3070_LinuxSTA_V2.3.0.4_20100604.new/Makefile    2011-01-05 19:17:14.000000000 +0100
@@ -117,11 +117,14 @@
endif

ifeq ($(PLATFORM),PC)
+ifndef KERNEL_VERSION
+    KERNEL_VERSION := $(shell uname -r)
+endif
# Linux 2.6
-LINUX_SRC = /lib/modules/$(shell uname -r)/build
+LINUX_SRC = /lib/modules/$(KERNEL_VERSION)/build
# Linux 2.4 Change to your local setting
#LINUX_SRC = /usr/src/linux-2.4
-LINUX_SRC_MODULE = /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless/
+LINUX_SRC_MODULE = /lib/modules/$(KERNEL_VERSION)/kernel/drivers/net/wireless/
CROSS_COMPILE =
endif

@@ -234,7 +237,7 @@
endif

cp -f os/linux/Makefile.4 $(RT28xx_DIR)/os/linux/Makefile
-    $(MAKE) -C $(RT28xx_DIR)/os/linux/
+    $(MAKE) KERNEL_VERSION=$(KERNEL_VERSION)-C $(RT28xx_DIR)/os/linux/

ifeq ($(OSABL),YES)
cp -f os/linux/Makefile.4.netif $(RT28xx_DIR)/os/linux/Makefile
@@ -279,7 +282,7 @@
ifeq ($(PLATFORM),FREESCALE8377)
$(MAKE) ARCH=powerpc CROSS_COMPILE=$(CROSS_COMPILE) -C  $(LINUX_SRC) SUBDIRS=$(RT28xx_DIR)/os/linux modules
else
-    $(MAKE) -C $(LINUX_SRC) SUBDIRS=$(RT28xx_DIR)/os/linux modules
+    $(MAKE) -C $(LINUX_SRC) SUBDIRS=$(RT28xx_DIR)/os/linux KERNEL_VERSION=$(KERNEL_VERSION) modules
endif
endif

DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/os/linux/Makefile.4

--- DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/os/linux/Makefile.4    2009-12-30 02:12:06.000000000 +0100
+++ DPO_RT3070_LinuxSTA_V2.3.0.4_20100604.new/os/linux/Makefile.4    2011-01-05 19:01:56.000000000 +0100
@@ -13,6 +13,9 @@

OBJ := $(MOD_NAME).o

+ifndef KERNEL_VERSION
+KERNEL_VERSION := $(shell uname -r)
+endif

#ifdef CONFIG_STA_SUPPORT
RT28XX_STA_OBJ := \
@@ -200,9 +203,9 @@
cp $(RT28xx_DIR)/$(DAT_FILE_NAME) $(DAT_PATH)/.
install -d $(LINUX_SRC_MODULE)
install -m 644 -c $(addsuffix .o,$(MOD_NAME)) $(LINUX_SRC_MODULE)
-    /sbin/depmod -a ${shell uname -r}
+    /sbin/depmod -a $(KERNEL_VERSION)

uninstall:
#    rm -rf $(DAT_PATH)
rm -rf $(addprefix $(LINUX_SRC_MODULE),$(addsuffix .o,$(MOD_NAME)))
-    /sbin/depmod -a ${shell uname -r}
+    /sbin/depmod -a $(KERNEL_VERSION)

DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/os/linux/Makefile.6

--- DPO_RT3070_LinuxSTA_V2.3.0.4_20100604/os/linux/Makefile.6    2009-12-30 02:12:13.000000000 +0100
+++ DPO_RT3070_LinuxSTA_V2.3.0.4_20100604.new/os/linux/Makefile.6    2011-01-05 19:02:29.000000000 +0100
@@ -12,6 +12,10 @@

obj-m := $(MOD_NAME).o

+ifndef KERNEL_VERSION
+KERNEL_VERSION := $(shell uname -r)
+endif
+

#ifdef CONFIG_STA_SUPPORT
rt$(CHIPSET)sta-objs := \
@@ -198,9 +202,9 @@
cp $(RT28xx_DIR)/$(DAT_FILE_NAME) $(DAT_PATH)/.
install -d $(LINUX_SRC_MODULE)
install -m 644 -c $(addsuffix .ko,$(MOD_NAME)) $(LINUX_SRC_MODULE)
-    /sbin/depmod -a ${shell uname -r}
+    /sbin/depmod -a $(KERNEL_VERSION)

uninstall:
#    rm -rf $(DAT_PATH)
rm -rf $(addprefix $(LINUX_SRC_MODULE),$(addsuffix .ko,$(MOD_NAME)))
-    /sbin/depmod -a ${shell uname -r}
+    /sbin/depmod -a $(KERNEL_VERSION)

I’m no expert when it comes to Makefiles, but these changes solved the issue and the load module now builds automagically every time the kernel was updated.

Öppna Finders nuvarande plats i Terminal

En sak som jag tänkt på mycket men aldrig kommit mig för att undersöka är om det fanns något smidigt sätt att öppna katalogen man navigerat till via Finder i Terminal. En liten snabb googlesökning tog mig, givetvis, till macosxhints.com: A script to open current Finder folder in the Terminal.

Öppna “AppleScript Editor” (finns under Applications, Utilities), kopiera kodsnutten från ovanstående länk och spara. Det är dock väldigt viktigt att spara det som en applikation och inte ett script.

När detta är gjort är det bara att dra filen till Finderns verktygsrad. I och med detta får den dock standard ikonen, vilket inte är särkilt snyggt. Gå till Applications, Utilities och högerklicka på “Terminal”, välj “Get Info”. Högerklicka på AppleScript filen (som sparats som en applikation) och välj “Get Info”. Klicka på ikonen för “Terminal” och tryck cmd+c (kopiera), klicka på ikonen för AppleScriptet och tryck cmd+v (klistra in). Detta gör att ditt AppleScript får samma ikon som “Terminal”.

Asus EEE 901 och Ubuntu EEE

I bought an Asus EEE 901 today. I chosed the black model with Windows XP. But it didn’t take long time before I installed Ubuntu EEE, which is a tailor made Ubuntu based distribution.

On their homepage there are some optimization guides. I started with How to: Reduce Disk Writes to Prolong the Life of your Flash Drive [ubuntu-eee.com]. I skipped the second part of the commands under “blkid.tab and mtab”, since I wanted to continue with Transparent Encryption for home folder [ubuntu-eee.com] which uses FUSE.

I followed the guide mostly step by step, except I didn’t add pam_encfs.so in /etc/pam.d/common-session. That line make sure that the volumes is unmounted when logging out, but it resulted in some error messages every time I ran a command with sudo:

umount: /home/mikael: device is busy
umount: /home/mikael: device is busy

I’m not really sure what sudo is up to, but it seems like the login process for users ends, which results in trying to unmount the home directory.

Eyecandy is a must, it was however not possible to enable them via “System”, “Settings”, “Apperance”, “Visual effects”. So I had to install them manually and then activate them.

sudo apt-get install compiz compizconfig-settings-manager avant-window-navigator

The first package enables visual effects in genera, the second is for being able to configure the visual effects and the third is a Mac OS X-like dock. Recommended effects are “Rotating Cube”, “Reflection Cube” and “Ring switcher”.

Next step was to get my Huawei E220 3G modem working. Fortunately, people had already solved that problem: Mobitel 3G with Huawei E220 on Debian [sayura.net]. I skipped the udev rule and the associated script since I didn’t want it to connect automagically when detected. When I want to connect, I plugin the modem, click on the NetworkManager applet and uncheck “Enable wireless”, then right-click on the same applet, chose “Dial Up Connections” and “Connect to ppp0 via modem…”. Unfortunately there’s a bug in NetworkManager that makes it not possible to detect a working connection that has been configured outside of it, this results in Firefox running in offline-mode. Since Firefox 3.0.1 the way to get around this is to configure “toolkit.networkmanager.disable” to “true” through “about:config”.

A really annoying thing is that pipe (|) doesn’t work in the terminal. A quick google search took me to skrivmaskin.se/linux. I never use caps-lock, so let’s remapping it to |:

echo "setxkbmap -option ctrl:nocaps" >> ~/.bashrc
echo " xmodmap -e \"keycode 66 = bar\"" >> ~/.bashrc

Bluetooth worked out-of-the-box, as long as the feature was activated in BIOS. “Accessories”, “Bluetooth File Sharing” was the only thing needed to get it work. It does however have a really ugly icon in the menu bar, so with the help of strace I found out which icon it was using and replaced it with something that suited my taste. There are 6 pictures which has to be replaced in /usr/share/gnome-bluetooth/pixmaps: frame1.png, frame2.png, ..., frame6.png.

The end result: