#!/sbin/sh

. "$env"

print "Patching the ramdisk for NetHunter & init.d..."

cd "$ramdisk_patch"

# fix permissions of patch files
chmod -R 0755 .

find -type f \( \
	-name "*.rc" ! -name "ueventd.*" \
	\) -exec chmod 0750 {} \;

find -type f \( \
	-name "*.xml" -o -name "*.do" -o -name "*.pem" -o -name "*.vtab" -o \
	-name "fstab.*" -o -name "*.prop" -o -name "*_contexts" -o \
	-name "ueventd.*" -o -name "sepolicy" -o -name "sepolicy_version" \
	\) -exec chmod 0644 {} \;

# move the patch files into the ramdisk
cp -rd ./. "$ramdisk/"

cd "$ramdisk"

# keep adb secure to stop outside attackers
setprop ro.adb.secure 1
setprop ro.secure 1

# import nethunter init to init.rc
import_rc init.nethunter.rc

# ensure /dev/hidg0 and /dev/hidg1 have the correct access rights
ueventd_set "/dev/hidg*" 0666 root root
context_set "/dev/hidg[0-9]*" "u:object_r:input_device:s0"
