Skip to content

Instantly share code, notes, and snippets.

@rakslice
Last active June 20, 2023 04:21
Show Gist options
  • Save rakslice/74da64b69cdeb3938ec0e98a3c34a377 to your computer and use it in GitHub Desktop.
Save rakslice/74da64b69cdeb3938ec0e98a3c34a377 to your computer and use it in GitHub Desktop.
A script to put together and build fujitsu_scroll modified psmouse module on alpine
#!/bin/bash
set -e
# A script to put together and build fujitsu_scroll modified psmouse module on alpine
if [ ! -d ~/src/aports ]; then
echo "error: you need an aports checkout to get the current kernel source"
exit 1
fi
set -x
sudo apk add linux-lts-dev
if [ ! -d ~/src/fujitsu_scroll ]; then
cd ~/src
git clone https://github.com/sammertens/fujitsu_scroll fujitsu_scroll
cd fujitsu_scroll
else
cd ~/src/fujitsu_scroll
git pull
fi
# freshen the kernel source from aports
# - make sure aports is up to date
cd ~/src/aports/main/linux-lts
git pull
# - make sure its the source for the current running kernel ver
pkgver=$(grep '^pkgver=' APKBUILD | cut -d'=' -f2)
pkgrel=$(grep '^pkgrel=' APKBUILD | cut -d'=' -f2)
[ "$(uname -r | cut -d'-' -f1)" == "$pkgver" ]
# skipping the pkg release number check because it seems they often bump it without checking in the incremented number
# so it won't match
#[ "$(uname -r | cut -d'-' -f2)" == "$pkgrel" ]
[ "$(uname -r | cut -d'-' -f3)" == "lts" ]
marker=.prepared.$(uname -r)
if [ ! -f $marker ]; then
# - prepare source files
if [ -d src ]; then
rm -rf src
fi
abuild unpack prepare
touch $marker
fi
cd src/linux-*/drivers/input/mouse
for f in *.h *.c; do
if [ "$f" == "psmouse-base.c" ]; then continue; fi
if [ "$f" == "psmouse.h" ]; then continue; fi
if [ -f ~/src/fujitsu_scroll/drivers/input/mouse/"$f" ] && \
diff "$f" ~/src/fujitsu_scroll/drivers/input/mouse/"$f"; then
continue
fi
cp "$f" ~/src/fujitsu_scroll/drivers/input/mouse/
done
# ok now build fujitsu scroll version
cd ~/src/fujitsu_scroll
#make -C /lib/modules/$(uname -r)/build M=~/src/fujitsu_scroll/drivers/input/mouse clean
make -C /lib/modules/$(uname -r)/build M=~/src/fujitsu_scroll/drivers/input/mouse modules
sudo make -C /lib/modules/$(uname -r)/build M=~/src/fujitsu_scroll/drivers/input/mouse modules_install
# this will install the module in extras/ since we are using the out of tree build process to build it
# even though it is basically a copy of the module subdir
# rename the original psmouse module to disable it so that our built one in extras will be used
orig_ko=/lib/modules/$(uname -r)/kernel/drivers/input/mouse/psmouse.ko.gz
if [ -f "$orig_ko" ]; then
sudo mv "$orig_ko" "${orig_ko}.bak"
fi
if lsmod | grep psmouse > /dev/null; then
sudo rmmod psmouse
fi
sudo depmod
sudo modprobe psmouse "$@" || (
echo "FAILED TO LOAD, PUTTING BACK ORIGINAL"
sudo mv "${orig_ko}.bak" "$orig_ko"
sudo modprobe psmouse
exit 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment