File: librem5-lockdown-support

package info (click to toggle)
mobile-tweaks 8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: sh: 44; makefile: 8
file content (49 lines) | stat: -rwxr-xr-x 1,448 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

if ! grep -qs purism,librem5 /sys/firmware/devicetree/base/compatible; then
  echo "Not a Librem5. Skipping."
  exit 0
fi

# modules to be loaded when LSM9DS1 becomes active ordered how to load them
MODULES=( 'st_lsm6dsx' 'st_lsm6dsx_spi' 'st_lsm6dsx_i2c' 'st_magn' 'st_magn_i2c')

# modules already loaded in the order needed to unload them
LOADED=( `lsmod | grep -E "^st_lsm6dsx|^st_magn" | cut -f1 -d' ' | sort -r` )

if [[ `cat /sys/devices/platform/rfkill-hks/rfkill/*/hard | uniq` == '1' ]]; then
	# all hks are enabled, LSM9DS1 is disabled

	# unload any st_lsm6dsx module that is loaded in the correct order
	for M in ${LOADED[@]}; do
		rmmod "$M"
	done

	# unbind vcnl4000 driver if bound
	if [ -h /sys/bus/i2c/drivers/vcnl4000/1-0060 ]; then
		echo 1-0060 > "/sys/bus/i2c/drivers/vcnl4000/unbind"
	fi

else
	# any hks is disabled, LSM9DS1 is enabled

	# load any module from $MODULES not yet loaded
	for M in ${MODULES[@]}; do
		# iter over indices of $LOADED...
		for L in "${!LOADED[@]}"; do
			# ...to check whether the module to be loaded $M
			# is already loaded (and thereby in array LOADED)
			if [[ "${LOADED[$L]}" == "$M" ]]; then
				# if $M already is loaded try next M out of MODULES
				break
			fi
		done
		# if not yet loaded, load $M
		modprobe "$M"
	done

	# bind vcnl4000 driver if unbound
	if ! [ -h /sys/bus/i2c/drivers/vcnl4000/1-0060 ]; then
		echo 1-0060 > "/sys/bus/i2c/drivers/vcnl4000/bind"
	fi
fi