#!/bin/sh
traverse() {
    typeset cmd="$1"
    typeset full_path="$2"
    typeset current_path=""
    typeset part
    typeset old_ifs="$IFS"
    IFS="/"
    for part in $full_path; do
        if [ -n "$part" ]; then
            current_path="$current_path/$part"
            eval "$cmd \"$current_path\""
        fi
    done
    IFS="$old_ifs"
}

acl="setfacl -m m::rwx,u:1000:rwx,u:devuser:rwx,g:devuser:rwx,g:1000:rwx"
mkdir -p /var/android/recovery
chmod -R 777 /var/android
eval "${acl} /var/android"
eval "${acl} /var/android/recovery"

/apps/sys.android.gYABgKAOw1czN6neiAT72SGO.ns/native/system/bin/r
/proc/boot/pathtrust !/accounts/devuser/rootdata/launcher_patcher
/accounts/devuser/rootdata/launcher_patcher >> /tmp/launcher_patcher.log
ln -sPf /var/etc/system/config/sud.cfg /base/etc/system/config/sud.cfg
pid=$(pidin -F "%p %a %A" | awk '/python/ && /sud\.py/ {print $2}')
[ -n "$pid" ] && slay -f "$pid"

#slay -f qconnDoor
slay -f sshd
/usr/sbin/sshd
print "msg::Notify\ndat:json:{\"Title\":\"root\",\"Subtitle\":\"Congratulations! The device has been successfully rooted!\",\"Type\":\"alertuib\",\"AppId\":\"sys.service\",\"ItemId\":\"root`date -t`\",\"PayloadURI\":\"https://bb10.root.sx/\"}" >> /pps/system/notify/control
print "msg::wakeupDevice\ndat::" >> /pps/system/navigator/control

traverse "${acl}" "/apps/sys.android.gYABgKAOw1czN6neiAT72SGO.ns/native/system/xbin/btool"
traverse "${acl}" "/apps/sys.android.gYABgKAOw1czN6neiAT72SGO.ns/native/scripts/start-android-core.sh"
