diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-10-10 23:42:20 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-10-11 22:11:08 +0200 |
commit | 3dbffb183419d910008084ebb425679f3ef6538c (patch) | |
tree | e9678d09858bb1cabcf86cb5e6aaaad0adc5f3d6 | |
parent | 53f08cb13a1e366619837800549e1d7b80b0ddf6 (diff) | |
download | vendor_replicant-scripts-3dbffb183419d910008084ebb425679f3ef6538c.tar.gz vendor_replicant-scripts-3dbffb183419d910008084ebb425679f3ef6538c.tar.bz2 vendor_replicant-scripts-3dbffb183419d910008084ebb425679f3ef6538c.zip |
key-migration.sh: enable it to run multiple times and add printsreplicant-6.0-0004-rc3
Before this patch, the key-migration.sh script only migrated the keys the
first time it ran. To do that, in that first run, it also creates the
/data/system/.key-migration-done file, and in subsequent runs it skips
the key migration if that file was present.
It probably did that to not redo the same operations again and again
either to limit the data loss risk by not doing any filesystem writes
and/or to speedup the boot process.
However if we have more than one maintainer or keyset changes over time,
users will need to run this script the first time, and at the second
change later on, the new script will not run. In addition users also need
to be able to create such script themselves and run them whenever they
need to in order to migrate to self builds, or downgrade.
Using a revision system to do that would be error prone as users and
developers would need to not forget to bump the revision to make the
script run. Using an automatic revision with the hash of the script
content also has issues as running the same script twice (for instance
by doing an upgrade, then a downgrade and then an upgrade) wouldn't
work.
Running the script each time ensure that all uses cases work, at the
cost of speed: in the recovery, with all Replicant 4.2 and 6.0 keys
up to Replicant 6.0 0004 RC2, running the script takes about 5s on
a Galaxy SIII (GT-I9300):
# time sh ./key-migration.sh
Key migration done
0m4.55s real 0m1.07s user 0m3.18s system
We also ensured that no writes were made to the packages.xml file
if nothing had to be changed. This increases the risk during the
key update as no backup of the packages.xml is done, however this
decreases the risk subsequently as no writes are made anymore.
Prints were also added to inform the user of if the script ran fine,
and if not why it didn't.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r-- | images/gen_key_migration_script/templates/key-migration.sh | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/images/gen_key_migration_script/templates/key-migration.sh b/images/gen_key_migration_script/templates/key-migration.sh index 879022a..56acb4f 100644 --- a/images/gen_key_migration_script/templates/key-migration.sh +++ b/images/gen_key_migration_script/templates/key-migration.sh @@ -14,21 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -PACKAGES=/data/system/packages.xml -PACKAGES_BACKUP=/data/system/packages-backup.xml -MIGRATION_DONE=/data/system/.key-migration-done - -if [ -f ${MIGRATION_DONE} ]; then - exit 0 -fi - -if [ ! -f ${PACKAGES_BACKUP} ] && [ ! -f ${PACKAGES} ]; then - touch ${MIGRATION_DONE} - exit 0 -fi - -if [ -f ${PACKAGES_BACKUP} ]; then - mv ${PACKAGES_BACKUP} ${PACKAGES} +PACKAGES="/data/system/packages.xml" + +if [ ! -f "${PACKAGES}" ]; then + echo "Cannot migrate keys due to missing ${PACKAGES}:" + echo "- If /data is not mounted, you might need to mount it" + echo "- If /data is already mounted, maybe the data partition is blank." + echo " In this case you can skip running this script." + exit 0 fi ##################### @@ -37,7 +30,12 @@ fi {{ generate_shell_commands(certs_data) }} -chmod 660 ${PACKAGES} -chown system:system ${PACKAGES} +if [ "$(find /data/system/packages.xml -perm 660)" != "${PACKAGES}" ] ; then + chmod 660 ${PACKAGES} +fi + +if [ "$(find /data/system/packages.xml -user system -group system)" != "${PACKAGES}" ] ; then + chown system:system ${PACKAGES} +fi -touch ${MIGRATION_DONE} +echo "Key migration done" |