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

234 lines
6.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
2019-05-05 19:05:10 +00:00
error () {
echo "!! ${@}"
exit 1
}
if [ "${MODE}" = "SYSTEM" ]; then
2018-10-02 21:30:06 +00:00
OVERLAY_PATH=""
else
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
}
test "$(whoami)" != "root" && error "not running as root"
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" ]; then
2018-10-02 21:30:06 +00:00
echo " creating overlay: ${app}"
mkdir -p "${OVERLAY_PATH}/system/${sysdir}/${app}"
touch "${OVERLAY_PATH}/system/${sysdir}/${app}/.replace"
else
echo " removing app: ${app}"
rm -rf "/system/${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 () {
[ "${MODE}" = "SYSTEM" ] && mount -orw,remount /system
2018-10-02 21:30:06 +00:00
for app in ${@}; do
for path in ${app_locations}; do
[ -d ${path}/${app} ] && overrides_add_intern app ${app}
done
2018-10-02 21:30:06 +00:00
done
[ "${MODE}" = "SYSTEM" ] && mount -oro,remount /system
2018-10-02 21:30:06 +00:00
}
overrides_remove_intern () {
sysdir=${1}
app=${2}
if [ "${MODE}" = "MAGISK" ]; then
2018-10-02 21:30:06 +00:00
echo " removing overlay: ${app}"
rm -rf "${OVERLAY_PATH}/system/${sysdir}/${app}"
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" ]; then
for path in ${app_locations}; do
[ -f ${OVERLAY_PATH}/${path}/${app}/.replace ] && overrides_add_intern app ${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" ]; 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=""
echo "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" ]; then
for path in ${app_locations}; do
if [ -d ${path} ]; then
2020-10-10 06:10:12 +00:00
app_int=""
echo "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
echo "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" ]; 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" ]; 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"
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"
2019-05-05 19:05:10 +00:00
[[ -f ${config} ]] && export config || config=${STORAGE}/.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