diff options
author | Gabriele M <moto.falcon.git@gmail.com> | 2017-01-22 22:50:02 +0100 |
---|---|---|
committer | Jason Riordan <jriordan001@gmail.com> | 2017-02-27 23:33:02 -0500 |
commit | 5f124ae55be98d4996658f05aaac4c63802ea590 (patch) | |
tree | 86d026173350088bdafa1efaf469e8f602d681c3 /addonsu | |
parent | 52996421a116965bff6b7b58bd99693b4ef02d23 (diff) | |
download | vendor_replicant-5f124ae55be98d4996658f05aaac4c63802ea590.zip vendor_replicant-5f124ae55be98d4996658f05aaac4c63802ea590.tar.gz vendor_replicant-5f124ae55be98d4996658f05aaac4c63802ea590.tar.bz2 |
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
Diffstat (limited to 'addonsu')
-rw-r--r-- | addonsu/51-addonsu.sh | 37 | ||||
-rw-r--r-- | addonsu/mount-system.sh | 13 | ||||
-rw-r--r-- | addonsu/updater-script-install | 21 | ||||
-rw-r--r-- | addonsu/updater-script-remove | 19 |
4 files changed, 90 insertions, 0 deletions
diff --git a/addonsu/51-addonsu.sh b/addonsu/51-addonsu.sh new file mode 100644 index 0000000..4e36c4c --- /dev/null +++ b/addonsu/51-addonsu.sh @@ -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 diff --git a/addonsu/mount-system.sh b/addonsu/mount-system.sh new file mode 100644 index 0000000..2e209fb --- /dev/null +++ b/addonsu/mount-system.sh @@ -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 diff --git a/addonsu/updater-script-install b/addonsu/updater-script-install new file mode 100644 index 0000000..762ddc5 --- /dev/null +++ b/addonsu/updater-script-install @@ -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); diff --git a/addonsu/updater-script-remove b/addonsu/updater-script-remove new file mode 100644 index 0000000..dab1df9 --- /dev/null +++ b/addonsu/updater-script-remove @@ -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); |