#!/system/bin/sh
MODE=$1
log_print() {
echo "($MODE) $1"
log -p i -t launch_daemonsu "($MODE) $1"
}
log_print "start"
if [ `mount | grep " /data " >/dev/null 2>&1; echo $?` -ne 0 ]; then
# /data not mounted yet, we will be called again later
log_print "abort: /data not mounted #1"
exit
fi
if [ `mount | grep " /data " | grep "tmpfs" >/dev/null 2>&1; echo $?` -eq 0 ]; then
# /data not mounted yet, we will be called again later
log_print "abort: /data not mounted #2"
exit
fi
SBIN=
DAEMONSU=
LOGFILE=
if [ ! -d "/su" ]; then
log_print "/sbin mode"
# sbin mode
SBIN=true
SUFILES=/data/adb/su
DAEMONSU=/sbin/daemonsu
LOGFILE=/sbin/.launch_daemonsu.log
# in case of factory reset
if [ ! -d "/data/adb" ]; then
mkdir /data/adb
chmod 0700 /data/adb
restorecon /data/adb
fi
# cleanup /su mode
rm -rf /data/su.img
else
log_print "/su mode"
# normal systemless mode
SBIN=false
SUFILES=/su
DAEMONSU=/su/bin/daemonsu
LOGFILE=/dev/.launch_daemonsu.log
# cleanup /sbin mode
rm -rf /data/adb/su
fi
if ($SBIN) || [ `cat /proc/mounts | grep $SUFILES >/dev/null 2>&1; echo $?` -eq 0 ]; then
if [ -d "$SUFILES/bin" ]; then
if [ `ps | grep -v "launch_daemonsu.sh" | grep "daemonsu" >/dev/null 2>&1; echo $?` -eq 0 ] || [ `ps -A | grep -v "launch_daemonsu.sh" | grep "daemonsu" >/dev/null 2>&1; echo $?` -eq 0 ]; then
# nothing to do here
log_print "abort: daemonsu already running"
exit
fi
fi
fi
setprop sukernel.daemonsu.launch $MODE
if ($SBIN); then
# make sure our SUFILES directory exists
# not needed in /su mode, created by boot image patcher
mkdir $SUFILES
chown 0.0 $SUFILES
chmod 0755 $SUFILES
chcon u:object_r:system_file:s0 $SUFILES
fi
loopsetup() {
LOOPDEVICE=
for DEV in $(ls /dev/block/loop*); do
if [ `losetup $DEV $1 >/dev/null 2>&1; echo $?` -eq 0 ]; then
LOOPDEVICE=$DEV
break
fi
done
log_print "loopsetup($1): $LOOPDEVICE"
}
resize() {
local LAST=
local SIZE=
for i in `ls -l /data/su.img`; do
if [ "$LAST" = "root" ]; then
if [ "$i" != "root" ]; then
SIZE=$i
break;
fi
fi
LAST=$i
done
log_print "/data/su.img: $SIZE bytes"
if [ "$SIZE" -lt "96000000" ]; then
log_print "resizing /data/su.img to 96M"
e2fsck -p -f /data/su.img
resize2fs /data/su.img 96M
fi
}
REBOOT=false
# copy boot image backups
log_print "copying boot image backups from /cache to /data"
cp -f /cache/stock_boot_* /data/. 2>/dev/null
if ($SBIN); then
if [ -d "/data/supersu_install" ] || [ -d "/cache/supersu_install" ]; then
log_print "merging from [/data|/cache]/supersu_install"
cp -af /data/supersu_install/. $SUFILES
cp -af /cache/supersu_install/. $SUFILES
rm -rf /data/supersu_install
rm -rf /cache/supersu_install
log_print "merge complete"
fi
elif [ ! -d "$SUFILES/bin" ]; then
# not mounted yet, and doesn't exist already, merge
log_print "$SUFILES not mounted yet"
if [ -f "/data/su.img" ]; then
log_print "/data/su.img found"
e2fsck -p -f /data/su.img
# make sure the image is the right size
resize
fi
# newer image in /cache ?
# only used if recovery couldn't mount /data
if [ -f "/cache/su.img" ]; then
log_print "/cache/su.img found"
e2fsck -p -f /cache/su.img
OVERWRITE=true
if [ -f "/data/su.img" ]; then
# attempt merge, this will fail pre-M
# will probably also fail with /system installed busybox,
# but then again, is there anything busybox doesn't break?
# falls back to overwrite
log_print "/data/su.img found"
log_print "attempting merge"
mkdir /cache/data_img
mkdir /cache/cache_img
# setup loop devices
loopsetup /data/su.img
LOOPDATA=$LOOPDEVICE
log_print "$LOOPDATA /data/su.img"
loopsetup /cache/su.img
LOOPCACHE=$LOOPDEVICE
log_print "$LOOPCACHE /cache/su.img"
if [ ! -z "$LOOPDATA" ]; then
if [ ! -z "$LOOPCACHE" ]; then
# if loop devices have been setup, mount images
OK=true
if [ `mount -t ext4 -o rw,noatime $LOOPDATA /cache/data_img >/dev/null 2>&1; echo $?` -ne 0 ]; then
OK=false
fi
if [ `mount -t ext4 -o rw,noatime $LOOPCACHE /cache/cache_img >/dev/null 2>&1; echo $?` -ne 0 ]; then
OK=false
fi
if ($OK); then
# if mounts have succeeded, merge the images
if [ `cp -af /cache/cache_img/. /cache/data_img >/dev/null 2>&1; echo $?` -eq 0 ]; then
log_print "merge complete"
OVERWRITE=false
fi
fi
umount /cache/data_img
umount /cache/cache_img
fi
fi
losetup -d $LOOPDATA
losetup -d $LOOPCACHE
rmdir /cache/data_img
rmdir /cache/cache_img
fi
if ($OVERWRITE); then
# no /data/su.img or merge failed, replace
log_print "replacing /data/su.img with /cache/su.img"
mv /cache/su.img /data/su.img
# make sure the new image is the right size
resize
fi
rm /cache/su.img
fi
if [ ! -f "/data/su.img" ]; then
if [ -d "/.sufrp" ]; then
# create empty image
make_ext4fs -l 96M -a $SUFILES -S /.sufrp/file_contexts_image /data/su.img
chown 0.0 /data/su.img
chmod 0600 /data/su.img
chcon u:object_r:system_data_file:s0 /data/su.img
# make sure the new image is the right size
resize
fi
fi
fi
# do we have an APK to install ?
if [ -f "/cache/SuperSU.apk" ]; then
cp /cache/SuperSU.apk /data/SuperSU.apk
rm /cache/SuperSU.apk
fi
if [ -f "/data/SuperSU.apk" ]; then
log_print "installing SuperSU APK in /data"
APKPATH=eu.chainfire.supersu-1
for i in `ls /data/app | grep eu.chainfire.supersu- | grep -v eu.chainfire.supersu.pro`; do
if [ `cat /data/system/packages.xml | grep $i >/dev/null 2>&1; echo $?` -eq 0 ]; then
APKPATH=$i
break;
fi
done
rm -rf /data/app/eu.chainfire.supersu-*
log_print "SUFILES path: /data/app/$APKPATH"
mkdir /data/app/$APKPATH
chown 1000.1000 /data/app/$APKPATH
chmod 0755 /data/app/$APKPATH
chcon u:object_r:apk_data_file:s0 /data/app/$APKPATH
cp /data/SuperSU.apk /data/app/$APKPATH/base.apk
chown 1000.1000 /data/app/$APKPATH/base.apk
chmod 0644 /data/app/$APKPATH/base.apk
chcon u:object_r:apk_data_file:s0 /data/app/$APKPATH/base.apk
rm /data/SuperSU.apk
sync
# just in case
REBOOT=true
fi
# sometimes we need to reboot, make it so
if ($REBOOT); then
log_print "rebooting"
if [ "$MODE" = "post-fs-data" ]; then
# avoid device freeze (reason unknown)
sh -c "sleep 5; reboot" &
else
reboot
fi
exit
fi
if (! $SBIN) && [ ! -d "$SUFILES/bin" ]; then
# not mounted yet, and doesn't exist already, mount
log_print "preparing mount"
# fix permissions
chown 0.0 /data/su.img
chmod 0600 /data/su.img
chcon u:object_r:system_data_file:s0 /data/su.img
# losetup is unreliable pre-M
if [ `cat /proc/mounts | grep $SUFILES >/dev/null 2>&1; echo $?` -ne 0 ]; then
loopsetup /data/su.img
if [ ! -z "$LOOPDEVICE" ]; then
MOUNT=$(mount -t ext4 -o rw,noatime $LOOPDEVICE $SUFILES 2>&1)
log_print "mount error (if any): $MOUNT"
fi
fi
# trigger mount, should also work pre-M, but on post-fs-data trigger may
# be processed only after this script runs, causing a fallback to service launch
if [ `cat /proc/mounts | grep $SUFILES >/dev/null 2>&1; echo $?` -ne 0 ]; then
setprop sukernel.mount 1
sleep 1
fi
# exit if all mount attempts have failed, script is likely to be called again
if [ `cat /proc/mounts | grep $SUFILES >/dev/null 2>&1; echo $?` -ne 0 ]; then
log_print "abort: mount failed"
exit
fi
log_print "mount succeeded"
fi
if [ ! -d "$SUFILES/bin" ]; then
log_print "FRP: empty $SUFILES"
if [ -d "/.sufrp" ]; then
log_print "FRP: install"
/.sufrp/frp_install
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
supersu.zip (97个子文件)
common
init.supersu.rc 484B
000000deepsleep 228B
install-recovery.sh 629B
frp_install 1KB
chromeos
kernel_data_key.vbprivk 1KB
kernel.keyblock 1KB
kernel.config 1B
kernel.bootloader 1B
hexpatch 656B
avb
supersu.x509.der 763B
BootSignature_Android.jar 27KB
supersu.pk8 1KB
file_contexts 2KB
supersu_is_here 100B
99SuperSUDaemon 55B
launch_daemonsu.sh 13KB
fbe_bypass.sh 1KB
Superuser.apk 6.06MB
init.supersu.rc.24 523B
init.supersu.rc.bindsbin 381B
formats
gzip.1 2B
bzip2 2B
lzo 2B
lz4.2 2B
xz 2B
legz4 2B
lzma 2B
lz4.1 2B
gzip.2 2B
file_contexts_image 81B
init.supersu.rc.24.bindsbin 420B
mips64
sukernel 115KB
suinit 323KB
su 120KB
libsupol.so 485KB
supolicy 67KB
arm
sukernel 49KB
suinit 150KB
su 74KB
libsupol.so 198KB
supolicy 41KB
x86_tools
chattr 13KB
bzip2 64KB
liblzo2.so 114KB
liblzma.so.5 146KB
xz 62KB
chattr.pie 13KB
lz4 49KB
lzop 57KB
mips
sukernel 134KB
suinit 360KB
su 147KB
libsupol.so 475KB
supolicy 70KB
mips_tools
bzip2 73KB
liblzo2.so 141KB
liblzma.so.5 216KB
xz 70KB
chattr.pie 0B
lz4 70KB
lzop 70KB
arm_tools
chattr 10KB
bzip2 68KB
liblzo2.so 116KB
liblzma.so.5 158KB
xz 54KB
chattr.pie 10KB
lz4 49KB
lzop 45KB
x64
sukernel 70KB
suinit 326KB
su 102KB
libsupol.so 335KB
supolicy 46KB
LICENSE 2KB
x86
sukernel 73KB
su.pie 102KB
suinit 317KB
su 102KB
libsupol.so 338KB
supolicy 45KB
META-INF
MANIFEST.MF 7KB
CERT.RSA 2KB
CERT.SF 7KB
com
google
android
update-binary 78KB
updater-script 78B
arm64
sukernel 70KB
chromeos
futility 535KB
suinit 274KB
su 106KB
libsupol.so 327KB
supolicy 50KB
armv7
sukernel 45KB
suinit 150KB
su 74KB
libsupol.so 198KB
supolicy 41KB
共 97 条
- 1
资源评论
lo_heng
- 粉丝: 53
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功