scripts: fix sloppy/unpredictable cmd && this || that statements

- be a bit more POSIX to avoid any potential issues when full shell stdout/err are redirected
- actual logic chains remain unchanged
This commit is contained in:
osm0sis 2020-11-29 20:35:34 -04:00 committed by John Wu
parent a687d1347b
commit ce84f1762c
5 changed files with 52 additions and 16 deletions

View File

@ -13,7 +13,8 @@ trampoline() {
exec sh $MAGISKBIN/addon.d.sh "$@"
exit $?
elif [ "$1" = post-restore ]; then
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
BOOTMODE=false
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
if ! $BOOTMODE; then
@ -24,7 +25,13 @@ trampoline() {
[ -z $OUTFD ] && OUTFD=$(ps | grep -v 'grep' | grep -oE 'status_fd=[0-9]+' | cut -d= -f2)
[ -z $OUTFD ] && OUTFD=$(ps -Af | grep -v 'grep' | grep -oE 'status_fd=[0-9]+' | cut -d= -f2)
fi
ui_print() { $BOOTMODE && log -t Magisk -- "$1" || echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD; }
ui_print() {
if $BOOTMODE; then
log -t Magisk -- "$1"
else
echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
fi
}
ui_print "***********************"
ui_print " Magisk addon.d failed"
@ -88,7 +95,12 @@ main() {
if $backuptool_ab; then
# Swap the slot for addon.d-v2
if [ ! -z $SLOT ]; then [ $SLOT = _a ] && SLOT=_b || SLOT=_a; fi
if [ ! -z $SLOT ]; then
case $SLOT in
_a) SLOT=_b;;
_b) SLOT=_a;;
esac
fi
fi
find_boot_image
@ -128,7 +140,8 @@ case "$1" in
post-restore)
initialize
if $backuptool_ab; then
$BOOTMODE && su=su || su=sh
su=sh
$BOOTMODE && su=su
exec $su -c "sh $0 addond-v2"
else
# Run in background, hack for addon.d-v1

View File

@ -32,7 +32,14 @@
# Pure bash dirname implementation
getdir() {
case "$1" in
*/*) dir=${1%/*}; [ -z $dir ] && echo "/" || echo $dir ;;
*/*)
dir=${1%/*}
if [ -z $dir ]; then
echo "/"
else
echo $dir
fi
;;
*) echo "." ;;
esac
}

View File

@ -63,7 +63,8 @@ pgrep magiskd >/dev/null && pkill -9 magiskd
[ -f /system/bin/magisk ] && umount -l /system/bin
# SELinux stuffs
[ -e /sys/fs/selinux ] && SELINUX=true || SELINUX=false
SELINUX=false
[ -e /sys/fs/selinux ] && SELINUX=true
if $SELINUX; then
ln -sf ./magiskinit magiskpolicy
./magiskpolicy --live --magisk

View File

@ -14,7 +14,8 @@ setup_bb() {
export BBBIN
case "$1" in
"extract"|"-x")
[ -z "$2" ] && BBBIN=./busybox || BBBIN="$2"
BBBIN=./busybox
[ -z "$2" ] || BBBIN="$2"
extract_bb
;;
"sh")

View File

@ -12,7 +12,11 @@
###################
ui_print() {
$BOOTMODE && echo "$1" || echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
if $BOOTMODE; then
echo "$1"
else
echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD
fi
}
toupper() {
@ -64,7 +68,8 @@ print_title() {
local len line1len line2len pounds
line1len=$(echo -n $1 | wc -c)
line2len=$(echo -n $2 | wc -c)
[ $line1len -gt $line2len ] && len=$line1len || len=$line2len
len=$line2len
[ $line1len -gt $line2len ] && len=$line1len
len=$((len + 2))
pounds=$(printf "%${len}s" | tr ' ' '*')
ui_print "$pounds"
@ -258,8 +263,8 @@ mount_partitions() {
fi
mount -o bind /system_root/system /system
else
grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts \
&& SYSTEM_ROOT=true || SYSTEM_ROOT=false
SYSTEM_ROOT=false
grep ' / ' /proc/mounts | grep -qv 'rootfs' || grep -q ' /system_root ' /proc/mounts && SYSTEM_ROOT=true
fi
# /vendor is used only on some older devices for recovery AVBv1 signing so is not critical if fails
[ -L /system/vendor ] && mount_name vendor$SLOT /vendor '-o ro'
@ -426,7 +431,11 @@ install_magisk() {
$BOOTSIGNED && ui_print "- Boot image is signed with AVB 1.0"
fi
$IS64BIT && mv -f magiskinit64 magiskinit 2>/dev/null || rm -f magiskinit64
if $IS64BIT; then
mv -f magiskinit64 magiskinit 2>/dev/null
else
rm -f magiskinit64
fi
# Source the boot patcher
SOURCEDMODE=true
@ -511,7 +520,8 @@ check_data() {
# Test if DE storage is writable
$DATA && [ -d /data/adb ] && touch /data/adb/.rw && rm /data/adb/.rw && DATA_DE=true
fi
$DATA && NVBASE=/data || NVBASE=/cache/data_adb
NVBASE=/data
$DATA || NVBASE=/cache/data_adb
$DATA_DE && NVBASE=/data/adb
resolve_vars
}
@ -652,14 +662,18 @@ install_module() {
api_level_arch_detect
# Setup busybox and binaries
$BOOTMODE && boot_actions || recovery_actions
if $BOOTMODE; then
boot_actions
else
recovery_actions
fi
# Extract prop file
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
local MODDIRNAME
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
local MODDIRNAME=modules
$BOOTMODE && MODDIRNAME=modules_update
local MODULEROOT=$NVBASE/$MODDIRNAME
MODID=`grep_prop id $TMPDIR/module.prop`
MODNAME=`grep_prop name $TMPDIR/module.prop`