2
0
mirror of https://gitlab.com/Nanolx/NanoDroid synced 2024-11-02 03:40:13 +00:00

fix scripts

This commit is contained in:
Christopher Roy Bratusek 2018-10-02 23:30:06 +02:00
parent 68d8f6fab8
commit 08f27a9b30
2 changed files with 221 additions and 72 deletions

View File

@ -0,0 +1,221 @@
#!/system/bin/sh
export NO_MAGISK=0
export MODPATH=@MODPATH@
if [ -z "${MODPATH}" ]; then
OVERLAY_PATH=""
NO_MAGISK=1
elif [ -d "/dev/tmp/magisk_img/$(basename "${MODPATH}")" ]; then
OVERLAY_PATH="/dev/tmp/magisk_img/$(basename "${MODPATH}")"
elif [ -d "${MODPATH}" ]; then
OVERLAY_PATH="${MODPATH}"
else
echo "couldn't find NanoDroid!"
exit 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
}
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 [[ ${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 "/sdcard/nanodroid_backups/${sysdir}"
echo " moving to /sdcard/nanodroid_backups: ${app}"
rm -rf "/sdcard/nanodroid_backups/${sysdir}/${app}"
mv "/system/${sysdir}/${app}" "/sdcard/nanodroid_backups/${sysdir}/"
fi
grep -q "^${app}" "${config}" || echo "${app}" >> "${config}"
}
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}
done
}
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 "/sdcard/nanodroid_backups/${sysdir}/${app}"
else
echo " reinstalling: ${app}"
mv "/sdcard/nanodroid_backups/${sysdir}/${app}" "/system/${sysdir}/"
fi
fi
sed -e "/^${app}$/d" -i "${config}"
}
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}
fi
done
}
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
else
echo "Moved-Out apps from /system/app:"
for app in $(find "/sdcard/nanodroid_backups/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 "/sdcard/nanodroid_backups/priv-app" -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
[[ ! -f ${OVERLAY_PATH}/${app}/.replace ]] && 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
[[ ! -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
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
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"); 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"
for app in $(find "${OVERLAY_PATH}/system/app" -name "*.replace") \
$(find "${OVERLAY_PATH}/system/priv-app" -name "*.replace"); do
xapp=$(basename $(dirname ${app}))
echo " adding ${xapp} to configuration"
grep -q "^${xapp}$" "${config}" || echo "${xapp}" >> "${config}"
done
else
echo " overrides_genconfig() does nothing in System Mode!"
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
else overrides_genconfig
fi
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

View File

@ -1,72 +0,0 @@
#!/system/bin/sh
APK_DIR=/sdcard/nanodroid_apks
nlx="https://www.nanolx.org/apk"
update_apk () {
if $(busybox wget --help 2>/dev/null); then
mkdir -p ${APK_DIR}
apk=${1}
apk_p=$(basename ${apk} .apk)
apk_o=$(basename ${apk})
if [[ -f ${MODPATH}/system/${apk} ]]; then
echo -e "\nUpdating: ${apk_p}"
rm -f ${APK_DIR}/${apk_o}
busybox wget ${2} -O ${APK_DIR}/${apk_o} || error "failed to download ${apk_p}"
pm install -r ${APK_DIR}/${apk_o} || error "failed to install ${apk_p}"
fi
else
error "wget is not installed, install Busybox"
fi
}
error () {
echo "!! ${@}"
exit 1
}
[[ $(whoami) != "root" ]] && error "not running as root"
case ${1} in
ps | playstore )
update_apk priv-app/Phonesky/Phonesky.apk "${nlx}/Phonesky.apk"
;;
#ol | openlauncher )
# update_apk app/OpenLauncher/OpenLauncher.apk "${nlx}/OpenLauncher.apk"
#;;
mpv | MPV )
update_apk app/MPV/MPV.apk "${nlx}/MPV.apk"
;;
fs | fakestore )
update_apk priv-app/FakeStore/FakeStore.apk "${nlx}/FakeStore.apk"
;;
mg | microG )
update_apk priv-app/GmsCore/GmsCore.apk "${nlx}/GmsCore.apk"
;;
dg | DroidGuard )
update_apk priv-app/DroidGuard/DroidGuard.apk "${nlx}/DroidGuard.apk"
;;
* )
echo "nanodroid-upd
Utility to update custon NanoDroid apks
Usage: nanodroid-upd <apk>
short | long apk name
ps | playstore
fs | fakestore
mpv | MPV
mg | microG
dg | DroidGuard"
;;
esac