2018-10-02 21:30:06 +00:00
|
|
|
#!/system/bin/sh
|
|
|
|
|
2020-08-18 16:13:09 +00:00
|
|
|
export MODID=@MODID@
|
|
|
|
export MODE=@MODE@
|
2018-10-02 21:30:06 +00:00
|
|
|
|
2020-10-17 21:16:41 +00:00
|
|
|
OVERLAY_PATH=""
|
|
|
|
|
2020-10-21 17:03:45 +00:00
|
|
|
[ -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-17 21:02:23 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-21 17:03:45 +00:00
|
|
|
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
|
2020-08-18 16:13:09 +00:00
|
|
|
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
|
|
|
|
|
2019-01-17 18:41:02 +00:00
|
|
|
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)
|
|
|
|
|
2020-10-08 20:06:11 +00:00
|
|
|
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
|
2020-10-08 20:06:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-21 17:03:45 +00:00
|
|
|
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}
|
|
|
|
|
2020-10-21 17:03:45 +00:00
|
|
|
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
|
2020-10-08 20:06:11 +00:00
|
|
|
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
|
|
|
|
|
2019-01-26 09:52:48 +00:00
|
|
|
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}
|
2019-01-11 16:56:00 +00:00
|
|
|
|
2018-10-02 21:30:06 +00:00
|
|
|
for app in ${@}; do
|
2020-10-08 20:06:11 +00:00
|
|
|
for path in ${app_locations}; do
|
2020-10-10 06:14:58 +00:00
|
|
|
[ -d ${path}/${app} ] && overrides_add_intern ${path} ${app}
|
2020-10-08 20:06:11 +00:00
|
|
|
done
|
2018-10-02 21:30:06 +00:00
|
|
|
done
|
2019-01-11 16:56:00 +00:00
|
|
|
|
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}
|
|
|
|
|
2020-10-21 17:03:45 +00:00
|
|
|
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
|
2020-10-08 20:06:11 +00:00
|
|
|
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
|
2020-10-21 17:03:45 +00:00
|
|
|
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
|
2020-10-08 20:06:11 +00:00
|
|
|
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}
|
2020-10-08 20:06:11 +00:00
|
|
|
done
|
2018-10-02 21:30:06 +00:00
|
|
|
else
|
2020-10-08 20:06:11 +00:00
|
|
|
# only remove entry from config file (if it exists)
|
|
|
|
overrides_remove_intern app ${app}
|
2018-10-02 21:30:06 +00:00
|
|
|
fi
|
|
|
|
done
|
2019-01-11 16:56:00 +00:00
|
|
|
|
2018-10-02 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
overrides_list () {
|
2020-10-21 17:03:45 +00:00
|
|
|
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
|
2020-10-08 20:06:11 +00:00
|
|
|
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}:"
|
2020-10-08 20:06:11 +00:00
|
|
|
for app in $(find "${OVERLAY_PATH}/${path}" -name "*.replace"); do
|
2020-10-08 20:16:17 +00:00
|
|
|
app_int="\n * $(basename $(dirname "${app}"))${app_int}"
|
2020-10-08 20:06:11 +00:00
|
|
|
done
|
2020-10-08 20:16:17 +00:00
|
|
|
echo -e "${app_int}" | sort
|
2020-10-08 20:06:11 +00:00
|
|
|
fi
|
2018-10-02 21:30:06 +00:00
|
|
|
done
|
|
|
|
else
|
2020-10-08 20:06:11 +00:00
|
|
|
echo " overrides_list() does nothing in System Mode!"
|
2018-10-02 21:30:06 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides_list_non () {
|
2020-10-21 17:03:45 +00:00
|
|
|
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
|
2020-10-08 20:06:11 +00:00
|
|
|
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}:"
|
2020-10-08 20:06:11 +00:00
|
|
|
for app in $(find "${path}" -mindepth 1 -maxdepth 1 -type d); do
|
2020-10-08 20:16:17 +00:00
|
|
|
[ ! -d ${OVERLAY_PATH}/${app} ] && app_int="\n * $(basename ${app})${app_int}"
|
2020-10-08 20:06:11 +00:00
|
|
|
done
|
2020-10-08 20:16:17 +00:00
|
|
|
echo -e "${app_int}" | sort
|
2020-10-08 20:06:11 +00:00
|
|
|
fi
|
2018-10-02 21:30:06 +00:00
|
|
|
done
|
|
|
|
else
|
2020-10-08 20:06:11 +00:00
|
|
|
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}:"
|
2020-10-08 20:06:11 +00:00
|
|
|
for app in $(find "${path}" -mindepth 1 -maxdepth 1 -type d); do
|
2020-10-08 20:16:17 +00:00
|
|
|
app_int="\n * $(basename ${app})${app_int}"
|
2020-10-08 20:06:11 +00:00
|
|
|
done
|
2020-10-08 20:16:17 +00:00
|
|
|
echo -e "${app_int}" | sort
|
2020-10-08 20:06:11 +00:00
|
|
|
fi
|
2018-10-02 21:30:06 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides_clear () {
|
2020-10-21 17:03:45 +00:00
|
|
|
if [ "${MODE}" = "MAGISK" -o "${MODE}" = "MAGISK_INSTALL" ]; then
|
2018-10-02 21:30:06 +00:00
|
|
|
echo " removing Overlays from ${OVERLAY_PATH}"
|
2019-10-08 18:44:52 +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
|
|
|
echo " removing override: $(basename $(dirname ${app}))"
|
|
|
|
rm -rf "$(dirname "${app}")"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo " overrides_clear() does nothing in System Mode!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
overrides_genconfig () {
|
2020-10-21 17:03:45 +00:00
|
|
|
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
|
|
|
|
2019-10-08 18:44:52 +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
|
2020-10-08 20:06:11 +00:00
|
|
|
config_locations="/data/media/0 /external_sd /sdcard1 /data"
|
2018-10-02 21:30:06 +00:00
|
|
|
get_config .nanodroid-overlay
|
|
|
|
|
2020-10-08 20:06:11 +00:00
|
|
|
app_locations="/system/app /system/priv-app /system/reserve /system/product/app /system/product/priv-app"
|
|
|
|
|
2020-10-19 19:23:11 +00:00
|
|
|
[[ -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 )
|
2020-10-08 20:06:11 +00:00
|
|
|
[ "${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
|
2019-01-07 19:32:53 +00:00
|
|
|
|