#!/system/bin/sh

set_perm() {
  chown $1.$2 $4
  chmod $3 $4
  if [ ! -z "$5" ]; then
    chcon -h $5 $4
    chcon $5 $4
  else
    chcon -h u:object_r:system_file:s0 $4
    chcon u:object_r:system_file:s0 $4
  fi
}

cp_perm() {
  rm $5
  if [ -f "$4" ]; then
    cat $4 > $5
    set_perm $1 $2 $3 $5 $6
  fi
}

chcon u:object_r:system_file:s0 /su

mkdir /su/bin
mkdir /su/xbin
mkdir /su/lib
mkdir /su/etc
mkdir /su/su.d

set_perm 0 0 0751 /su/bin
set_perm 0 0 0755 /su/xbin
set_perm 0 0 0755 /su/lib
set_perm 0 0 0755 /su/etc
set_perm 0 0 0700 /su/su.d

cp_perm 0 0 0755 /.sufrp/su /su/bin/su
cp_perm 0 0 0755 /.sufrp/su /su/bin/daemonsu
ln -s /su/bin/su /su/bin/supolicy
cp_perm 0 0 0755 /.sufrp/supolicy /su/bin/supolicy_wrapped
cp_perm 0 0 0644 /.sufrp/libsupol.so /su/lib/libsupol.so
cp_perm 0 0 0755 /.sufrp/sukernel /su/bin/sukernel

