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

216 lines
5.9 KiB
Plaintext
Raw Normal View History

#!/system/bin/sh
2018-01-23 20:11:52 +00:00
export NO_MAGISK=0
export MODPATH=@MODPATH@
if [[ -d /dev/tmp/magisk_img/$(basename ${MODPATH}) ]]; then
OVERLAY_PATH=/dev/tmp/magisk_img/$(basename ${MODPATH})
elif [[ -d /dev/tmp/magisk_merge_img/$(basename ${MODPATH}) ]]; then
OVERLAY_PATH=/dev/tmp/magisk_merge_img/$(basename ${MODPATH})
else
OVERLAY_PATH=${MODPATH}
[[ "${MODPATH}" != "/sbin/.core/"* ]] && NO_MAGISK=1
fi
error () {
echo "!! ${@}"
exit 1
}
show_help () {
echo "nanodroid-overlay
Magisk Mode: Manages Overlays (Pseudo Debloat feature)
System Mode: Manages Moved-Outs (Force Debloat feature)
Options:
-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
"
exit 0
}
[[ $(whoami) != "root" ]] && error "not running as root"
2018-01-23 20:11:52 +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
}
2018-04-20 18:03:05 +00:00
overrides_add_intern () {
app=$(basename ${1})
if [[ ${NO_MAGISK} -eq 0 ]]; then
echo " creating overlay: ${app}"
mkdir -p "${OVERLAY_PATH}/system/${1}"
touch "${OVERLAY_PATH}/system/${1}/.replace"
else
echo " moving to /sdcard/nanodroid_backups: ${app}"
rm -rf "/sdcard/nanodroid_backups/${1}"
mv "/system/${1}" "/sdcard/nanodroid_backups/${1}"
fi
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
grep -q "^${app}" "${config}" || echo "${app}" >> "${config}"
2018-01-23 20:11:52 +00:00
}
2018-04-20 18:03:05 +00:00
overrides_add () {
for app in ${@}; do
[[ -d /system/app/${app} ]] && overrides_add_intern app/${app}
[[ -d /system/priv-app/${app} ]] && overrides_add_intern priv-app/${app}
2018-01-23 20:11:52 +00:00
done
}
2018-04-20 18:03:05 +00:00
overrides_remove_intern () {
app=$(basename ${1})
if [[ ${NO_MAGISK} -eq 0 ]]; then
echo " removing overlay: ${app}"
rm -rf "${OVERLAY_PATH}/system/${1}"
else
if [[ -d /system/${1} ]]; then
echo " removing old backup: ${app}"
rm -rf "/sdcard/nanodroid_backups/${1}"
else
echo " reinstalling: ${app}"
mv "/sdcard/nanodroid_backups/${1}" "/system/${1}"
2018-01-23 20:11:52 +00:00
fi
2018-04-20 18:03:05 +00:00
fi
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
sed -e "/^${app}$/d" -i "${config}"
}
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
overrides_remove () {
for app in ${@}; do
if [[ ${NO_MAGISK} -eq 0 ]]; then
[[ -f ${OVERLAY_PATH}/system/app/${app}/.replace ]] && overrides_remove_intern app/${app}
[[ -f ${OVERLAY_PATH}/system/priv-app/${app}/.replace ]] && overrides_remove_intern priv-app/${app}
else
[[ -d /sdcard/nanodroid_backups/app/${app} ]] && overrides_remove_intern app/${app}
[[ -d /sdcard/nanodroid_backups/priv-app/${app} ]] && overrides_remove_intern priv-app/${app}
2018-01-23 20:11:52 +00:00
fi
done
2018-04-20 18:03:05 +00:00
}
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
overrides_list () {
if [[ ${NO_MAGISK} -eq 0 ]]; then
echo "Overrides for /system/app:"
2018-04-22 18:19:05 +00:00
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace"); do
2018-04-20 18:03:05 +00:00
echo " * $(basename $(dirname "${app}"))"
done
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
echo "Overrides for /system/priv-app:"
2018-04-22 18:19:05 +00:00
for app in $(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace"); do
2018-04-20 18:03:05 +00:00
echo " * $(basename $(dirname "${app}"))"
done
else
echo "Moved-Out apps from /system/app:"
for app in $(find "/sdcard/nanodroid_backups/app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
echo " * $(basename $(dirname "${app}"))"
done
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
echo "Moved-Out apps from /system/priv-app:"
for app in $(find "/sdcard/nanodroid_backups/priv-app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
echo " * $(basename $(dirname "${app}"))"
done
fi
2018-01-23 20:11:52 +00:00
}
2018-04-20 18:03:05 +00:00
overrides_list_non () {
if [[ ${NO_MAGISK} -eq 0 ]]; then
echo "non-overriden apps from /system/app:"
for app in $(find "/system/app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
[[ ! -f ${OVERLAY_PATH}/${app}/.replace ]] && echo " * $(basename ${app})"
done
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
echo "non-overriden apps from /system/priv-app:"
for app in $(find "/system/priv-app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
[[ ! -f ${OVERLAY_PATH}/${app}/.replace ]] && echo " * $(basename ${app})"
done
else
echo "non-moved-out apps from /system/app:"
for app in $(find "/system/app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
echo " * $(basename ${app})"
done
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
echo "non-moved-out apps from /system/priv-app:"
for app in $(find "/system/priv-app" -mindepth 1 -maxdepth 1 -type d); do
2018-04-20 18:03:05 +00:00
echo " * $(basename ${app})"
done
fi
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
}
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
overrides_clear () {
if [[ ${NO_MAGISK} -eq 0 ]]; then
echo " removing Overlays from ${OVERLAY_PATH}"
2018-04-22 18:19:05 +00:00
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace") \
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace"); do
2018-04-20 18:03:05 +00:00
echo " removing override: $(basename $(dirname ${app}))"
rm -rf "$(dirname "${app}")"
2018-01-23 20:11:52 +00:00
done
2018-04-20 18:03:05 +00:00
else
echo " overrides_clear() does nothing in System Mode!"
2018-01-23 20:11:52 +00:00
fi
2018-04-20 18:03:05 +00:00
}
overrides_genconfig () {
if [[ ${NO_MAGISK} -eq 0 ]]; then
rm -f ${config}
export config="/data/.nanodroid-overlay"
2018-01-23 20:11:52 +00:00
2018-04-22 18:19:05 +00:00
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace") \
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace"); do
2018-01-23 20:11:52 +00:00
xapp=$(basename $(dirname ${app}))
echo " adding ${xapp} to configuration"
2018-04-20 18:03:05 +00:00
grep -q "^${xapp}$" "${config}" || echo "${xapp}" >> "${config}"
2018-01-23 20:11:52 +00:00
done
2018-04-20 18:03:05 +00:00
else
echo " overrides_genconfig() does nothing in System Mode!"
2018-01-23 20:11:52 +00:00
fi
}
# check for configuration files
config_locations="/sdcard /external_sd @ZIPDIR@ /data /dev/tmp/install"
get_config .nanodroid-overlay
if [[ -f ${config} ]]; then
export config
2018-04-20 18:03:05 +00:00
else overrides_genconfig
2018-01-23 20:11:52 +00:00
fi
2018-04-20 18:03:05 +00:00
opt=${1}
[[ -z ${opt} ]] && show_help || shift
2018-01-23 20:11:52 +00:00
2018-04-20 18:03:05 +00:00
case ${opt} in
-l | --list ) overrides_list ;;
-a | --add ) overrides_add "${@}" ;;
-r | --remove ) remove_overrides "${@}" ;;
-s | --show ) overrides_list_non ;;
-c | --clear ) overrides_clear ;;
-x | --create ) overrides_add "$(cat "${config}")" ;;
-g | --genconfig ) overrides_genconfig ;;
2018-01-23 20:11:52 +00:00
-u | --update )
2018-04-20 18:03:05 +00:00
overrides_clear
overrides_add "$(cat "${config}")"
2018-01-23 20:11:52 +00:00
;;
* ) show_help ;;
2018-01-23 20:11:52 +00:00
esac