2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-10-31 09:20:23 +00:00
NanoDroid/Full/system/bin/nanodroid-overlay

253 lines
7.2 KiB
Plaintext
Raw Normal View History

2018-10-02 21:30:06 +00:00
#!/system/bin/sh
export MODID=@MODID@
export MODE=@MODE@
2018-10-02 21:30:06 +00:00
OVERLAY_PATH=""
[ -f /dev/tmp/install/CommonInstaller ] && MODE=${MODE}_INSTALL
[ -f /tmp/backuptool.functions ] && MODE=${MODE}_INSTALL
[ -f /postinstall/tmp/backuptool.functions ] && MODE=${MODE}_INSTALL
2020-10-18 07:42:02 +00:00
# detect whether we need to remount /system or / in system mode
if grep -q " $(readlink -f /system) " /proc/mounts 2>/dev/null; then
remount_point=/system
else remount_point=/
fi
2019-05-05 19:05:10 +00:00
error () {
echo "!! ${@}"
exit 1
}
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
if [ -d "/data/adb/modules_update/${MODID}" ]; then
OVERLAY_PATH="/data/adb/modules_update/${MODID}"
elif [ -d "/data/adb/modules/${MODID}" ]; then
OVERLAY_PATH="/data/adb/modules/${MODID}"
else
error "couldn't find NanoDroid!"
fi
2018-10-02 21:30:06 +00:00
fi
grep_prop() {
[ -f /vendor/build.prop ] && \
FILES="/system/build.prop /vendor/build.prop" || \
FILES="/system/build.prop"
sed -n "s/^${1}=//p" ${FILES} | head -n 1
}
2018-10-02 21:30:06 +00:00
show_help () {
echo "nanodroid-overlay
Magisk Mode: Manages Overlays (Pseudo Debloat feature)
System Mode: Manages Moved-Outs (Force Debloat feature)
Options Magisk Mode:
2018-10-02 21:30:06 +00:00
-a | --add [appname] add override for app [appname]
-r | --remove [appname] remove override for app [appname]
-s | --show show non-overriden /system applications
-l | --list show all overriden /system applications
-x | --create create all overrides
-u | --update update all overrides (= clear + create)
-c | --clear remove all overrides
-g | --genconfig (re-)create configuration from existing overrides
Options System Mode:
-a | --add [appname] add override for app [appname]
-r | --remove [appname] remove override for app [appname] from configuration
-s | --show show non-overriden /system applications
-x | --create create all overrides
2018-10-02 21:30:06 +00:00
"
exit 0
}
if [ "${MODE}" != "SYSTEM_INSTALL" -a "${MODE}" != "MAGISK_INSTALL" ]; then
2020-10-18 07:42:02 +00:00
test "$(whoami)" != "root" && error "not running as root"
fi
2018-10-02 21:30:06 +00:00
get_config () {
config=""
config_exists=0
for path in ${config_locations}; do
if test -r "${path}/${1}" -a -f "${path}/${1}"; then
config="${path}/${1}"
config_exists=1
return
fi
done
}
overrides_add_intern () {
sysdir=${1}
app=${2}
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
2018-10-02 21:30:06 +00:00
echo " creating overlay: ${app}"
2020-10-10 06:25:12 +00:00
mkdir -p "${OVERLAY_PATH}/${sysdir}/${app}"
touch "${OVERLAY_PATH}/${sysdir}/${app}/.replace"
2018-10-02 21:30:06 +00:00
else
echo " removing app: ${app}"
2020-10-10 06:25:12 +00:00
rm -rf "${sysdir}/${app}"
2018-10-02 21:30:06 +00:00
fi
grep -q "^${app}$" "${config}" 2>/dev/null || echo "${app}" >> "${config}"
2018-10-02 21:30:06 +00:00
}
overrides_add () {
2020-10-18 07:42:02 +00:00
[ "${MODE}" = "SYSTEM" ] && mount -orw,remount ${remount_point}
2018-10-02 21:30:06 +00:00
for app in ${@}; do
for path in ${app_locations}; do
2020-10-10 06:14:58 +00:00
[ -d ${path}/${app} ] && overrides_add_intern ${path} ${app}
done
2018-10-02 21:30:06 +00:00
done
2020-10-18 07:42:02 +00:00
[ "${MODE}" = "SYSTEM" ] && mount -oro,remount ${remount_point}
2018-10-02 21:30:06 +00:00
}
overrides_remove_intern () {
sysdir=${1}
app=${2}
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
2018-10-02 21:30:06 +00:00
echo " removing overlay: ${app}"
2020-10-10 06:25:12 +00:00
rm -rf "${OVERLAY_PATH}/${sysdir}/${app}"
2018-10-02 21:30:06 +00:00
else
echo " overrides_remove() does nothing in System Mode!"
2018-10-02 21:30:06 +00:00
fi
sed -e "/^${app}$/d" -i "${config}"
}
overrides_remove () {
for app in ${@}; do
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
for path in ${app_locations}; do
2020-10-10 06:14:58 +00:00
[ -f ${OVERLAY_PATH}/${path}/${app}/.replace ] && overrides_remove_intern ${path} ${app}
done
2018-10-02 21:30:06 +00:00
else
# only remove entry from config file (if it exists)
overrides_remove_intern app ${app}
2018-10-02 21:30:06 +00:00
fi
done
2018-10-02 21:30:06 +00:00
}
overrides_list () {
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
for path in ${app_locations}; do
2020-10-10 06:03:47 +00:00
if [ -d ${OVERLAY_PATH}/${path} ]; then
2020-10-10 06:10:12 +00:00
app_int=""
2020-10-10 09:43:34 +00:00
echo -e "\n ** Overrides for ${path}:"
for app in $(find "${OVERLAY_PATH}/${path}" -name "*.replace"); do
app_int="\n * $(basename $(dirname "${app}"))${app_int}"
done
echo -e "${app_int}" | sort
fi
2018-10-02 21:30:06 +00:00
done
else
echo " overrides_list() does nothing in System Mode!"
2018-10-02 21:30:06 +00:00
fi
}
overrides_list_non () {
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
for path in ${app_locations}; do
if [ -d ${path} ]; then
2020-10-10 06:10:12 +00:00
app_int=""
2020-10-10 09:43:34 +00:00
echo -e "\n ** Non-Overriden apps for ${path}:"
for app in $(find "${path}" -mindepth 1 -maxdepth 1 -type d); do
[ ! -d ${OVERLAY_PATH}/${app} ] && app_int="\n * $(basename ${app})${app_int}"
done
echo -e "${app_int}" | sort
fi
2018-10-02 21:30:06 +00:00
done
else
for path in ${app_locations}; do
if [ -d ${path} ]; then
2020-10-10 09:43:34 +00:00
echo -e "\n ** Non-Overriden apps for ${path}:"
for app in $(find "${path}" -mindepth 1 -maxdepth 1 -type d); do
app_int="\n * $(basename ${app})${app_int}"
done
echo -e "${app_int}" | sort
fi
2018-10-02 21:30:06 +00:00
done
fi
}
overrides_clear () {
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
2018-10-02 21:30:06 +00:00
echo " removing Overlays from ${OVERLAY_PATH}"
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/reserve" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/product/app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/product/priv-app" -name "*.replace" 2>/dev/null) ; do
2018-10-02 21:30:06 +00:00
echo " removing override: $(basename $(dirname ${app}))"
rm -rf "$(dirname "${app}")"
done
else
echo " overrides_clear() does nothing in System Mode!"
fi
}
overrides_genconfig () {
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
2018-10-02 21:30:06 +00:00
rm -f ${config}
2019-01-04 20:24:18 +00:00
touch ${config}
2018-10-02 21:30:06 +00:00
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/reserve" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/product/app" -name "*.replace" 2>/dev/null) \
$(find "${OVERLAY_PATH}/system/product/priv-app" -name "*.replace" 2>/dev/null); do
2018-10-02 21:30:06 +00:00
xapp=$(basename $(dirname ${app}))
echo " adding ${xapp} to configuration"
2019-01-04 20:24:18 +00:00
grep -q "^${xapp}$" "${config}" 2>/dev/null || echo "${xapp}" >> "${config}"
2018-10-02 21:30:06 +00:00
done
else
echo " overrides_genconfig() does nothing in System Mode!"
fi
}
# check for configuration files
config_locations="/data/media/0 /external_sd /sdcard1 /data /system/addon.d /tmp"
2020-10-23 17:19:20 +00:00
media_rw=$(grep "^/dev/block.*/mnt/media_rw" /proc/mounts \
| cut -d " " -f 2 \
| cut -d "/" -f 4)
ext_storage="/storage/${media_rw}"
[ -r "${ext_storage}" ] && config_locations="${ext_storage} ${config_locations}"
2018-10-02 21:30:06 +00:00
get_config .nanodroid-overlay
app_locations="/system/app /system/priv-app /system/reserve /system/product/app /system/product/priv-app"
[[ -f ${config} ]] && export config || config=/data/media/0/.nanodroid-overlay
2018-10-02 21:30:06 +00:00
opt=${1}
[[ -z ${opt} ]] && show_help || shift
case ${opt} in
-l | --list ) overrides_list ;;
-a | --add ) overrides_add "${@}" ;;
-r | --remove ) overrides_remove "${@}" ;;
-s | --show ) overrides_list_non ;;
-c | --clear ) overrides_clear ;;
2020-09-08 20:25:12 +00:00
-x | --create ) overrides_add "$(grep -E -v '^(#|[[:space:]]*$)' "${config}")" ;;
2018-10-02 21:30:06 +00:00
-g | --genconfig ) overrides_genconfig ;;
-u | --update )
[ "${MODE}" = "MAGISK" ] && overrides_clear
2020-09-08 20:25:12 +00:00
overrides_add "$(grep -E -v '^(#|[[:space:]]*$)' "${config}")"
2018-10-02 21:30:06 +00:00
;;
* ) show_help ;;
esac