mirror of
https://gitlab.com/Nanolx/NanoDroid
synced 2024-10-31 09:20:23 +00:00
275 lines
7.8 KiB
Bash
Executable File
275 lines
7.8 KiB
Bash
Executable File
#!/system/bin/sh
|
|
|
|
export NO_MAGISK=0
|
|
export SYS_REMOUNT=0
|
|
export MODPATH=@MODPATH@
|
|
|
|
error () {
|
|
echo "!! ${@}"
|
|
exit 1
|
|
}
|
|
|
|
if [ -z "${MODPATH}" ]; then
|
|
OVERLAY_PATH=""
|
|
NO_MAGISK=1
|
|
[ ! -d /twres ] && SYS_REMOUNT=1
|
|
elif [ -d "${MODPATH}" ]; then
|
|
OVERLAY_PATH="${MODPATH}"
|
|
else
|
|
error "couldn't find NanoDroid!"
|
|
fi
|
|
|
|
# select storage path
|
|
if [ -n ${EXTERNAL_STORAGE} ]; then
|
|
STORAGE="${EXTERNAL_STORAGE}"
|
|
else
|
|
if [ -w /sdcard ]; then
|
|
STORAGE="/sdcard"
|
|
elif [ -w /storage/self/primary ]; then
|
|
STORAGE="/storage/self/primary"
|
|
elif [ -w /data/media/0 ]; then
|
|
STORAGE="/data/media/0"
|
|
fi
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
test "$(whoami)" != "root" && error "not running as root"
|
|
|
|
SYS_BACKUP_PATH="${STORAGE}/nanodroid_backups/$(grep_prop ro.build.flavor)_$(grep_prop ro.build.id)"
|
|
|
|
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 [[ ${NO_MAGISK} -eq 0 ]]; then
|
|
echo " creating overlay: ${app}"
|
|
mkdir -p "${OVERLAY_PATH}/system/${sysdir}/${app}"
|
|
touch "${OVERLAY_PATH}/system/${sysdir}/${app}/.replace"
|
|
else
|
|
mkdir -p "${SYS_BACKUP_PATH}/${sysdir}"
|
|
echo " moving to ${STORAGE}/nanodroid_backups: ${app}"
|
|
rm -rf "${SYS_BACKUP_PATH}/${sysdir}/${app}"
|
|
mv "/system/${sysdir}/${app}" "${SYS_BACKUP_PATH}/${sysdir}/"
|
|
fi
|
|
|
|
grep -q "^${app}$" "${config}" 2>/dev/null || echo "${app}" >> "${config}"
|
|
}
|
|
|
|
overrides_add () {
|
|
[[ ${SYS_REMOUNT} -eq 1 ]] && mount -orw,remount /system
|
|
|
|
for app in ${@}; do
|
|
[ -d /system/app/${app} ] && overrides_add_intern app ${app}
|
|
[ -d /system/priv-app/${app} ] && overrides_add_intern priv-app ${app}
|
|
[ -d /system/reserve/${app} ] && overrides_add_intern reserve ${app}
|
|
done
|
|
|
|
[[ ${SYS_REMOUNT} -eq 1 ]] && mount -oro,remount /system
|
|
}
|
|
|
|
overrides_remove_intern () {
|
|
sysdir=${1}
|
|
app=${2}
|
|
|
|
if [[ ${NO_MAGISK} -eq 0 ]]; then
|
|
echo " removing overlay: ${app}"
|
|
rm -rf "${OVERLAY_PATH}/system/${sysdir}/${app}"
|
|
else
|
|
if [[ -d /system/${sysdir}/${app} ]]; then
|
|
echo " removing old backup: ${app}"
|
|
rm -rf "${SYS_BACKUP_PATH}/${sysdir}/${app}"
|
|
else
|
|
echo " reinstalling: ${app}"
|
|
mv "${SYS_BACKUP_PATH}/${sysdir}/${app}" "/system/${sysdir}/"
|
|
fi
|
|
fi
|
|
|
|
sed -e "/^${app}$/d" -i "${config}"
|
|
}
|
|
|
|
overrides_remove () {
|
|
[[ ${SYS_REMOUNT} -eq 1 ]] && mount -orw,remount /system
|
|
|
|
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}
|
|
[ -f ${OVERLAY_PATH}/system/reserve/${app}/.replace ] && overrides_remove_intern reserve ${app}
|
|
else
|
|
[ -d ${STORAGE}/nanodroid_backups/app/${app} ] && overrides_remove_intern app ${app}
|
|
[ -d ${STORAGE}/nanodroid_backups/priv-app/${app} ] && overrides_remove_intern priv-app ${app}
|
|
[ -d ${STORAGE}/nanodroid_backups/reserve/${app} ] && overrides_remove_intern reserve ${app}
|
|
fi
|
|
done
|
|
|
|
[[ ${SYS_REMOUNT} -eq 1 ]] && mount -oro,remount /system
|
|
}
|
|
|
|
overrides_list () {
|
|
if [[ ${NO_MAGISK} -eq 0 ]]; then
|
|
echo "Overrides for /system/app:"
|
|
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace"); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
|
|
echo "Overrides for /system/priv-app:"
|
|
for app in $(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace"); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
|
|
echo "Overrides for /system/reserve:"
|
|
for app in $(find "${OVERLAY_PATH}/system/reserve" -name "*.replace"); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
else
|
|
echo "Moved-Out apps from /system/app:"
|
|
for app in $(find "${SYS_BACKUP_PATH}/app" -mindepth 1 -maxdepth 1 -type d); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
|
|
echo "Moved-Out apps from /system/priv-app:"
|
|
for app in $(find "${SYS_BACKUP_PATH}/priv-app" -mindepth 1 -maxdepth 1 -type d); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
|
|
echo "Moved-Out apps from /system/reserve:"
|
|
for app in $(find "${SYS_BACKUP_PATH}/reserve" -mindepth 1 -maxdepth 1 -type d); do
|
|
echo " * $(basename $(dirname "${app}"))"
|
|
done
|
|
fi
|
|
}
|
|
|
|
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
|
|
[[ ! -d ${OVERLAY_PATH}/${app} ]] && echo " * $(basename ${app})"
|
|
done
|
|
|
|
echo "non-overriden apps from /system/priv-app:"
|
|
for app in $(find "/system/priv-app" -mindepth 1 -maxdepth 1 -type d); do
|
|
[[ ! -d ${OVERLAY_PATH}/${app} ]] && echo " * $(basename ${app})"
|
|
done
|
|
|
|
echo "non-overriden apps from /system/reserve:"
|
|
for app in $(find "/system/reserve" -mindepth 1 -maxdepth 1 -type d); do
|
|
[[ ! -d ${OVERLAY_PATH}/${app} ]] && 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
|
|
echo " * $(basename ${app})"
|
|
done
|
|
|
|
echo "non-moved-out apps from /system/priv-app:"
|
|
for app in $(find "/system/priv-app" -mindepth 1 -maxdepth 1 -type d); do
|
|
echo " * $(basename ${app})"
|
|
done
|
|
|
|
echo "non-moved-out apps from /system/reserve:"
|
|
for app in $(find "/system/reserve" -mindepth 1 -maxdepth 1 -type d); do
|
|
echo " * $(basename ${app})"
|
|
done
|
|
fi
|
|
|
|
}
|
|
|
|
overrides_clear () {
|
|
if [[ ${NO_MAGISK} -eq 0 ]]; then
|
|
echo " removing Overlays from ${OVERLAY_PATH}"
|
|
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace") \
|
|
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace") \
|
|
$(find "${OVERLAY_PATH}/system/reserve" -name "*.replace") ; do
|
|
echo " removing override: $(basename $(dirname ${app}))"
|
|
rm -rf "$(dirname "${app}")"
|
|
done
|
|
else
|
|
echo " overrides_clear() does nothing in System Mode!"
|
|
fi
|
|
}
|
|
|
|
overrides_genconfig () {
|
|
if [[ ${NO_MAGISK} -eq 0 ]]; then
|
|
rm -f ${config}
|
|
export config="/data/.nanodroid-overlay"
|
|
touch ${config}
|
|
|
|
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace") \
|
|
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace") \
|
|
$(find "${OVERLAY_PATH}/system/reserve" -name "*.replace") ; do
|
|
xapp=$(basename $(dirname ${app}))
|
|
echo " adding ${xapp} to configuration"
|
|
grep -q "^${xapp}$" "${config}" 2>/dev/null || echo "${xapp}" >> "${config}"
|
|
done
|
|
else
|
|
echo " overrides_genconfig() does nothing in System Mode!"
|
|
fi
|
|
}
|
|
|
|
# check for configuration files
|
|
config_locations="/data/media/0 /external_sd /sdcard1 /data @ZIPDIR@ /dev/tmp/install"
|
|
get_config .nanodroid-overlay
|
|
|
|
[[ -f ${config} ]] && export config || config=${STORAGE}/.nanodroid-overlay
|
|
|
|
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 ;;
|
|
-x | --create ) overrides_add "$(cat "${config}")" ;;
|
|
-g | --genconfig ) overrides_genconfig ;;
|
|
|
|
-u | --update )
|
|
overrides_clear
|
|
overrides_add "$(cat "${config}")"
|
|
;;
|
|
|
|
* ) show_help ;;
|
|
esac
|
|
|