From 1fc321d8c2c61a38467077a8e5c38162dcf2e293 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Mon, 21 May 2018 06:12:35 +0800 Subject: [PATCH 01/14] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79bfb20..733a3e1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro - Not backwards-compatible for Magisk version <15 due to template change **Fixes** -- No longer relies on shebang /bin/xbin/bash. In fact, it was stupid for me to do this back then :S +- No longer relies on shebang /system/xbin/bash. In fact, it was stupid for me to do this back then :S - This will ensure greater support to different devices especially on stock ROM **Modifications** From 0b6dcfe44910e4ea79977c4709e9d5e852622e0d Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Mon, 21 May 2018 07:34:11 +0800 Subject: [PATCH 02/14] Use Magisk's Busybox. Warning: Hard coded --- README.md | 21 +++++---------------- system/bin/tsbinds | 17 ++++++++++------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 733a3e1..b7f9ae1 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,23 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro ## Notice - Using this module will disable sdcardfs -- Not compatible with Huawei stock ROMs (Please report if now works on 1.0.8) - Not compatible when device has no SD Card slot - Read below - Not compatible when adoptable storage is used - Hey there! This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. ## Links -- [**More Info and Further Reading**](https://www.technosparks.net/pages/product-documentation/ts-binds) +- [**More Info and Further Reading**](https://www.technosparks.net/pages/product-documentation/ts-binds?from=readme) - [XDA Developers thread](https://forum.xda-developers.com/apps/magisk/module-ts-binds-t3628856) - [→ DOWNLOAD ZIP](https://github.com/Magisk-Modules-Repo/ts-binds/releases) (Also available in Magisk Repo) - [GitHub](https://github.com/Magisk-Modules-Repo/ts-binds/) - [Changelogs](https://github.com/Magisk-Modules-Repo/ts-binds/releases) ## Changelog (2 recent versions) +### 1.0.9 +- Deprecated (not really) `tsbinds unbind ` command because changes in the kernel is not synchronised by the system + - Some research has also been done in order to determine the through cause. + ### 1.0.8 **Regressions** @@ -33,17 +36,3 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro **Modifications** - Updated help snippet - -### 1.0.6 & 1.0.7 -**Additions** -- Disable sdcardfs by using prop entries - -**Fixes** -- Invalid path to log file in service.sh - -**Modifications** -- Magisk v14 compliant -- SD card name will not be cached anymore -- Simpler `grep`ing of SD card name -- File overwrite warning is added to `tsbinds help` for the `tsbinds move` feature -- Readme.md now points to GitHub releases to show changelogs instead of commits as changelogs diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 827c948..7766438 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -1,6 +1,9 @@ -#!/system/bin/sh +#!/sbin/.core/busybox/sh # sy +busybox=/sbin/.core/busybox +PATH=$busybox:$PATH + # Check if run under root -------------------------------- if ! ls /data > /dev/null 2> /dev/null; then echo "[!] ERROR" @@ -13,7 +16,7 @@ if ! ls /data > /dev/null 2> /dev/null; then fi # Functions ---------------------------------------------- -MODDIR=/magisk/ts-binds +MODDIR=/sbin/.core/img/ts-binds int=/data/media/0 sd=$(grep -m 1 -Eo "/mnt/media_rw/[0-9A-Z]{4}-[0-9A-Z]{4}" /proc/mounts) folderlist=$MODDIR/cached-folderlist.sh @@ -56,17 +59,17 @@ function printhelp { echo " mounting on boot" echo "log ................ Prints out the log" echo - echo "Available but useless, kept because for" - echo "developmental tests:" + echo "As of 1.0.8, unbind features are proven" + echo "useless because the changes in the" + echo "kernel is not synchronised with the ROM" + echo "Below are the such features, kept" + echo "in the script for posterity" echo echo "bind o . Binds to " echo "unbind . Unbinds a specific" echo " entry by its name" echo "unbind all ......... Unbinds all entries" echo "unbind o ..... Unbinds " - echo - echo "I am experimenting on a disable per" - echo "folder couple feature" echo echo "Note: running the command reinit, and unbind, move with \"all\" argument may return \"unmount\" errors. Most of the time they can be safely ignored." } From 96c22d78778aac182ba8c79cd1683c16d6af9494 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Mon, 21 May 2018 07:53:25 +0800 Subject: [PATCH 03/14] Update README --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7f9ae1..c57876d 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,17 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro ## Changelog (2 recent versions) ### 1.0.9 +**Modifications** +- Change to use busybox + - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` +- Uses hardcoded path towards module directory `/sbin/.core/img/ts-binds` + - Was `/magisk/ts-binds` but /magisk is a softlink towards above path + - I know, hardcoding paths is a bad practice, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module dir other than extreme measures of loopdevice check or looping through countless number of directories from root. + + +**Regressions** - Deprecated (not really) `tsbinds unbind ` command because changes in the kernel is not synchronised by the system - - Some research has also been done in order to determine the through cause. + - Research is in progress to determine the through cause. ### 1.0.8 From 7aa180c245ecdcea98e94e02d67da8305d4c7f6d Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Tue, 22 May 2018 11:07:11 +0800 Subject: [PATCH 04/14] Update README --- README.md | 2 +- system/bin/tsbinds | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c57876d..7c8158b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` - Uses hardcoded path towards module directory `/sbin/.core/img/ts-binds` - Was `/magisk/ts-binds` but /magisk is a softlink towards above path - - I know, hardcoding paths is a bad practice, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module dir other than extreme measures of loopdevice check or looping through countless number of directories from root. + - I know, hardcoding paths is not recommended by the Magisk documentation, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module dir other than extreme measures of loopdevice check or looping through countless number of directories from root. So instead of taxing the shell during boot, I prefer not to do that instead. **Regressions** diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 7766438..6788142 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -32,6 +32,7 @@ function printhelp { echo "bind ... Binds a specific entry" echo " by its name" echo "bind all ........... Binds all entries " + echo "bind o . Binds to " echo "check .. Check if an entry is binded" echo "check all .......... Check if all entries are" echo " individually binded" @@ -63,9 +64,8 @@ function printhelp { echo "useless because the changes in the" echo "kernel is not synchronised with the ROM" echo "Below are the such features, kept" - echo "in the script for posterity" + echo "in the script for rare use cases" echo - echo "bind o . Binds to " echo "unbind . Unbinds a specific" echo " entry by its name" echo "unbind all ......... Unbinds all entries" From 01ea691e74c939ad360e3a2c918a4a1c906d8f8e Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Wed, 23 May 2018 14:08:01 +0800 Subject: [PATCH 05/14] Remove the "move" feature --- system/bin/tsbinds | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 6788142..13d6050 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -42,16 +42,6 @@ function printhelp { echo "update f ........... Update cached entries" echo " regardless if the user's" echo " entries are modified" - echo "move ... Unbind and then move" - echo " specific recursing files" - echo " and folders to the" - echo " SD card path. Files" - echo " will be overwritten!" - echo "move all ........... Unbind and then move" - echo " all recursing files" - echo " and folders to the" - echo " SD card path. Files" - echo " will be overwritten!" echo "reinit ............. Re-run the script that" echo " runs on boot" echo "disable ............ Disables automatic " @@ -182,42 +172,6 @@ elif [ "$1" == "update" ]; then tslog "No update made to cached list" fi -# Move --------------------------------------------------- -elif [ "$1" == "move" ]; then - if [ ! "$2" ]; then - echo 'E: Bind name is not provided!' - elif [ "$2" == "all" ]; then - tsbinds unbind all - function folderbind { - if [ "$(ls -A "$3")" ]; then - mv -f "$3/"* "$2/" && tslog "Files moved successfully for $1" || tslog "Moving operation failed for $1" - else - tslog "No files to move for $1" - fi - } - source $folderlist - tsbinds bind all - elif line="$(grep "$2" $folderlist)"; then - function folderbind { - wasBinded=no - if grep -q "$3" /proc/mounts; then - wasBinded=yes - tsbinds unbind $1 - fi - if [ "$(ls -A "$3")" ]; then - mv -f "$3/"* "$2/" && tslog "Files moved successfully for $1" || tslog "Moving operation failed for $1" - else - tslog "No files to move for $1" - fi - if [ $wasBinded == "yes" ]; then - tsbinds bind $1 - fi - } - eval $line; - else - tslog "Unable to move contents of $2, entry not found in list!" - fi - # Reinit ------------------------------------------------- elif [ "$1" == "reinit" ]; then tsbinds unbind all From dc941dc8aa9b4f55f0696f7e66ad80b190d16e5b Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Fri, 25 May 2018 03:40:41 +0800 Subject: [PATCH 06/14] Add propline to disable esdfs --- common/system.prop | 1 + 1 file changed, 1 insertion(+) diff --git a/common/system.prop b/common/system.prop index 68694ec..cfad655 100644 --- a/common/system.prop +++ b/common/system.prop @@ -1,3 +1,4 @@ # Disable sdcardfs by prop persist.sys.sdcardfs=force_off ro.sys.sdcardfs=false +persist.esdfs_sdcard=false From efaa16fd4efbbfe21a740a5c244eab07dac0e9e2 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Fri, 25 May 2018 04:01:50 +0800 Subject: [PATCH 07/14] Return to use the --bind switch. Also rbind instead of bind to see if there are any bad results --- system/bin/tsbinds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 13d6050..f65ff20 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -90,7 +90,7 @@ elif [ "$1" == "bind" ]; then tslog "Bind aborted: Folder '$3' as target doesn't exist!" return 1 else - mount -o bind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1" + mount --rbind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1" fi } if [ ! "$2" ]; then From ec05764b5e3803e80d15f8d915af98f3cef43b26 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Fri, 25 May 2018 05:36:56 +0800 Subject: [PATCH 08/14] Add buildprop entry to enable FUSE --- common/system.prop | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/system.prop b/common/system.prop index cfad655..a0313d3 100644 --- a/common/system.prop +++ b/common/system.prop @@ -1,4 +1,6 @@ # Disable sdcardfs by prop -persist.sys.sdcardfs=force_off ro.sys.sdcardfs=false +persist.sys.sdcardfs=force_off persist.esdfs_sdcard=false +persist.fuse_sdcard=true + From e3418ceec07c37cfb1f213ca9421c963fcaa38ba Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Fri, 25 May 2018 05:43:56 +0800 Subject: [PATCH 09/14] Update README --- README.md | 5 ++--- system/bin/tsbinds | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7c8158b..e6c7d1c 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,8 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro ## Notice - Using this module will disable sdcardfs - Not compatible when device has no SD Card slot - - Read below + - This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. - Not compatible when adoptable storage is used - - Hey there! This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. ## Links - [**More Info and Further Reading**](https://www.technosparks.net/pages/product-documentation/ts-binds?from=readme) @@ -26,7 +25,7 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro - Change to use busybox - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` - Uses hardcoded path towards module directory `/sbin/.core/img/ts-binds` - - Was `/magisk/ts-binds` but /magisk is a softlink towards above path + - Was `/magisk/ts-binds` but /magisk is a symbolic link towards above path - I know, hardcoding paths is not recommended by the Magisk documentation, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module dir other than extreme measures of loopdevice check or looping through countless number of directories from root. So instead of taxing the shell during boot, I prefer not to do that instead. diff --git a/system/bin/tsbinds b/system/bin/tsbinds index f65ff20..af50d35 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -109,6 +109,7 @@ elif [ "$1" == "bind" ]; then # Unbind ------------------------------------------------- elif [ "$1" == "unbind" ]; then + unbindNotice="NOTICE: Kernel reports that mountpoint is unmounted but the OS may still treat them as if they are still binded. Reboot for full changes!" function folderbind { if ! grep -q "$3" /proc/mounts; then tslog "$1 is already unbinded" @@ -122,10 +123,13 @@ elif [ "$1" == "unbind" ]; then tslog "Unbinding all entries" source $folderlist tslog "All entries were processed" + echo $unbindNotice elif [ "$2" == "o" ]; then folderbind "o" $3 $4 + echo $unbindNotice elif line="$(grep "$2" $folderlist)"; then eval $line + echo $unbindNotice else tslog "Unable to unbind $2, entry not found in list!" fi From 1980115b1f398d13602afbb362dacff0762dedb0 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Tue, 29 May 2018 12:09:41 +0800 Subject: [PATCH 10/14] Not deprecating the unbind feature --- system/bin/tsbinds | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/system/bin/tsbinds b/system/bin/tsbinds index af50d35..b567321 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -33,6 +33,10 @@ function printhelp { echo " by its name" echo "bind all ........... Binds all entries " echo "bind o . Binds to " + echo "unbind . Unbinds a specific" + echo " entry by its name" + echo "unbind all ......... Unbinds all entries" + echo "unbind o ..... Unbinds " echo "check .. Check if an entry is binded" echo "check all .......... Check if all entries are" echo " individually binded" @@ -49,17 +53,8 @@ function printhelp { echo "enable ............. Enables automatic " echo " mounting on boot" echo "log ................ Prints out the log" - echo - echo "As of 1.0.8, unbind features are proven" - echo "useless because the changes in the" - echo "kernel is not synchronised with the ROM" - echo "Below are the such features, kept" - echo "in the script for rare use cases" echo - echo "unbind . Unbinds a specific" - echo " entry by its name" - echo "unbind all ......... Unbinds all entries" - echo "unbind o ..... Unbinds " + echo echo "Note: running the command reinit, and unbind, move with \"all\" argument may return \"unmount\" errors. Most of the time they can be safely ignored." } From b86f99d57c7f885a004427cc4adeade12f98c467 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Tue, 29 May 2018 13:19:13 +0800 Subject: [PATCH 11/14] Fix to mount namespace problem --- system/bin/tsbinds | 68 ++++++++++++++++++++++++++++------------------ test.sh | 3 ++ 2 files changed, 44 insertions(+), 27 deletions(-) create mode 100755 test.sh diff --git a/system/bin/tsbinds b/system/bin/tsbinds index b567321..69ba5ea 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -1,6 +1,7 @@ -#!/sbin/.core/busybox/sh +#!/system/bin/sh # sy +# All hail busybox for standardising this script! busybox=/sbin/.core/busybox PATH=$busybox:$PATH @@ -22,6 +23,10 @@ sd=$(grep -m 1 -Eo "/mnt/media_rw/[0-9A-Z]{4}-[0-9A-Z]{4}" /proc/mounts) folderlist=$MODDIR/cached-folderlist.sh folderlistuser=$int/ts-binds-folderlist.txt logfile=$int/ts-binds.log + +su="/sbin/su -M -c" +log="tee -a $logfile" + function printhelp { echo "tsbinds [options] [arg]" echo @@ -29,6 +34,8 @@ function printhelp { echo echo "help ............... Show this reference text" echo "h .................. Ditto" + echo "pairs .............. Prints out the folder" + echo " pairs in folderlist" echo "bind ... Binds a specific entry" echo " by its name" echo "bind all ........... Binds all entries " @@ -53,14 +60,15 @@ function printhelp { echo "enable ............. Enables automatic " echo " mounting on boot" echo "log ................ Prints out the log" + echo "mount .............. Prints out the mount" + echo " entries" echo echo echo "Note: running the command reinit, and unbind, move with \"all\" argument may return \"unmount\" errors. Most of the time they can be safely ignored." } function tslog { - echo -e "$(date +'%F %T'):\n $1\n" >> $logfile - echo -e "$1" + echo -e "$1" |& tee -a $log } # No action given ---------------------------------------- @@ -76,7 +84,7 @@ elif [ "$1" == "help" ] || [ "$1" == "h" ]; then # Bind --------------------------------------------------- elif [ "$1" == "bind" ]; then function folderbind { - if grep -q "$3" /proc/mounts; then + if $su mountpoint "$3"; then tslog "$1 is already binded" elif [ ! -d "$2" ] && [ ! -f "$2" ]; then tslog "Bind aborted: Folder '$2' as source doesn't exist!" @@ -85,7 +93,7 @@ elif [ "$1" == "bind" ]; then tslog "Bind aborted: Folder '$3' as target doesn't exist!" return 1 else - mount --rbind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1" + ($su mount --rbind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1") |& $log fi } if [ ! "$2" ]; then @@ -96,7 +104,7 @@ elif [ "$1" == "bind" ]; then tslog "All entries were processed" elif [ "$2" == "o" ]; then folderbind "o" $3 $4 - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line else tslog "Unable to bind $2, entry not found in list!" @@ -104,12 +112,11 @@ elif [ "$1" == "bind" ]; then # Unbind ------------------------------------------------- elif [ "$1" == "unbind" ]; then - unbindNotice="NOTICE: Kernel reports that mountpoint is unmounted but the OS may still treat them as if they are still binded. Reboot for full changes!" function folderbind { - if ! grep -q "$3" /proc/mounts; then + if ! $su mountpoint "$3"; then tslog "$1 is already unbinded" else - umount "$3" && tslog "Unbind successful: $1" || tslog "Unbind failed: $1" + ($su umount "$3" && tslog "Unbind successful: $1" || tslog "Unbind failed: $1") |& $log fi } if [ ! "$2" ]; then @@ -118,13 +125,10 @@ elif [ "$1" == "unbind" ]; then tslog "Unbinding all entries" source $folderlist tslog "All entries were processed" - echo $unbindNotice elif [ "$2" == "o" ]; then folderbind "o" $3 $4 - echo $unbindNotice - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line - echo $unbindNotice else tslog "Unable to unbind $2, entry not found in list!" fi @@ -132,14 +136,14 @@ elif [ "$1" == "unbind" ]; then # Check -------------------------------------------------- elif [ "$1" == "check" ]; then function folderbind { - grep -q "$3" /proc/mounts && tslog "$1 is BINDED" || tslog "$1 is NOT binded" + ($su mountpoint "$3" && tslog "$1 is BINDED" || tslog "$1 is NOT binded") |& $log } if [ ! "$2" ]; then echo 'E: Bind name is not provided!'; elif [ "$2" == "all" ]; then source $folderlist tslog "All entries were checked" - elif line="$(grep "$2" $folderlist)"; then + elif line="$(grep -m 1 "$2" $folderlist)"; then eval $line else tslog "Unable to check $2, entry not found in list!" @@ -148,24 +152,24 @@ elif [ "$1" == "check" ]; then # Update ------------------------------------------------- elif [ "$1" == "update" ]; then if [ ! -f $folderlistuser ]; then - cp $MODDIR/ts-binds-folderlist.txt $folderlistuser - chmod 0664 $folderlistuser - chown 1023:1023 $folderlistuser + cp $MODDIR/ts-binds-folderlist.txt $folderlistuser |& $log + chmod 0664 $folderlistuser |& $log + chown 1023:1023 $folderlistuser |& $log tslog "Copied user list to internal storage" tsbinds update elif [ ! -f $folderlist ]; then - cp $folderlistuser $folderlist - chmod 0755 $folderlist - chown 0:0 $folderlist + cp $folderlistuser $folderlist |& $log + chmod 0755 $folderlist |& $log + chown 0:0 $folderlist |& $log tslog "Cached the user list" elif [ "$2" ] && [ "$2" == "f" ]; then - cp -f $folderlistuser $folderlist + cp -f $folderlistuser $folderlist |& $log tslog "Force-updated cached list" elif [ ! $folderlist -nt $folderlistuser ]; then tslog "Difference found between cached and original user list" - cp -f $folderlistuser $folderlist - chmod 0755 $folderlist - chown 0:0 $folderlist + cp -f $folderlistuser $folderlist |& $log + chmod 0755 $folderlist |& $log + chown 0:0 $folderlist |& $log tslog "Updated cached list" else tslog "No update made to cached list" @@ -178,16 +182,26 @@ elif [ "$1" == "reinit" ]; then # Enable or disable -------------------------------------- elif [ "$1" == "disable" ]; then - touch $MODDIR/disable.txt + touch $MODDIR/disable.txt |& $log tslog "ts-binds automatic bind disabled" elif [ "$1" == "enable" ]; then - rm -f $MODDIR/disable.txt + rm -f $MODDIR/disable.txt |& $log tslog "ts-binds automatic bind enabled" # Print log ---------------------------------------------- elif [ "$1" == "log" ]; then cat $logfile echo + +# Print mount -------------------------------------------- +elif [ "$1" == "mount" ]; then + $su mount + echo + +# Print folder pairs ----------------------------------- +elif [ "$1" == "pairs" ]; then + awk '{print $2}' $folderlistuser + echo # Action unrecognised ------------------------------------ else diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..9f0541a --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +aa='echo Test' +$aa lel From dbb0ad2d81d2b20709574988803285e88d36404e Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Tue, 29 May 2018 13:19:48 +0800 Subject: [PATCH 12/14] Remove unintended file --- test.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 test.sh diff --git a/test.sh b/test.sh deleted file mode 100755 index 9f0541a..0000000 --- a/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -aa='echo Test' -$aa lel From dc5c8c385b764f72ba22cc0603d3bf4b7be883ed Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Tue, 29 May 2018 13:25:56 +0800 Subject: [PATCH 13/14] Update README and module's info --- README.md | 10 +++++++++- module.prop | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e6c7d1c..1156774 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Derived from a very long-living trick for users who are struggling with the inte For example, if you mirror the `Download` folder on Internal with the `Stuff from Internet` folder on your SD Card, the same list of cat pictures will be shown on both directories when navigated via a file manager, and any changes will take effect on both paths. ## Notice -- Using this module will disable sdcardfs +- Using this module will disable sdcardfs and esdfs using buildprop - Not compatible when device has no SD Card slot - This is because the module expect to have an SD Card mounted. As for the moment you may use the module without an SD Card by editing /magisk/ts-binds/service.sh. Go to line 17 and read the comment. I will consider a suitable way to workaround this logic in the script. - Not compatible when adoptable storage is used @@ -21,6 +21,14 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro ## Changelog (2 recent versions) ### 1.0.9 +**Additions** +- New `mount` parameter to output the system's mount entries. Command `tsbinds mount` is to execute in shell +- New `pairs` parameter to output the pair names in the `folderlist`. Great to do quick revision. Command `tsbinds pairs` is to execute in shell + +**Fixes** +- Fix the mount namespace issue - now binds and unbinds take effect the way it should be! + - All the commands are now passed through `su -M -c` to take effect on the global namespace. + **Modifications** - Change to use busybox - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` diff --git a/module.prop b/module.prop index de9f4fc..84d741f 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ id=ts-binds name=ts-binds -version=1.0.8 -versionCode=12 +version=1.0.9 +versionCode=13 author=TechnoSparks description=ts-binds binds two different folders on your device so that both folders share the same contents minMagisk=1500 From 4d0de066d190d018fc7836e0bbd24b8888419258 Mon Sep 17 00:00:00 2001 From: TechnoSparks Date: Fri, 1 Jun 2018 07:31:06 +0800 Subject: [PATCH 14/14] 1.0.9 --- META-INF/com/google/android/update-binary | 3 + README.md | 7 +-- config.sh | 27 +++++--- data/config.txt | 0 .../fresh-folderlist.txt | 0 system/bin/tsbinds | 61 ++++++++++--------- 6 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 data/config.txt rename ts-binds-folderlist.txt => data/fresh-folderlist.txt (100%) diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index 0b49ca5..85a6b23 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -134,6 +134,9 @@ $LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh ui_print "- Setting permissions" set_permissions +ui_print "- Checking on data folder" +set_data + ########################################################################################## # Finalizing ########################################################################################## diff --git a/README.md b/README.md index 1156774..05ade53 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,7 @@ For example, if you mirror the `Download` folder on Internal with the `Stuff fro - Uses hardcoded PATH towards the busybox folder `/sbin/.core/busybox` - Uses hardcoded path towards module directory `/sbin/.core/img/ts-binds` - Was `/magisk/ts-binds` but /magisk is a symbolic link towards above path - - I know, hardcoding paths is not recommended by the Magisk documentation, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module dir other than extreme measures of loopdevice check or looping through countless number of directories from root. So instead of taxing the shell during boot, I prefer not to do that instead. - - -**Regressions** -- Deprecated (not really) `tsbinds unbind ` command because changes in the kernel is not synchronised by the system - - Research is in progress to determine the through cause. + - I know, hardcoding paths is not recommended by the Magisk documentation, but the module goes forward by Magisk's new version. The reason I had to do this is because there is no other easy alternative to find module's dir other than extreme measures of loopdevice mounting or looping through countless number of directories from root. So instead of taxing the shell during boot, I prefer not to do that instead. ### 1.0.8 diff --git a/config.sh b/config.sh index aadc277..35f1d92 100644 --- a/config.sh +++ b/config.sh @@ -48,12 +48,6 @@ print_modname() { ui_print " " } -print_onFinish() { - ui_print " " - ui_print "[i] Flashing is done!" - ui_print "------------------------------------------------" -} - ########################################################################################## # Replace list ########################################################################################## @@ -93,10 +87,12 @@ set_permissions() { # set_perm $MODPATH/system/lib/libart.so 0 0 0644 # The following is default permissions, DO NOT remove - set_perm_recursive $MODPATH 0 0 0755 0644 - set_perm $MODPATH/service.sh 0 0 0755 - set_perm $MODPATH/system/bin/tsbinds 0 0 0755 - set_perm $MODPATH/ts-binds-folderlist.txt 0 0 0666 + set_perm_recursive $MODPATH 0 0 0755 0644 + + set_perm $MODPATH/service.sh 0 0 0755 + set_perm $MODPATH/system/bin/tsbinds 0 0 0755 + set_perm $MODPATH/data/fresh-folderlist.txt 1023 1023 0664 + set_perm $MODPATH/data/config.txt 0 0 0666 } ########################################################################################## @@ -109,3 +105,14 @@ set_permissions() { # difficult for you to migrate your modules to newer template versions. # Make update-binary as clean as possible, try to only do function calls in it. +set_data() { + if [ ! -d /data/ts-binds ]; then + mv $MODPATH/data /data/ts-binds + fi +} + +print_onFinish() { + ui_print " " + ui_print "[i] Flashing is done!" + ui_print "------------------------------------------------" +} diff --git a/data/config.txt b/data/config.txt new file mode 100644 index 0000000..e69de29 diff --git a/ts-binds-folderlist.txt b/data/fresh-folderlist.txt similarity index 100% rename from ts-binds-folderlist.txt rename to data/fresh-folderlist.txt diff --git a/system/bin/tsbinds b/system/bin/tsbinds index 69ba5ea..a250694 100644 --- a/system/bin/tsbinds +++ b/system/bin/tsbinds @@ -18,14 +18,16 @@ fi # Functions ---------------------------------------------- MODDIR=/sbin/.core/img/ts-binds +datadir=/data/ts-binds int=/data/media/0 sd=$(grep -m 1 -Eo "/mnt/media_rw/[0-9A-Z]{4}-[0-9A-Z]{4}" /proc/mounts) -folderlist=$MODDIR/cached-folderlist.sh +folderlist=$datadir/cached-folderlist.sh folderlistuser=$int/ts-binds-folderlist.txt logfile=$int/ts-binds.log -su="/sbin/su -M -c" -log="tee -a $logfile" +function supass { + /sbin/su -M -c "$@" +} function printhelp { echo "tsbinds [options] [arg]" @@ -68,7 +70,8 @@ function printhelp { echo "Note: running the command reinit, and unbind, move with \"all\" argument may return \"unmount\" errors. Most of the time they can be safely ignored." } function tslog { - echo -e "$1" |& tee -a $log + echo -e "$(date +'%F %T'):\n $1\n" >> $logfile + echo -e "$1" } # No action given ---------------------------------------- @@ -84,7 +87,8 @@ elif [ "$1" == "help" ] || [ "$1" == "h" ]; then # Bind --------------------------------------------------- elif [ "$1" == "bind" ]; then function folderbind { - if $su mountpoint "$3"; then + cmd="mountpoint -q \"$3\"" + if (supass $cmd); then tslog "$1 is already binded" elif [ ! -d "$2" ] && [ ! -f "$2" ]; then tslog "Bind aborted: Folder '$2' as source doesn't exist!" @@ -93,7 +97,8 @@ elif [ "$1" == "bind" ]; then tslog "Bind aborted: Folder '$3' as target doesn't exist!" return 1 else - ($su mount --rbind "$2" "$3" && tslog "Bind successful: $1" || tslog "Bind failed: $1") |& $log + cmd="mount --rbind \"$2\" \"$3\"" + (supass $cmd) && tslog "Bind successful: $1" || tslog "Bind failed: $1" fi } if [ ! "$2" ]; then @@ -113,10 +118,12 @@ elif [ "$1" == "bind" ]; then # Unbind ------------------------------------------------- elif [ "$1" == "unbind" ]; then function folderbind { - if ! $su mountpoint "$3"; then + cmd="mountpoint -q \"$3\"" + if ! (supass $cmd); then tslog "$1 is already unbinded" else - ($su umount "$3" && tslog "Unbind successful: $1" || tslog "Unbind failed: $1") |& $log + cmd="umount \"$3\"" + (supass $cmd) && tslog "Unbind successful: $1" || tslog "Unbind failed: $1" fi } if [ ! "$2" ]; then @@ -136,7 +143,8 @@ elif [ "$1" == "unbind" ]; then # Check -------------------------------------------------- elif [ "$1" == "check" ]; then function folderbind { - ($su mountpoint "$3" && tslog "$1 is BINDED" || tslog "$1 is NOT binded") |& $log + cmd="mountpoint -q \"$3\"" + (supass $cmd) && tslog "$1 is BINDED" || tslog "$1 is NOT binded" } if [ ! "$2" ]; then echo 'E: Bind name is not provided!'; @@ -152,24 +160,18 @@ elif [ "$1" == "check" ]; then # Update ------------------------------------------------- elif [ "$1" == "update" ]; then if [ ! -f $folderlistuser ]; then - cp $MODDIR/ts-binds-folderlist.txt $folderlistuser |& $log - chmod 0664 $folderlistuser |& $log - chown 1023:1023 $folderlistuser |& $log + cp $datadir/fresh-folderlist.txt $folderlistuser tslog "Copied user list to internal storage" tsbinds update elif [ ! -f $folderlist ]; then - cp $folderlistuser $folderlist |& $log - chmod 0755 $folderlist |& $log - chown 0:0 $folderlist |& $log + cp $folderlistuser $folderlist tslog "Cached the user list" elif [ "$2" ] && [ "$2" == "f" ]; then - cp -f $folderlistuser $folderlist |& $log + cp -f $folderlistuser $folderlist tslog "Force-updated cached list" elif [ ! $folderlist -nt $folderlistuser ]; then tslog "Difference found between cached and original user list" - cp -f $folderlistuser $folderlist |& $log - chmod 0755 $folderlist |& $log - chown 0:0 $folderlist |& $log + cp -f $folderlistuser $folderlist tslog "Updated cached list" else tslog "No update made to cached list" @@ -182,10 +184,10 @@ elif [ "$1" == "reinit" ]; then # Enable or disable -------------------------------------- elif [ "$1" == "disable" ]; then - touch $MODDIR/disable.txt |& $log + touch $MODDIR/disable.txt tslog "ts-binds automatic bind disabled" elif [ "$1" == "enable" ]; then - rm -f $MODDIR/disable.txt |& $log + rm -f $MODDIR/disable.txt tslog "ts-binds automatic bind enabled" # Print log ---------------------------------------------- @@ -195,19 +197,22 @@ elif [ "$1" == "log" ]; then # Print mount -------------------------------------------- elif [ "$1" == "mount" ]; then - $su mount + supass mount echo -# Print folder pairs ----------------------------------- +# Print folder pairs ------------------------------------- elif [ "$1" == "pairs" ]; then - awk '{print $2}' $folderlistuser - echo + while IFS='' read -r line || [[ -n "$line" ]]; do + if ! (echo $line | grep -Eo "#\| +" > /dev/null 2> /dev/null); then + echo $line | awk '{print $2}' + fi + done < $folderlist # Action unrecognised ------------------------------------ else echo "E: Unknown action \"$1\" supplied" fi -# Force log proper permission -chown 1023:1023 $logfile $folderlistuser -chmod 0664 $logfile $folderlistuser +# Force log proper permission ---------------------------- +chown 1023:1023 $logfile $folderlistuser $folderlist +chmod 0664 $logfile $folderlistuser $folderlist