0

I have an addon.d script that removed unwanted apps after every update so that they don't come back but it seems that the code responsible for it isn't executed whenever I update my device. Is it that the restore function isn't executed so that is why the post-restore function isn't executed either? I have no idea what is wrong.

#!/sbin/sh
#
# /system/addon.d/74-brs.sh
#
. /tmp/backuptool.functions

list_files() {
cat <<EOF
EOF
}

case "$1" in
  backup)
    list_files | while read FILE DUMMY; do
      backup_file $S/$FILE
    done
  ;;
  restore)
    list_files | while read FILE REPLACEMENT; do
      R=""
      [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
      [ -f "$C/$S/$FILE" ] && restore_file $S/$FILE $R
    done
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    # Stub
  ;;
  post-restore)
   rm -rf /system/app/Calendar
   rm -rf /system/app/Jelly
   rm -rf /system/app/messaging
  ;;
esac

New :

#!/sbin/sh
. /tmp/backuptool.functions

list_files() {
cat <<EOF
/system/app/Calendar/Calendar.apk
/system/app/Jelly/Jelly.apk
/system/app/messaging/messaging.apk
EOF
}

case "$1" in
  backup)
    list_files | while read FILE DUMMY; do
      backup_file $S/$FILE
    done
  ;;
  restore)
    list_files | while read FILE REPLACEMENT; do
      R=""
      [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
      [ -f "$C/$S/$FILE" ] && restore_file $S/$FILE $R
    done
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    # Stub
  ;;
  post-restore)
   rm -rf /system/app/Calendar
   rm -rf /system/app/Jelly
   rm -rf /system/app/messaging
  ;;
esac

1 Answers1

0

while list_files() does not return the list of affected files, this will not work as expected ...

list_files() {
cat <<EOF

# add all the files into here, directories do not matter. 

EOF
}

just because the list_files | while read FILE DUMMY; do and also

list_files | while read FILE REPLACEMENT; do will do exactly nothing.

in order to obtain the relevant file-names, you can use ls:

ls -la /system/app/Calendar
ls -la /system/app/Jelly
ls -la /system/app/messaging

also, make sure the have re-mounted the system partition in read/write mode.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Is it limited to files only? I want to delete the directory related to the apps –  Sep 12 '18 at 07:14
  • you need filenames, in order to backup/restore them (else those loops will exit before the first iteration, already). only for `rm -rf` the name of the directory is a suitable parameter. one can't just equip any command with any parameters. – Martin Zeitler Sep 12 '18 at 07:31
  • is it possible to remove the files without backing it up? I could add the apks file there and back them up before deleting them but that would be redundant because I do not want any backups. –  Sep 12 '18 at 08:50
  • @KuoChongYii it seems you do not understand the basic concept of what you are trying to script there... because this would lead to a system partition, which cannot be updated anymore, because it's original state cannot be restored, without having kept a backup. why you can't just add the file-names into there ?? – Martin Zeitler Sep 12 '18 at 08:53
  • I do not wish to backup anything. I just want it to run the removal script. I did add the file names but it does not remove the directory either. –  Sep 12 '18 at 09:01
  • @KuoChongYii I've already provided an answer, which explains why. what you wish does not matter the least, while you are trying to work against the way the framework works. you can't just do whatever you want to, there are certain rules to it. – Martin Zeitler Sep 12 '18 at 09:02
  • It do understand that without running the restore function, the post-restore function won't run either. I did add the file names but it still does not work. See post edit. –  Sep 12 '18 at 09:04