Add target to make a flashable su addon

Run 'make addonsu' to make a flashable zip to install the addon and
'make addonsu-remove' for a flashable zip that removes it.

Change-Id: I5b2fe67f98f2474b923c074dc6025b47c6db2ae0
This commit is contained in:
Gabriele M 2017-01-22 22:50:02 +01:00 committed by Jason Riordan
parent 52996421a1
commit 5f124ae55b
5 changed files with 127 additions and 0 deletions

37
addonsu/51-addonsu.sh Normal file
View File

@ -0,0 +1,37 @@
#!/sbin/sh
. /tmp/backuptool.functions
list_files() {
cat <<EOF
bin/su
xbin/su
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" -o -L "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
done
;;
pre-backup)
# Stub
;;
post-backup)
# Stub
;;
pre-restore)
# Stub
;;
post-restore)
# Stub
;;
esac

13
addonsu/mount-system.sh Normal file
View File

@ -0,0 +1,13 @@
#!/sbin/sh
if mount /system; then
exit 0
fi
# Try to get the block from /etc/recovery.fstab
block=`cat /etc/recovery.fstab | cut -d '#' -f 1 | grep /system | grep -o '/dev/[^ ]*' | head -1`
if [ -n "$block" ] && mount $block /system; then
exit 0
fi
exit 1

View File

@ -0,0 +1,21 @@
ui_print("Installing su addon...");
ifelse(is_mounted("/system"), unmount("/system"));
package_extract_file("mount-system.sh", "/tmp/mount-system.sh");
set_metadata("/tmp/mount-system.sh", "uid", 0, "gid", 0, "mode", 0755);
run_program("/tmp/mount-system.sh") == 0 || abort("Could not mount /system");
if getprop("ro.build.system_root_image") != "true" then
package_extract_dir("system", "/system");
set_metadata("/system/addon.d/51-addonsu.sh", "uid", 0, "gid", 0, "mode", 0755, "selabel", "u:object_r:system_file:s0");
set_metadata("/system/xbin/su", "uid", 0, "gid", 2000, "mode", 0755, "selabel", "u:object_r:su_exec:s0");
symlink("/system/xbin/su", "/system/bin/su");
else
package_extract_dir("system", "/system/system");
set_metadata("/system/system/addon.d/51-addonsu.sh", "uid", 0, "gid", 0, "mode", 0755, "selabel", "u:object_r:system_file:s0");
set_metadata("/system/system/xbin/su", "uid", 0, "gid", 2000, "mode", 0755, "selabel", "u:object_r:su_exec:s0");
symlink("/system/xbin/su", "/system/system/bin/su");
endif;
unmount("/system");
ui_print("Done");
set_progress(1.000000);

View File

@ -0,0 +1,19 @@
ui_print("Removing su addon...");
ifelse(is_mounted("/system"), unmount("/system"));
package_extract_file("mount-system.sh", "/tmp/mount-system.sh");
set_metadata("/tmp/mount-system.sh", "uid", 0, "gid", 0, "mode", 0755);
run_program("/tmp/mount-system.sh") == 0 || abort("Could not mount /system");
if getprop("ro.build.system_root_image") != "true" then
delete("/system/addon.d/51-addonsu.sh");
delete("/system/bin/su");
delete("/system/xbin/su");
else
delete("/system/system/addon.d/51-addonsu.sh");
delete("/system/system/bin/su");
delete("/system/system/xbin/su");
endif;
unmount("/system");
ui_print("Done");
set_progress(1.000000);

37
build/tasks/addonsu.mk Normal file
View File

@ -0,0 +1,37 @@
ADDONSU_PREBUILTS_PATH := vendor/cm/addonsu/
ADDONSU_INSTALL_OUT := $(PRODUCT_OUT)/addonsu-install/
ADDONSU_INSTALL_TARGET := $(PRODUCT_OUT)/addonsu-$(TARGET_ARCH).zip
$(ADDONSU_INSTALL_TARGET): $(ALL_MODULES.updater.BUILT) \
$(ALL_MODULES.su.BUILT)
$(hide) rm -rf $@ $(ADDONSU_INSTALL_OUT)
$(hide) mkdir -p $(ADDONSU_INSTALL_OUT)/META-INF/com/google/android/
$(hide) mkdir -p $(ADDONSU_INSTALL_OUT)/system/xbin
$(hide) mkdir -p $(ADDONSU_INSTALL_OUT)/system/addon.d
$(hide) cp $(ALL_MODULES.su.BUILT) $(ADDONSU_INSTALL_OUT)/system/xbin/
$(hide) cp $(ALL_MODULES.updater.BUILT) $(ADDONSU_INSTALL_OUT)/META-INF/com/google/android/update-binary
$(hide) cp $(ADDONSU_PREBUILTS_PATH)/51-addonsu.sh $(ADDONSU_INSTALL_OUT)/system/addon.d/
$(hide) cp $(ADDONSU_PREBUILTS_PATH)/mount-system.sh $(ADDONSU_INSTALL_OUT)/
$(hide) cp $(ADDONSU_PREBUILTS_PATH)/updater-script-install $(ADDONSU_INSTALL_OUT)/META-INF/com/google/android/updater-script
$(hide) (cd $(ADDONSU_INSTALL_OUT) && zip -qr $@ *)
.PHONY: addonsu
addonsu: $(ADDONSU_INSTALL_TARGET)
@echo "Done: $(ADDONSU_INSTALL_TARGET)"
ADDONSU_REMOVE_OUT := $(PRODUCT_OUT)/addonsu-remove/
ADDONSU_REMOVE_TARGET := $(PRODUCT_OUT)/addonsu-remove-$(TARGET_ARCH).zip
$(ADDONSU_REMOVE_TARGET): $(ALL_MODULES.updater.BUILT)
$(hide) rm -rf $@ $(ADDONSU_REMOVE_OUT)
$(hide) mkdir -p $(ADDONSU_REMOVE_OUT)/META-INF/com/google/android/
$(hide) cp $(ALL_MODULES.updater.BUILT) $(ADDONSU_REMOVE_OUT)/META-INF/com/google/android/update-binary
$(hide) cp $(ADDONSU_PREBUILTS_PATH)/mount-system.sh $(ADDONSU_REMOVE_OUT)/
$(hide) cp $(ADDONSU_PREBUILTS_PATH)/updater-script-remove $(ADDONSU_REMOVE_OUT)/META-INF/com/google/android/updater-script
$(hide) (cd $(ADDONSU_REMOVE_OUT) && zip -qr $@ *)
.PHONY: addonsu-remove
addonsu-remove: $(ADDONSU_REMOVE_TARGET)
@echo "Done: $(ADDONSU_REMOVE_TARGET)"