funcs.txt: Add addon.d-v2 support

For maintainability, the script now uses helpers provided by addon.d.
pull/30/head
FriendlyNeighborhoodShane 4 years ago
parent f70b552e2a
commit 4e4f05e977

@ -115,8 +115,6 @@ addon_install() {
# #
# ADDOND_VERSION=2 # ADDOND_VERSION=2
modname="$modname";
save_files() { save_files() {
cat <<EOL cat <<EOL
$(echo "$stuff" "$stuff_arch" "$stuff_sdk" "$stuff_arch_sdk" "$addond_file" "$init_file" "$mark_file" | sed 's| |\n|g' | sort -u | tr -s '\n') $(echo "$stuff" "$stuff_arch" "$stuff_sdk" "$stuff_arch_sdk" "$addond_file" "$init_file" "$mark_file" | sed 's| |\n|g' | sort -u | tr -s '\n')
@ -145,69 +143,55 @@ abort() {
log " "; log " ";
log "=== MinMicroG addon.d script ==="; log "=== MinMicroG addon.d script ===";
[ -e "/system/system/build.prop" ] && sysroot="system"; if [ -f "/tmp/backuptool.functions" ]; then
[ -e "/system_root/system/build.prop" ] && sysroot="system_root"; . "/tmp/backuptool.functions" || abort "could not source addon.d helper";
[ -e "/mnt/system/system/build.prop" ] && sysroot="mnt/system"; elif [ -f "/postinstall/tmp/backuptool.functions" ]; then
[ -f "/$sysroot/system/build.prop" ] || abort "could not find a ROM in /$sysroot"; . "/postinstall/tmp/backuptool.functions" || abort "could not source addon.d helper";
else
abort "could not find addon.d helper"
fi;
sdk="$(grep ro.build.version.sdk "/$sysroot/system/build.prop" | head -n1 | cut -d= -f2)"; [ -f "$S/build.prop" ] || abort "could not find a ROM in $S";
sdk="$(grep ro.build.version.sdk "$S/build.prop" | head -n1 | cut -d= -f2)";
[ "$sdk" ] && [ "$sdk" -gt "0" ] || abort "could not find SDK"; [ "$sdk" ] && [ "$sdk" -gt "0" ] || abort "could not find SDK";
backupdir="/data/media/0/$modname/backups";
[ "$C" ] && tmpdir="$C" || tmpdir="/tmp/backupdir";
move() {
sourceobject="$1";
destobject="$2";
if [ "$sdk" -lt 21 ]; then
[ "$(basename "$(dirname "$sourceobject")").apk" = "$(basename "$sourceobject")" ] && { sourceobject="$(dirname "$(dirname "$sourceobject")")/$(basename "$sourceobject")"; destobject="$(dirname "$(dirname "$destobject")")/$(basename "$destobject")"; }
fi;
[ "$(basename "$(dirname "$sourceobject")").apk" = "$(basename "$sourceobject")" ] && { sourceobject="$(dirname "$sourceobject")"; destobject="$(dirname "$destobject")"; }
[ -e "$sourceobject" ] || return 0;
mkdir -p "$(dirname "$destobject")";
cp -rf "$sourceobject" "$(dirname "$destobject")/" || { log "ERROR: Could not move ($sourceobject to $destobject)"; return 1; }
[ -e "$destobject" ] && log "MOVER: Object moved ($sourceobject to $destobject)" || { log "ERROR: Could not move ($sourceobject to $destobject)"; return 1; }
rm -rf "$sourceobject" || { log "ERROR: Could not remove ($sourceobject)"; return 1; }
[ -e "$sourceobject" ] && { log "ERROR: Could not remove ($sourceobject)"; return 1; } || log "MOVER: Object removed ($sourceobject)";
}
perm_r() { translate_path() {
uid="$1"; while read -r entry; do
gid="$2"; if [ "$sdk" -lt 21 ]; then
dmod="$3"; [ "$(basename "$(dirname "$entry")").apk" = "$(basename "$entry")" ] && entry="$(dirname "$(dirname "$entry")")/$(basename "$entry")";
fmod="$4"; fi;
dir="$5"; [ "$(basename "$(dirname "$entry")").apk" = "$(basename "$entry")" ] && entry="$(dirname "$entry")";
[ -d "$dir" ] || return 0; echo "${entry#/system/}";
chown -R $uid:$gid "$dir" || chown -R $uid.$gid "$dir"; done;
find "$dir" -type d -exec chmod $dmod {} +;
find "$dir" -type f -exec chmod $fmod {} +;
} }
case "$1" in case "$1" in
backup) backup)
log " "; log " ";
log "Backing up..."; log "Backing up...";
save_files | while read object dummy; do save_files | translate_path | while read -r object; do
[ "$object" ] || continue; [ "$object" ] && [ -e "$S/$object" ] || continue;
move "/$sysroot/$object" "$tmpdir/$object"; backup_file "$S/$object";
log "BACKUPER: Object backed up ($object)";
done; done;
;; ;;
restore) restore)
log " "; log " ";
log "Restoring..."; log "Restoring...";
save_files | while read object dummy; do save_files | translate_path | while read -r object; do
[ "$object" ] || continue; [ "$object" ] && [ -e "$C/$S/$object" ] || continue;
move "$tmpdir/$object" "/$sysroot/$object"; restore_file "$S/$object";
log "RESTORER: Object restored ($object)";
done; done;
;; ;;
post-restore) post-restore)
log " "; log " ";
log "Debloating..."; log "Debloating...";
mount /data; delete_files | translate_path | while read -r object; do
delete_files | while read object dummy; do [ "$object" ] && [ -e "$S/$object" ] || continue;
[ "$object" ] || continue; rm -rf "$S/$object";
move "/$sysroot/$object" "$backupdir/$object"; log "DEBLOATER: Object debloated ($object)";
done; done;
[ -d "$backupdir" ] && { perm_r 1023 1023 775 664 "$backupdir"; chcon -hR "u:object_r:media_rw_data_file:s0" "$backupdir"; }
;; ;;
esac; esac;
EOF EOF

Loading…
Cancel
Save