diff --git a/addonsu/51-addonsu.sh b/addonsu/51-addonsu.sh index 895496da..f2d200b9 100644 --- a/addonsu/51-addonsu.sh +++ b/addonsu/51-addonsu.sh @@ -1,4 +1,7 @@ #!/sbin/sh +# +# ADDOND_VERSION=2 +# . /tmp/backuptool.functions diff --git a/prebuilt/common/bin/50-lineage.sh b/prebuilt/common/bin/50-lineage.sh index cf9d8155..e5cf0003 100755 --- a/prebuilt/common/bin/50-lineage.sh +++ b/prebuilt/common/bin/50-lineage.sh @@ -1,5 +1,7 @@ #!/sbin/sh # +# ADDOND_VERSION=2 +# # /system/addon.d/50-lineage.sh # During a LineageOS 15.1 upgrade, this script backs up /system/etc/hosts, # /system is formatted and reinstalled, then the file is restored. diff --git a/prebuilt/common/bin/backuptool.sh b/prebuilt/common/bin/backuptool.sh index 61b4d89e..8d85a643 100755 --- a/prebuilt/common/bin/backuptool.sh +++ b/prebuilt/common/bin/backuptool.sh @@ -7,6 +7,8 @@ export C=/tmp/backupdir export S=/system export V=15.1 +export ADDOND_VERSION=1 + # Scripts in /system/addon.d expect to find backuptool.functions in /tmp cp -f /tmp/install/bin/backuptool.functions /tmp @@ -15,6 +17,18 @@ preserve_addon_d() { if [ -d /system/addon.d/ ]; then mkdir -p /tmp/addon.d/ cp -a /system/addon.d/* /tmp/addon.d/ + + # Discard any scripts that aren't at least our version level + for f in /postinstall/tmp/addon.d/*sh; do + SCRIPT_VERSION=$(grep "^# ADDOND_VERSION=" $f | cut -d= -f2) + if [ -z "$SCRIPT_VERSION" ]; then + SCRIPT_VERSION=1 + fi + if [ $SCRIPT_VERSION -lt $ADDOND_VERSION ]; then + rm $f + fi + done + chmod 755 /tmp/addon.d/*.sh fi } diff --git a/prebuilt/common/bin/backuptool_ab.sh b/prebuilt/common/bin/backuptool_ab.sh index 26034a4d..70be0ae2 100755 --- a/prebuilt/common/bin/backuptool_ab.sh +++ b/prebuilt/common/bin/backuptool_ab.sh @@ -7,6 +7,8 @@ export S=/system export C=/postinstall/tmp/backupdir export V=15.1 +export ADDOND_VERSION=2 + # Scripts in /system/addon.d expect to find backuptool.functions in /tmp mkdir -p /postinstall/tmp/ cp -f /postinstall/system/bin/backuptool_ab.functions /postinstall/tmp/backuptool.functions @@ -16,6 +18,18 @@ preserve_addon_d() { if [ -d /system/addon.d/ ]; then mkdir -p /postinstall/tmp/addon.d/ cp -a /system/addon.d/* /postinstall/tmp/addon.d/ + + # Discard any scripts that aren't at least our version level + for f in /postinstall/tmp/addon.d/*sh; do + SCRIPT_VERSION=$(grep "^# ADDOND_VERSION=" $f | cut -d= -f2) + if [ -z "$SCRIPT_VERSION" ]; then + SCRIPT_VERSION=1 + fi + if [ $SCRIPT_VERSION -lt $ADDOND_VERSION ]; then + rm $f + fi + done + chmod 755 /postinstall/tmp/addon.d/*.sh fi }