-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `acc-en` executable for front-ends (to ensure acc language is always English) - `acc -I|--lang`: Show available, as well as the default and currently set languages - `acc -P|--performance`: accd performance monitor (htop) - `acc --upgrade`: always use current `installDir` - Attribute back-end files ownership to front-end app - Automatically copy installation log to <front-end app data>/files/logs/ - Back-end can be upgraded from Magisk Manager, EX/FK Kernel Manager, and similar apps (alternative to `acc --upgrade`) - `bundle.sh` - bundler for front-end app - Default loopDelay: 10,15 (plugged,unplugged) - Default resume capacity: 75 - Dynamic power saving and voltage control enhancements - Enhanced power supply logger (psl.sh) - Fixed busybox and `loopDelay` handling issues - Fixed `coolDownRatio` delays - Flashable uninstaller: `/sdcard/acc-uninstaller.zip` - `forceStatusAt100=status#`: force android to report a specific battery status (e.g., fully charged, value 5 for Pixel devices) at 100% capacity - Major optimizations - Prioritize `nano -l` for text editing - Renamed `chargingVoltageLimit` variable to `maxChargingVoltage` - Richer installation and initialization logs (/data/adb/acc-data/logs/) - Simplified Chinese translation (zh-rCN) by zjns @github - Updated `build.sh` and documentation - Updated Telegram group link (`t.me/acc_group/`) - Use `umask 077` everywhere - Workaround for front-end autostart blockage (Magisk service.d script) > Note: this version resets config to default to fix common issues and add new settings.
- Loading branch information
Showing
27 changed files
with
1,460 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,223 @@ | ||
#!/sbin/sh | ||
|
||
TMPDIR=/dev/tmp | ||
MOUNTPATH=/dev/magisk_img | ||
|
||
# Default permissions | ||
umask 022 | ||
#!/system/bin/sh | ||
# $id Installer/Upgrader | ||
# Copyright (c) 2019, VR25 (xda-developers.com) | ||
# License: GPLv3+ | ||
|
||
set +x | ||
echo | ||
id=acc | ||
umask 077 | ||
|
||
# log | ||
mkdir -p /data/adb/${id}-data/logs | ||
exec 2>/data/adb/${id}-data/logs/install.log | ||
set -x | ||
|
||
trap 'e=$?; echo; exit $e' EXIT | ||
|
||
# set up busybox | ||
if [ -d /sbin/.magisk/busybox ]; then | ||
[[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH | ||
elif [ -d /sbin/.core/busybox ]; then | ||
[[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH | ||
else | ||
[[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH | ||
if ! mkdir -m 700 /dev/.busybox 2>/dev/null; then | ||
if [ -x /data/adb/magisk/busybox ]; then | ||
/data/adb/magisk/busybox --install -s /dev/.busybox | ||
elif which busybox > /dev/null; then | ||
busybox --install -s /dev/.busybox | ||
else | ||
echo "(!) Install busybox binary first" | ||
exit 3 | ||
fi | ||
fi | ||
fi | ||
|
||
# Initial cleanup | ||
rm -rf $TMPDIR 2>/dev/null | ||
mkdir -p $TMPDIR | ||
# root check | ||
if [ $(id -u) -ne 0 ]; then | ||
echo "(!) $0 must run as root (su)" | ||
exit 4 | ||
fi | ||
|
||
# echo before loading util_functions | ||
ui_print() { echo "$1"; } | ||
print() { sed -n "s|^$1=||p" ${2:-$srcDir/module.prop}; } | ||
|
||
require_new_magisk() { | ||
ui_print "***********************************" | ||
ui_print " Please install the latest Magisk! " | ||
ui_print "***********************************" | ||
exit 1 | ||
set_perms() { | ||
local owner=${2:-0} perms=0600 target=$(readlink -f $1) | ||
if echo $target | grep -q '.*\.sh$' || [ -d $target ]; then perms=0700; fi | ||
chmod $perms $target | ||
chown $owner:$owner $target | ||
restorecon $target > /dev/null 2>&1 || : | ||
} | ||
|
||
imageless_magisk() { | ||
[ $MAGISK_VER_CODE -gt 18100 ] | ||
return $? | ||
set_perms_recursive() { | ||
local owner=${2:-0} target="" | ||
find $1 2>/dev/null | while read target; do set_perms $target $owner; done | ||
} | ||
|
||
########################################################################################## | ||
# Environment | ||
########################################################################################## | ||
set -euo pipefail | ||
|
||
OUTFD=$2 | ||
ZIPFILE=$3 | ||
# set source code directory | ||
[ -f $PWD/${0##*/} ] && srcDir=$PWD || srcDir=${0%/*} | ||
|
||
mount /data 2>/dev/null | ||
# unzip flashable zip if source code is unavailable | ||
if [ ! -f $srcDir/module.prop ]; then | ||
srcDir=/dev/.tmp | ||
rm -rf $srcDir 2>/dev/null || : | ||
mkdir $srcDir | ||
unzip -o ${ZIP:-${3:-}} -d $srcDir/ >&2 | ||
fi | ||
|
||
# Load utility functions | ||
if [ -f /data/adb/magisk/util_functions.sh ]; then | ||
. /data/adb/magisk/util_functions.sh | ||
NVBASE=/data/adb | ||
else | ||
require_new_magisk | ||
name=$(print name) | ||
author=$(print author) | ||
version=$(print version) | ||
versionCode=$(print versionCode) | ||
installDir=${installDir0:-/data/data/mattecarra.accapp/files} | ||
config=/data/media/0/$id/${id}.conf | ||
|
||
# migrate/restore config | ||
[ -f $config ] || mv ${config%/*}/config.txt $config 2>/dev/null || : | ||
if [ -d ${config%/*} ] && [ ! -d /data/adb/${id}-data ]; then | ||
mv $config ${config%/*}/config.txt 2>/dev/null || : | ||
(cd /data/media/0; mv ${config%/*} ${id}-data | ||
tar -cf - ${id}-data | tar -xf - -C /data/adb) | ||
rm -rf ${id}-data | ||
fi | ||
config=/data/adb/${id}-data/config.txt | ||
[ -f $config ] || cp /data/media/0/.${id}-config-backup.txt $config 2>/dev/null || : | ||
|
||
configVer=$(print versionCode $config 2>/dev/null || :) | ||
|
||
# check/set parent installation directory | ||
[ -d $installDir ] || installDir=/sbin/.magisk/modules | ||
[ -d $installDir ] || installDir=/sbin/.core/img | ||
[ -d $installDir ] || installDir=/data/adb | ||
[ -d $installDir ] || { echo "(!) /data/adb/ not found\n"; exit 1; } | ||
|
||
|
||
cat << EOF | ||
$name $version | ||
Copyright (c) 2017-2019, $author | ||
License: GPLv3+ | ||
(i) Installing in $installDir/$id/... | ||
EOF | ||
|
||
|
||
(pkill -9 -f "/$id (-|--)|/${id}d.sh" ) || : | ||
|
||
# install | ||
rm -rf $(readlink -f /sbin/.$id/$id) $installDir/$id 2>/dev/null || : | ||
cp -R $srcDir/$id/ $installDir/ | ||
installDir=$installDir/$id | ||
[ ${installDir0:-x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$id || installDir0=$installDir0/$id | ||
cp $srcDir/module.prop $installDir/ | ||
|
||
mkdir -p ${config%/*}/info | ||
cp -f $srcDir/*.md ${config%/*}/info | ||
|
||
case $installDir in | ||
/data/adb/$id|$installDir0) | ||
mv $installDir/service.sh $installDir/${id}-init.sh;; | ||
*) | ||
ln $installDir/service.sh $installDir/post-fs-data.sh;; | ||
esac | ||
|
||
# patch/upgrade config | ||
if [ -f $config ]; then | ||
if [ ${configVer:-0} -lt 201910130 ] \ | ||
|| [ ${configVer:-0} -gt $(print versionCode $installDir/default-config.txt) ] | ||
then | ||
rm $config | ||
# else | ||
# if [ $configVer -lt 201906290 ]; then | ||
# echo prioritizeBattIdleMode=false >> $config | ||
# sed -i '/^versionCode=/s/=.*/=201906290/' $config | ||
# fi | ||
# if [ $configVer -lt 201907080 ]; then | ||
# sed -i '/^loopDelay=/s/=.*/=10,30/' $config | ||
# sed -i '/^versionCode=/s/=.*/=201907080/' $config | ||
# fi | ||
# if [ $configVer -lt 201907090 ]; then | ||
# sed -i '/^rebootOnUnplug=/d' $config | ||
# sed -i '/^versionCode=/s/=.*/=201907090/' $config | ||
# fi | ||
# if [ $configVer -lt 201909260 ]; then | ||
# sed -i '/^loopDelay=/s/,30/,15/' $config | ||
# sed -i '/^versionCode=/s/=.*/=201909260/' $config | ||
# fi | ||
fi | ||
fi | ||
|
||
# Preperation for flashable zips | ||
setup_flashable | ||
cp -f $srcDir/bin/${id}-uninstaller.zip /data/media/0/ | ||
|
||
# Mount partitions | ||
mount_partitions | ||
# set perms | ||
set_perms_recursive ${config%/*} | ||
chmod 0666 /data/media/0/${id}-uninstaller.zip | ||
case $installDir in | ||
/data/*/files/$id) | ||
pkg=${installDir%/files/$id} | ||
pkg=${pkg##/data*/} | ||
owner=$(grep $pkg /data/system/packages.list | awk '{print $2}') | ||
set_perms_recursive ${installDir%/*} $owner | ||
;; | ||
*) | ||
set_perms_recursive $installDir | ||
;; | ||
esac | ||
|
||
# Detect version and architecture | ||
api_level_arch_detect | ||
set +euo pipefail | ||
|
||
# Setup busybox and binaries | ||
$BOOTMODE && boot_actions || recovery_actions | ||
|
||
########################################################################################## | ||
# Preparation | ||
########################################################################################## | ||
cat << EOF | ||
- Done | ||
# Extract common files | ||
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2 | ||
LATEST CHANGES | ||
[ ! -f $TMPDIR/install.sh ] && abort "! Unable to extract zip file!" | ||
# Load install script | ||
. $TMPDIR/install.sh | ||
EOF | ||
|
||
if imageless_magisk; then | ||
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules | ||
MODULEROOT=$NVBASE/$MODDIRNAME | ||
else | ||
$BOOTMODE && IMGNAME=magisk_merge.img || IMGNAME=magisk.img | ||
IMG=$NVBASE/$IMGNAME | ||
request_zip_size_check "$ZIPFILE" | ||
mount_magisk_img | ||
MODULEROOT=$MOUNTPATH | ||
fi | ||
|
||
MODID=`grep_prop id $TMPDIR/module.prop` | ||
MODPATH=$MODULEROOT/$MODID | ||
# print changelog | ||
tail -n +$(grep -n \($versionCode\) ${config%/*}/info/README.md | cut -d: -f1) \ | ||
${config%/*}/info/README.md | sed 's/^/ /' | ||
|
||
print_modname | ||
|
||
ui_print "******************************" | ||
ui_print "Powered by Magisk (@topjohnwu)" | ||
ui_print "******************************" | ||
cat << EOF | ||
########################################################################################## | ||
# Install | ||
########################################################################################## | ||
LINKS | ||
- ACC app: github.com/MatteCarra/AccA/ | ||
- Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/ | ||
- Donate: paypal.me/vr25xda/ | ||
- Daily Job Scheduler: github.com/VR-25/djs/ | ||
- Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/ | ||
- Git repository: github.com/VR-25/$id/ | ||
- Telegram channel: t.me/vr25_xda/ | ||
- Telegram group: t.me/${id}_group/ | ||
- Telegram profile: t.me/vr25xda/ | ||
- XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/ | ||
# Create mod paths | ||
rm -rf $MODPATH 2>/dev/null | ||
mkdir -p $MODPATH | ||
(i) Important info: https://bit.ly/2TRqRz0 | ||
on_install | ||
(i) Rebooting is unnecessary. | ||
- $id can be used right now. | ||
- $id daemon started. | ||
EOF | ||
|
||
# Remove placeholder | ||
rm -f $MODPATH/system/placeholder 2>/dev/null | ||
|
||
# Custom uninstaller | ||
[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh | ||
[ $installDir == /data/adb ] && echo -e "\n(i) Use init.d or an app to run $installDir/${id}-init.sh on boot to initialize ${id}." | ||
|
||
# Auto Mount | ||
if imageless_magisk; then | ||
$SKIPMOUNT && touch $MODPATH/skip_mount | ||
else | ||
$SKIPMOUNT || touch $MODPATH/auto_mount | ||
fi | ||
echo | ||
trap - EXIT | ||
|
||
# prop files | ||
$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop | ||
|
||
# Module info | ||
cp -af $TMPDIR/module.prop $MODPATH/module.prop | ||
if $BOOTMODE; then | ||
# Update info for Magisk Manager | ||
if imageless_magisk; then | ||
mktouch $NVBASE/modules/$MODID/update | ||
cp -af $TMPDIR/module.prop $NVBASE/modules/$MODID/module.prop | ||
# initialize $id | ||
if grep -q /storage/emulated /proc/mounts; then | ||
if [ -f $installDir/service.sh ]; then | ||
$installDir/service.sh --override | ||
else | ||
mktouch /sbin/.magisk/img/$MODID/update | ||
cp -af $TMPDIR/module.prop /sbin/.magisk/img/$MODID/module.prop | ||
$installDir/${id}-init.sh --override | ||
fi | ||
fi | ||
|
||
# post-fs-data mode scripts | ||
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh | ||
|
||
# service mode scripts | ||
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh | ||
|
||
# Handle replace folders | ||
for TARGET in $REPLACE; do | ||
mktouch $MODPATH$TARGET/.replace | ||
done | ||
|
||
ui_print "- Setting permissions" | ||
set_permissions | ||
|
||
########################################################################################## | ||
# Finalizing | ||
########################################################################################## | ||
|
||
cd / | ||
imageless_magisk || unmount_magisk_img | ||
$BOOTMODE || recovery_cleanup | ||
rm -rf $TMPDIR $MOUNTPATH | ||
|
||
ui_print "- Done" | ||
e=$? | ||
[ $e -eq 0 ] || { echo; exit $e; } | ||
exit 0 |
Oops, something went wrong.